Open
Description
Given the following code:
trait Trait<'a>: Sized {
fn method(self)
where
for<'b> Self: Trait<'b>;
}
The current output is:
Compiling playground v0.0.1 (/playground)
error[E0283]: type annotations needed
--> src/lib.rs:1:1
|
1 | trait Trait<'a>: Sized {
| ^^^^^^^^^^^^^^^^^^^^^^
| |
| cannot infer type for type parameter `Self`
| required by this bound in `Trait`
|
= note: cannot satisfy `Self: Trait<'a>`
help: consider specifying the type arguments in the function call
|
1 | trait Trait<'a>: Sized::<Self, 'a> {
| ^^^^^^^^^^^^
error: aborting due to previous error
I would’ve expected this code to compile. Even if there is a reason why it shouldn’t compile, the error message is about the most confusing/nonsensical error message I’ve ever seen. The “best” part is how it suggests adding arguments to Sized
.
Metadata
Metadata
Assignees
Labels
Area: Messages for errors, warnings, and lintsArea: Higher-ranked things (e.g., lifetimes, types, trait bounds aka HRTBs)Area: Lifetimes / regionsArea: Suggestions generated by the compiler applied by `cargo fix`Area: Trait systemDiagnostics: Confusing error or lint that should be reworked.Relevant to the compiler team, which will review and decide on the PR/issue.
Type
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
steffahn commentedon Apr 22, 2021
This code used to compile fine in rust
1.0
through1.3
, it used to ICE from1.4
to1.6
and it gives some kind ofcannot resolve `Self : Trait<'a>`
/E0283
error ever since1.7
.SNCPlay42 commentedon Apr 22, 2021
This looks similar to #84398, but that one's a recent regression.
steffahn commentedon Apr 23, 2021
In
1.3
-1.4
the ICE appears atnightly-2015-08-15
.This range includes
In this list, I would suspect that #27641 could be the regression point.
In
1.6
-1.7
the ICE disappears and the first version of the error message appears atnightly-2015-12-19
.That’s a huge range with no nightly versions existing in between…
Looking through this, it might be #30389 since that’s related to RFC 1214 again.
Skimming the RFC and also in general thinking about this code a few times I don’t see any reason why this shouldn’t be allowed to be accepted by the compiler. So I’ll consider this a bug. @rustbot modify labels: C-bug, A-traits, A-lifetimes, D-confusing, A-suggestion-diagnostics.
The labels are quite diverse now, since this could count as 3 distinct issues:
Self
”. I don’t know of any situation where this kind of error message makes any sense; shouldn’t the compiler never actually have to “inferSelf
”? (D-confusing)Even though the code used to compile pre-
1.4
, I’m hesitant about marking this as a regression. This is super old and RFC 1214 seems to have come with some other – deliberate – breaking changes anyways.ChayimFriedman2 commentedon Apr 12, 2022
Another case of this bug (https://users.rust-lang.org/t/strange-type-annotations-needed-error/74117?u=chrefr):
https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=94818406f96dfe5f1a086ccd01cf35a7
estebank commentedon Aug 3, 2023
Current output:
2 remaining items