-
Notifications
You must be signed in to change notification settings - Fork 13.3k
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 all commits
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,52 @@ impl SomeTrait for Foo { // ok! | |
``` | ||
"##, | ||
|
||
E0406: r##" | ||
A function is referring to an associated type which hasn't been declared in | ||
the trait. Example of erroneous code: | ||
|
||
```compile_fail | ||
trait Foo { | ||
type Bar; | ||
|
||
// error: function signature contains a reference to `Self::Baz`, but | ||
// `Baz` hasn't been declared as an associated type of the trait | ||
fn return_bool(&self, &Self::Bar, &Self::Baz) -> bool; | ||
} | ||
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. :-/ |
||
``` | ||
You tried to use an associated type which hasn't been declared in the | ||
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 paragraph. |
||
trait body. All associated types must be declared with the | ||
type keyword, e.g. `type a;` before being used. | ||
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 don't like very much "e.g.". But since I don't have something in mind to replace, let's keep it (except if you find something better). |
||
|
||
One solution might be to declare the associated type in the trait: | ||
|
||
``` | ||
trait Foo { | ||
type Bar; | ||
type Baz; // declare `Baz` | ||
|
||
fn return_bool(&self, &Self::Bar, &Self::Baz) -> bool; | ||
} | ||
``` | ||
|
||
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; | ||
|
||
// `&Self::Baz` has been removed | ||
fn return_bool(&self, &Self::Bar) -> bool; | ||
} | ||
``` | ||
|
||
For more on associated types, refer to the associated types section | ||
of the Rust book: | ||
|
||
https://doc.rust-lang.org/book/associated-types.html | ||
"##, | ||
|
||
E0407: r##" | ||
A definition of a method not in the implemented trait was given in a trait | ||
implementation. Example of erroneous code: | ||
|
@@ -1105,7 +1151,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.
You forgot "Example of erroneous code:". Take a look at the RFC for more information.