Trait definitions with missing generic parameters suggest missing enum variant
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
Code
pub struct Point<A> {
x: A,
}
pub trait MyTrait1 {
fn fun(&self, p: Point<A>);
}
pub struct MyStruct;
impl<A> MyTrait1 for Point<A> {
fn fun(&self, p: Point<A>) {
todo!();
}
}
fn main() {
todo!();
}
Current output
error[E0412]: cannot find type `A` in this scope
--> src/main.rs:5:28
|
5 | fn fun(&self, p: Point<A>);
| ^ not found in this scope
|
help: there is an enum variant `futures_0_1_31::future::Either::A`; try using the variant's enum
|
5 | fn fun(&self, p: Point<futures_0_1_31::future::Either>);
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
For more information about this error, try `rustc --explain E0412`.
error: could not compile `playground` (bin "playground") due to previous error
Desired output
error[E0412]: cannot find type `A` in this scope
--> src/main.rs:5:28
|
5 | fn fun(&self, p: Point<A>);
| ^ not found in this scope
|
help: you might be missing a type parameter
|
4 | pub trait MyTrait1<A> {
| +++
For more information about this error, try `rustc --explain E0412`.
error: could not compile `playground` (bin "playground") due to previous error
Rationale and extra context
I'm using generic parameters and then noticed that in this code, when I use A as a generic parameter, the compiler suggested to add a enum variant. I'm not sure what this means and it still doesn't compile after following the suggestion. I've tried some earlier versions of rustc and that suggestion doesn't come up either.
If I use the generic parameter T, the compiler does not show this suggestion. It only output an error without any suggestion, like this:
error[E0412]: cannot find type `T` in this scope
--> src/main.rs:5:28
|
5 | fn fun(&self, p: Point<T>);
| ^ not found in this scope
For more information about this error, try `rustc --explain E0412`.
If I use a longer name for the generic parameter, the compiler gives me the correct hint, like this:
error[E0412]: cannot find type `Tt` in this scope
--> src/main.rs:5:28
|
5 | fn fun(&self, p: Point<Tt>);
| ^^ not found in this scope
|
help: you might be missing a type parameter
|
4 | pub trait MyTrait1<Tt> {
| ++++
For more information about this error, try `rustc --explain E0412`.
Other cases
No response
Anything else?
I am using the 1.73.0 Stable channel and it can be reproduced on the nightly (2023-11-07) version as well.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the diagnostic with the supplied Rust code on stable or nightly, then compare the suggestions for generic names A, T, and Tt. Done means the A case suggests adding a missing type parameter rather than an unrelated enum variant, while the other reported behaviors remain correct.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 48/100