-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Add error description for E0406 #34230
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -444,6 +444,43 @@ impl SomeTrait for Foo { // ok! | |
``` | ||
"##, | ||
|
||
E0406: r##" | ||
The function is referring to an associated type which hasn't been declared in | ||
the trait. | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You forgot "Example of erroneous code:". Take a look at the RFC for more information. |
||
```compile_fail | ||
trait Foo { | ||
type Bar; | ||
|
||
fn return_bool(&self, &Self::Bar, &Self::Baz) -> bool; | ||
// etc | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure this "// etc" is needed here. |
||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When I try to compile this code, I get E0220, not E0406:
I've found that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tried searching the codebase, hoping to find answers, but like you, my knowledge of compilers isn't exactly top-notch. I suspect the compiler is showing E0220 until this lands. I asked on the IRC regrading this as well, and it seems that E0406 should be thrown here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah damn, I tested your code on release. Didn't think it'd change on nightly. :-/ |
||
``` | ||
|
||
One solution might be to declare the associated type in the trait: | ||
|
||
``` | ||
trait Foo { | ||
type Bar; | ||
type Baz; //declare required associated type | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why so much space between the comment and the code? |
||
|
||
fn return_bool(&self, &Self::Bar, &Self::Baz) -> bool; | ||
// etc | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this "// etc" useful? |
||
} | ||
``` | ||
Alternatively, you could remove the input variable | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing an empty line before this block. |
||
corresponding to the associated type from the function signature: | ||
|
||
``` | ||
trait Foo { | ||
type Bar; | ||
|
||
fn return_bool(&self, &Self::Bar) -> bool; //&Self::Baz has been removed | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "//" has to be followed by a whitespace. |
||
// etc | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this "// etc" usefiul here as well? |
||
} | ||
``` | ||
"##, | ||
|
||
E0407: r##" | ||
A definition of a method not in the implemented trait was given in a trait | ||
implementation. Example of erroneous code: | ||
|
@@ -1105,7 +1142,6 @@ register_diagnostics! { | |
// E0257, | ||
// E0258, | ||
E0402, // cannot use an outer type parameter in this context | ||
E0406, // undeclared associated type | ||
// E0410, merged into 408 | ||
// E0413, merged into 530 | ||
// E0414, merged into 530 | ||
|
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.
"A function" instead of "The function". It makes it less personal. 😉