Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upError messages should indicate when a method is missing due to unsatisfied constraints #26516
Comments
sfackler
added
the
A-diagnostics
label
Jun 23, 2015
This comment has been minimized.
This comment has been minimized.
|
This may be more complicated to do then it seems. I'll look into it though, would be nice to help guide users though. |
This comment has been minimized.
This comment has been minimized.
|
Comment from Matthieu M. on Stack Overflow:
|
This comment has been minimized.
This comment has been minimized.
|
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 |
This comment has been minimized.
This comment has been minimized.
|
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 comment has been minimized.
This comment has been minimized.
|
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:
|
This comment has been minimized.
This comment has been minimized.
|
I'm wondering if this message could be improved further. It seems confusing to me for it to say |
brson
added
I-wishlist
T-compiler
labels
Jan 26, 2017
This comment has been minimized.
This comment has been minimized.
|
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. |
DanielKeep commentedJun 23, 2015
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.)