-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Misleading type error when generic parameter is sole mismatch. #76086
Labels
A-diagnostics
Area: Messages for errors, warnings, and lints
C-enhancement
Category: An issue proposing an enhancement or a PR with one.
D-confusing
Diagnostics: Confusing error or lint that should be reworked.
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
Comments
jonas-schievink
added
A-diagnostics
Area: Messages for errors, warnings, and lints
C-enhancement
Category: An issue proposing an enhancement or a PR with one.
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
labels
Aug 29, 2020
estebank
added
the
D-confusing
Diagnostics: Confusing error or lint that should be reworked.
label
Aug 29, 2020
estebank
added a commit
to estebank/rust
that referenced
this issue
Nov 16, 2023
When encountering a type error involving a `Self` literal, point at the self type of the enclosing `impl`. CC rust-lang#76086.
estebank
added a commit
to estebank/rust
that referenced
this issue
Nov 16, 2023
When encountering a type error caused by the use of `Self`, suggest using the actual type name instead. ``` error[E0308]: mismatched types --> $DIR/struct-path-self-type-mismatch.rs:13:9 | LL | impl<T> Foo<T> { | - ------ this is the type of the `Self` literal | | | found type parameter LL | fn new<U>(u: U) -> Foo<U> { | - ------ expected `Foo<U>` because of return type | | | expected type parameter LL | / Self { LL | | LL | | inner: u LL | | LL | | } | |_________^ expected `Foo<U>`, found `Foo<T>` | = note: expected struct `Foo<U>` found struct `Foo<T>` = note: a type parameter was expected, but a different one was found; you might be missing a type parameter or trait bound = note: for more information, visit https://doc.rust-lang.org/book/ch10-02-traits.html#traits-as-parameters help: use the type name directly | LL | Foo::<U> { | ~~~~~~~~ ``` Fix rust-lang#76086.
estebank
added a commit
to estebank/rust
that referenced
this issue
Nov 16, 2023
When encountering a type error caused by the use of `Self`, suggest using the actual type name instead. ``` error[E0308]: mismatched types --> $DIR/struct-path-self-type-mismatch.rs:13:9 | LL | impl<T> Foo<T> { | - ------ this is the type of the `Self` literal | | | found type parameter LL | fn new<U>(u: U) -> Foo<U> { | - ------ expected `Foo<U>` because of return type | | | expected type parameter LL | / Self { LL | | LL | | inner: u LL | | LL | | } | |_________^ expected `Foo<U>`, found `Foo<T>` | = note: expected struct `Foo<U>` found struct `Foo<T>` = note: a type parameter was expected, but a different one was found; you might be missing a type parameter or trait bound = note: for more information, visit https://doc.rust-lang.org/book/ch10-02-traits.html#traits-as-parameters help: use the type name directly | LL | Foo::<U> { | ~~~~~~~~ ``` Fix rust-lang#76086.
estebank
added a commit
to estebank/rust
that referenced
this issue
Nov 16, 2023
When encountering a type error involving a `Self` literal, point at the self type of the enclosing `impl`. CC rust-lang#76086.
matthiaskrgr
added a commit
to matthiaskrgr/rust
that referenced
this issue
Nov 16, 2023
…rrors Better handle type errors involving `Self` literals When encountering a type error involving a `Self` literal, point at the self type of the enclosing `impl` and suggest using the actual type name instead. ``` error[E0308]: mismatched types --> $DIR/struct-path-self-type-mismatch.rs:13:9 | LL | impl<T> Foo<T> { | - ------ this is the type of the `Self` literal | | | found type parameter LL | fn new<U>(u: U) -> Foo<U> { | - ------ expected `Foo<U>` because of return type | | | expected type parameter LL | / Self { LL | | LL | | inner: u LL | | LL | | } | |_________^ expected `Foo<U>`, found `Foo<T>` | = note: expected struct `Foo<U>` found struct `Foo<T>` = note: a type parameter was expected, but a different one was found; you might be missing a type parameter or trait bound = note: for more information, visit https://doc.rust-lang.org/book/ch10-02-traits.html#traits-as-parameters help: use the type name directly | LL | Foo::<U> { | ~~~~~~~~ ``` Fix rust-lang#76086.
rust-timer
added a commit
to rust-lang-ci/rust
that referenced
this issue
Nov 17, 2023
Rollup merge of rust-lang#117959 - estebank:issue-76086, r=compiler-errors Better handle type errors involving `Self` literals When encountering a type error involving a `Self` literal, point at the self type of the enclosing `impl` and suggest using the actual type name instead. ``` error[E0308]: mismatched types --> $DIR/struct-path-self-type-mismatch.rs:13:9 | LL | impl<T> Foo<T> { | - ------ this is the type of the `Self` literal | | | found type parameter LL | fn new<U>(u: U) -> Foo<U> { | - ------ expected `Foo<U>` because of return type | | | expected type parameter LL | / Self { LL | | LL | | inner: u LL | | LL | | } | |_________^ expected `Foo<U>`, found `Foo<T>` | = note: expected struct `Foo<U>` found struct `Foo<T>` = note: a type parameter was expected, but a different one was found; you might be missing a type parameter or trait bound = note: for more information, visit https://doc.rust-lang.org/book/ch10-02-traits.html#traits-as-parameters help: use the type name directly | LL | Foo::<U> { | ~~~~~~~~ ``` Fix rust-lang#76086.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
A-diagnostics
Area: Messages for errors, warnings, and lints
C-enhancement
Category: An issue proposing an enhancement or a PR with one.
D-confusing
Diagnostics: Confusing error or lint that should be reworked.
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
Some Rust (playground):
yields an error about the mismatched type of
inner
:but I know it should be
()
- the return type onfoo
also expectsT
to be()
! The second error is somewhat more helpful:The actual issue I'd had writing this was
Self { inner: () }
instead ofGeneric { inner: () }
. It would have been helpful if rustc could have concluded that the type I'd wanted matched the function's return type, and that the issue wasSelf
beingGeneric<T>
and causing the mismatch.cc @estebank who'd asked me to write up an issue with a reproduction.
Apologies for the mushy title, I couldn't think of something more precise - very open to rewording if someone's got a better one-liner.
The text was updated successfully, but these errors were encountered: