-
Notifications
You must be signed in to change notification settings - Fork 12.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Mention that type parameters are used recursively on bivariance error #127871
Conversation
| - type parameter must be used non-recursively in the definition | ||
LL | Cons(Box<ListCell<T>>), | ||
| ^ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Notably, the primary span is now the usage, not the definition. We could put that back, I guess.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pretty sure this fixes #118976 (edit: Well, I marked that as A-docs not A-diagnostics but doesn't matter as long as we clear up the confusion somehow). Might also fix some of the open issues linked here: #118976 (comment) (dunno, haven't looked at them lol)
Interestingly, this actually regresses #66912...
Maybe we should recurse into the structs/aliases to check for cycles 🤔 |
Oh, that's a bummer. Makes sense looking at the current impl. If you can make it work easily, I'd love to see this addressed. Note though that the cycles may have arbitrary periods. |
Sure, but never greater than |
OK, should also "fix" #66912 by explaining that the parameter is likely unused in the containing type. Not totally certain if that's sufficient, but it should at least unregress the test. |
This comment has been minimized.
This comment has been minimized.
dfd6084
to
c02d0de
Compare
error: type parameter `T` is only used recursively | ||
--> $DIR/issue-105231.rs:2:15 | ||
| | ||
LL | struct A<T>(B<T>); | ||
| ^ unused type parameter | ||
| - ^ | ||
| | | ||
| type parameter must be used non-recursively in the definition | ||
| | ||
= help: consider removing `T`, referring to it in a field, or using a marker such as `PhantomData` | ||
= help: if you intended `T` to be a const parameter, use `const T: /* Type */` instead | ||
= note: all type parameters must be used in a non-recursive way in order to constrain their variance |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be ideal if we either expanded this diagnostic with some of the info from E0072, or if we silenced this one if E0072 was emitted (because it gives the "solution" already, making this one redundant).
@bors r+ |
Esteban, I'm not entirely sure why you r+'ed even tho I had assigned myself. Clearly, I had sth. I wanted to say. Anyway, I will post it as a PR instead. |
…iaskrgr Rollup of 8 pull requests Successful merges: - rust-lang#127418 (Wrap too long type name) - rust-lang#127594 (Fuchsia status code match arm) - rust-lang#127835 (Fix ICE in suggestion caused by `⩵` being recovered as `==`) - rust-lang#127858 (match lowering: Rename `MatchPair` to `MatchPairTree`) - rust-lang#127871 (Mention that type parameters are used recursively on bivariance error) - rust-lang#127913 (remove `debug-logging` default from tools profile) - rust-lang#127925 (Remove tag field from `Relation`s) - rust-lang#127929 (Use more accurate span for `addr_of!` suggestion) r? `@ghost` `@rustbot` modify labels: rollup
…iaskrgr Rollup of 8 pull requests Successful merges: - rust-lang#127418 (Wrap too long type name) - rust-lang#127594 (Fuchsia status code match arm) - rust-lang#127835 (Fix ICE in suggestion caused by `⩵` being recovered as `==`) - rust-lang#127858 (match lowering: Rename `MatchPair` to `MatchPairTree`) - rust-lang#127871 (Mention that type parameters are used recursively on bivariance error) - rust-lang#127913 (remove `debug-logging` default from tools profile) - rust-lang#127925 (Remove tag field from `Relation`s) - rust-lang#127929 (Use more accurate span for `addr_of!` suggestion) r? `@ghost` `@rustbot` modify labels: rollup
Rollup of 8 pull requests Successful merges: - rust-lang#127418 (Wrap too long type name) - rust-lang#127594 (Fuchsia status code match arm) - rust-lang#127835 (Fix ICE in suggestion caused by `⩵` being recovered as `==`) - rust-lang#127858 (match lowering: Rename `MatchPair` to `MatchPairTree`) - rust-lang#127871 (Mention that type parameters are used recursively on bivariance error) - rust-lang#127913 (remove `debug-logging` default from tools profile) - rust-lang#127925 (Remove tag field from `Relation`s) - rust-lang#127929 (Use more accurate span for `addr_of!` suggestion) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of rust-lang#127871 - compiler-errors:recursive, r=estebank Mention that type parameters are used recursively on bivariance error Right now when a type parameter is used recursively, even with indirection (so it has a finite size) we say that the type parameter is unused: ``` struct B<T>(Box<B<T>>); ``` This is confusing, because the type parameter is *used*, it just doesn't have its variance constrained. This PR tweaks that message to mention that it must be used *non-recursively*. Not sure if we should actually mention "variance" here, but also I'd somewhat prefer we don't keep the power users in the dark w.r.t the real underlying issue, which is that the variance isn't constrained. That technical detail is reserved for a note, though. cc `@fee1-dead` Fixes rust-lang#118976 Fixes rust-lang#26283 Fixes rust-lang#53191 Fixes rust-lang#105740 Fixes rust-lang#110466
…better-err, r=compiler-errors Lazy type aliases: Diagostics: Detect bivariant ty params that are only used recursively Follow-up to errs's rust-lang#127871. Extends the logic to cover LTAs, too, not just ADTs. This change only takes effect with the next-gen solver enabled as cycle errors like the one we have here are fatal in the old solver. That's my explanation anyways. r? compiler-errors
Rollup merge of rust-lang#127976 - fmease:lta-cyclic-bivariant-param-better-err, r=compiler-errors Lazy type aliases: Diagostics: Detect bivariant ty params that are only used recursively Follow-up to errs's rust-lang#127871. Extends the logic to cover LTAs, too, not just ADTs. This change only takes effect with the next-gen solver enabled as cycle errors like the one we have here are fatal in the old solver. That's my explanation anyways. r? compiler-errors
Right now when a type parameter is used recursively, even with indirection (so it has a finite size) we say that the type parameter is unused:
This is confusing, because the type parameter is used, it just doesn't have its variance constrained. This PR tweaks that message to mention that it must be used non-recursively.
Not sure if we should actually mention "variance" here, but also I'd somewhat prefer we don't keep the power users in the dark w.r.t the real underlying issue, which is that the variance isn't constrained. That technical detail is reserved for a note, though.
cc @fee1-dead
Fixes #118976
Fixes #26283
Fixes #53191
Fixes #105740
Fixes #110466