Skip to content
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

Closed
wants to merge 4 commits into from

Conversation

nikhilshagri
Copy link
Contributor

reference for PR: # #32777

r? @GuillaumeGomez

Please review it :)

@rust-highfive
Copy link
Collaborator

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
Copy link
Member

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. 😉

@GuillaumeGomez
Copy link
Member

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." 😺

@nikhilshagri
Copy link
Contributor Author

@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
Copy link
Member

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure.

@GuillaumeGomez
Copy link
Member

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.

@nikhilshagri
Copy link
Contributor Author

@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
Copy link
Member

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.

Copy link
Contributor Author

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. 😕

Copy link
Member

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?

Copy link
Contributor Author

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.

@nikhilshagri
Copy link
Contributor Author

@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
Copy link
Member

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.

@GuillaumeGomez
Copy link
Member

Ok, so it remains two last nits and an invalid erroneous code example which doesn't throw E0406.

@nikhilshagri
Copy link
Contributor Author

but why doesn't it throw that error? like I said, I always assumed E0220 was a fallback error....

@GuillaumeGomez
Copy link
Member

Sorry but I really don't know.

cc @eddyb
cc @brson

@nikhilshagri
Copy link
Contributor Author

I dug deeper into the codebase, and found that an error is thrown when the type of Generic matches something called EqPredicate; which is currently unimplemented, also here. Seems like I picked the wrong issue to fix.
Well, I think I'm gonna pick some other issue to fix, and verify that the error is actually thrown before proceeding further 😜

@GuillaumeGomez
Copy link
Member

It might be worth to report an issue if E0406 is a better match for the error than E0220.

@nikhilshagri
Copy link
Contributor Author

👍 Will do.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants