-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Add error description for E0406 #34230
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @GuillaumeGomez (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
@@ -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 |
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. 😉
Great job, thanks! However, you forgot to explain why it is an error before showing how to fix it. since I like wise quotes: "Give a man a fish, we'll have meal for a day. Teach a man how to fish, he'll have meal a life." 😺 |
@GuillaumeGomez Right, I have added the explanation for the error, and fixed other minor things which you mentioned. Please take a look at it 😃 |
type Bar; | ||
|
||
// error: function signature contains a reference to Self::Baz, | ||
// but 'Baz' hasn't been declared as an associated type of the trait |
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.
Can you align the text like this:
// error: function signature contains a reference to Self::Baz,
// but 'Baz' hasn't been declared as an associated type of the trait
Please?
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.
Sure.
You didn't really explain more. Just write a little paragraph about the error. Explain a bit more what's happening. You can even give a link to the rust book if it can help users to understand what happened. |
@GuillaumeGomez I added the explanation para and some other fixes too. I hope it's good enough! |
} | ||
``` | ||
|
||
The use of 'associated types' allows us declare variables which might be used |
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.
No, that's not what I meant. Don't explain what the user tried to do but in which he/she did wrong.
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.
Well.... I can't understand what you are trying to say. 😕
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.
Sorry, I'll try to explain more clearly. So in here, what's expected is something which helps the user understands the error. Easy example:
let mut x: u32 = 0;
x = "salut !";
It'll fail because the expected type doesn't correspond to the one we put in x
. So instead of explaining what is a variable declaration, it'd be nice to point out that the two types must be the same. In this case, I'd write:
"The type of a variable cannot change once declared. If you want the type of x
to change, you must redeclare it but you'll lose its previous content. Otherwise you can just store the other data into a new variable."
Maybe add a link to the variable chapter in the book in case the user really doesn't know how it works.
And then you put examples which show it. Did it help?
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.
yep, that was useful. I will push a new commit tomorrow, amending the explanation.
@GuillaumeGomez modified the error desc. Let me know if it still requires something. |
fn return_bool(&self, &Self::Bar, &Self::Baz) -> bool; | ||
} | ||
``` | ||
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 comment
The reason will be displayed to describe this comment to others. Learn more.
Missing an empty line before this paragraph.
Ok, so it remains two last nits and an invalid erroneous code example which doesn't throw E0406. |
but why doesn't it throw that error? like I said, I always assumed E0220 was a fallback error.... |
I dug deeper into the codebase, and found that an error is thrown when the type of Generic matches something called |
It might be worth to report an issue if E0406 is a better match for the error than E0220. |
👍 Will do. |
reference for PR: # #32777
r? @GuillaumeGomez
Please review it :)