Skip to content
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

Merged
merged 4 commits into from
Nov 23, 2017

Conversation

estebank
Copy link
Contributor

@estebank estebank commented Nov 16, 2017

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(..) =>(),
  |         ^^^^^^^^^^^^^

When using a non-existing variant, function or associated item, refer to
the proper term, instead of defaulting to "associated item" in
diagnostics.
@kennytm kennytm added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Nov 16, 2017
@estebank estebank changed the title [WIP] Use the proper term when using non-existing variant Use the proper term when using non-existing variant Nov 16, 2017
@petrochenkov petrochenkov self-assigned this Nov 16, 2017
@estebank
Copy link
Contributor Author

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 std out of it.

::: $DIR/auxiliary/no_method_suggested_traits.rs
|
14 | pub enum Bar { X }
| ------------ method `method3` not found here
Copy link
Contributor Author

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
Copy link
Contributor Author

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.

Copy link
Contributor

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) {
Copy link
Contributor Author

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.

Copy link
Contributor

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
Copy link
Contributor

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"
Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@petrochenkov
Copy link
Contributor

r=me after adding tests (#46024 (comment))

@petrochenkov petrochenkov added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 18, 2017
@kennytm
Copy link
Member

kennytm commented Nov 22, 2017

Hi @estebank, could you add the tests as requested by @petrochenkov in #46024 (review)?

Copy link
Contributor Author

@estebank estebank left a 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"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@kennytm
Copy link
Member

kennytm commented Nov 22, 2017

@bors r=petrochenkov

These commands don't work in review comments 😄

@bors
Copy link
Contributor

bors commented Nov 22, 2017

📌 Commit c90b26d has been approved by petrochenkov

@kennytm
Copy link
Member

kennytm commented Nov 22, 2017

@bors r-

Trailing whitespace in the tests.

[00:04:28] tidy error: /checkout/src/test/compile-fail/issue-23173.rs:33: trailing whitespace

//~^ 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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(This line)

@estebank
Copy link
Contributor Author

@kennytm fixed.
@bors r=petrochenkov

@bors
Copy link
Contributor

bors commented Nov 23, 2017

📌 Commit b450aff has been approved by petrochenkov

@bors
Copy link
Contributor

bors commented Nov 23, 2017

⌛ Testing commit b450aff with merge a6031a2...

bors added a commit that referenced this pull request 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
Copy link
Contributor

bors commented Nov 23, 2017

☀️ Test successful - status-appveyor, status-travis
Approved by: petrochenkov
Pushing a6031a2 to master...

@bors bors merged commit b450aff into rust-lang:master Nov 23, 2017
@estebank estebank deleted the no-variant branch November 9, 2023 05:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants