-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should avoid pointing at ADTs in std
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pointing to any other crate isn't very helpful imo. std
isn't special. Just giving the full module path to them should suffice.
}; | ||
|
||
if let Some(def) = actual.ty_adt_def() { | ||
if let Some(full_sp) = tcx.hir.span_if_local(def.did) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks on travis like it's doing the right thing now
@@ -29,6 +29,6 @@ fn main() { | |||
|
|||
let xe1 = XEmpty1; //~ ERROR expected value, found struct `XEmpty1` | |||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add tests for all these new variations of diagnostics?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
r=me after adding tests (#46024 (comment)) |
Hi @estebank, could you add the tests as requested by @petrochenkov in #46024 (review)? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added tests cases.
@bors r=petrochenkov
} 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
@bors r=petrochenkov These commands don't work in review comments 😄 |
📌 Commit c90b26d has been approved by |
@bors r- Trailing whitespace in the tests.
|
src/test/compile-fail/issue-23173.rs
Outdated
//~^ ERROR no function or associated item named `method` found for type | ||
//~| NOTE function or associated item not found in `Struct` | ||
Struct::Assoc; | ||
//~^ ERROR no associated item named `Assoc` found for type `Struct` in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(This line)
📌 Commit b450aff has been approved by |
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(..) =>(), | ^^^^^^^^^^^^^ ```
☀️ 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.