-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Error messages should indicate when a method is missing due to unsatisfied constraints #26516
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
Comments
This may be more complicated to do then it seems. I'll look into it though, would be nice to help guide users though. |
Comment from Matthieu M. on Stack Overflow:
|
Yeah I believe that it is definitely implementable, just not sure if the internals are currently factored in such a way that will allow us to do this easily. I hope to have some time to generally improve trait resolution and indirectly error reporting this summer. Of course if some one else has a patch I'm sure everyone would be interested 😄 |
Big +1 to this, lots of people are bit by this. Including me: https://internals.rust-lang.org/t/better-error-message-when-method-name-matches-but-not-the-where-clause/1779 |
This seems to have been fixed by #26435: struct Foo;
fn get_res() -> Result<&'static str, Foo> { Ok("ok") }
fn main() {
let res1 = get_res();
assert!(res1.is_ok());
assert_eq!("just for test", res1.unwrap());
} Output:
|
I'm wondering if this message could be improved further. It seems confusing to me for it to say |
Since this is an old bug, there's a claim that it was fixed, and diagnostics have changed a lot, closing. Please open with updated suggestions based on current rustc. |
I've been seeing more and more questions along the lines of this StackOverflow question. A user tries to call a method that is in the docs, but the compiler insists it doesn't exist. It turns out that this is because the method is only implemented provided certain generic constraints are satisfied, but they aren't.
The compiler does not mention this.
The only way a new user would find out about this is if they scroll up from the documentation on the method, and realise that the
impl...
header applies to everything below it, which isn't immediately obvious.I think that the compiler should make a bit more of an effort here: if there is a method with the given name, but it doesn't satisfy one or more constraints, the compiler should at least add a note along the lines of:
Preferably, it would change the whole error from:
To something like:
(Language mangled a bit to put the potentially long type name at the end.)
The text was updated successfully, but these errors were encountered: