Uh oh!
There was an error while loading. Please reload this page.
Use the proper term when using non-existing variant - #46024
Conversation
When using a non-existing variant, function or associated item, refer to the proper term, instead of defaulting to "associated item" in diagnostics.
estebank
commented
Nov 16, 2017
The output of the pointing to the source ADT that doesn't have the variant/method/field doesn't really work that well for some types. I'm gonna expand on it to keep |
| ::: $DIR/auxiliary/no_method_suggested_traits.rs | ||
| | | ||
| 14 | pub enum Bar { X } | ||
| | ------------ method `method3` not found here |
There was a problem hiding this comment.
It should be method method2 not found for this
| ::: /checkout/src/liballoc/rc.rs | ||
| | | ||
| 284 | pub struct Rc<T: ?Sized> { | ||
| | ------------------------ method `method3` not found for this |
There was a problem hiding this comment.
We should avoid pointing at ADTs in std.
There was a problem hiding this comment.
Pointing to any other crate isn't very helpful imo. std isn't special. Just giving the full module path to them should suffice.
There was a problem hiding this comment.
@oli-obk I don't know if this will actually do what I want it to do. After the test suite runs I'll see. If the output is still suboptimal, I'll leave the PR with only the first commit for merging.
There was a problem hiding this comment.
Looks on travis like it's doing the right thing now
| let xe1 = XEmpty1(); //~ ERROR expected function, found struct `XEmpty1` | ||
| let xe3 = XE::Empty3; //~ ERROR no associated item named `Empty3` found for type | ||
| let xe3 = XE::Empty3(); //~ ERROR no associated item named `Empty3` found for type | ||
| let xe3 = XE::Empty3; //~ ERROR no variant named `Empty3` found for type |
There was a problem hiding this comment.
In this context nothing suggests for sure that Empty3 is a variant and not an associated constant or method.
At the same time, in other contexts like tuple struct patterns match { E::X(..) => {} } we can say for sure that X is a variant, but in this PR diagnostics are not context-dependent, only guessing based on case etc is used.
What I'd want to see is a context-dependent message worded and formatted uniformly with other "expected, (not) found" resolution diagnostics.
This is a bit vague and this PR is still an improvement, so I won't block this PR on these changes.
(I'm basically adding a "rewrite this from scratch" item in my TODO list now.)
| } else { | ||
| match (item_name.as_str().chars().next(), actual.is_fresh_ty()) { | ||
| (Some(name), false) if name.is_lowercase() => { | ||
| "function or associated item" |
There was a problem hiding this comment.
Could you add tests for all these new variations of diagnostics?
petrochenkov
commented
Nov 18, 2017
r=me after adding tests (#46024 (comment)) |
kennytm
commented
Nov 22, 2017
Hi @estebank, could you add the tests as requested by @petrochenkov in #46024 (review)? |
| } else { | ||
| match (item_name.as_str().chars().next(), actual.is_fresh_ty()) { | ||
| (Some(name), false) if name.is_lowercase() => { | ||
| "function or associated item" |
kennytm
commented
Nov 22, 2017
@bors r=petrochenkov These commands don't work in review comments 😄 |
bors
commented
Nov 22, 2017
📌 Commit c90b26d has been approved by |
kennytm
commented
Nov 22, 2017
@bors r- Trailing whitespace in the tests. |
estebank
commented
Nov 23, 2017
bors
commented
Nov 23, 2017
📌 Commit b450aff has been approved by |
bors
commented
Nov 23, 2017
Use the proper term when using non-existing variant When using a non-existing variant, function or associated item, refer to the proper term, instead of defaulting to "associated item" in diagnostics. Fix#28972. ``` error[E0599]: no variant named `Quux` found for type `Foo` in the current scope --> file.rs:7:9 | 7 | Foo::Quux(..) =>(), | ^^^^^^^^^^^^^ ```
bors
commented
Nov 23, 2017
☀️ Test successful - status-appveyor, status-travis |
When using a non-existing variant, function or associated item, refer to
the proper term, instead of defaulting to "associated item" in
diagnostics.
Fix#28972.