-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Confusing Error Message On Not Specifying Trait Bound In Generic Function Signature #41030
Comments
Today, we suggest that the method exists, but we somehow fail to see that it exists on Minimum in the first note and then latter note it in the second note.
|
It still doesn't help a lot IMO... since the problem is the bound isn't declared in the signature, and nothing regarding declaration is mentioned.
maybe change to
|
I think that can be easily fixed by checking if Do you have suggestion how the error should look like? Does that sound ok?
|
@pornel From my perspective, I think the problem is one of asymmetry in the help section. It mentioned "items from traits can only be used if the trait is implemented and in scope", but then went on to only suggest "perhaps you need to implement one of them". Excuse me for being insistent on this, but I believe the best way is to remind that to bring function into scope the trait bound needs to be declared as well as implemented. |
LOL this is actually a duplicate of #21673 . There's even a FIXME note in the source. |
@louy2 I think we're talking about different cases (which may be another reason to split or reword the message). For methods the message says "method not found", but adds a note saying "the method exists", which I really don't like, because it's very easy to miss the nuance and interpret the message as nonsense "the method does not exist" "but it exists". I've explained more here: https://internals.rust-lang.org/t/multiple-variants-of-the-same-erorr-message/6002 |
With #62772 the output will be:
|
Suggest trait bound on type parameter when it is unconstrained Given ``` trait Foo { fn method(&self) {} } fn call_method<T>(x: &T) { x.method() } ``` suggest constraining `T` with `Foo`. Fix rust-lang#21673, fix rust-lang#41030.
Suggest trait bound on type parameter when it is unconstrained Given ``` trait Foo { fn method(&self) {} } fn call_method<T>(x: &T) { x.method() } ``` suggest constraining `T` with `Foo`. Fix rust-lang#21673, fix rust-lang#41030.
Suggest trait bound on type parameter when it is unconstrained Given ``` trait Foo { fn method(&self) {} } fn call_method<T>(x: &T) { x.method() } ``` suggest constraining `T` with `Foo`. Fix rust-lang#21673, fix rust-lang#41030.
I am working through this Rust-101 tutorial and is faced with such a challenge:
So I tried it. Rust complained, but in a pretty confusing way:
The minimal code that produces the error message is
The error message tells me that I need to implement a trait. Since I have already implemented it, I would be confused by the error message, and misled by it from the actual reason, failure to declare it in the signature. I think it would be better if the message is changed to
On the other hand, if I actually drop the block
impl Minimum for i32
, but declareMinimum
in the signature, the error message iswhich is straightforward enough.
The text was updated successfully, but these errors were encountered: