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

Simplify error message with removing lifetime and reference information #76903

Closed
tronta opened this issue Sep 19, 2020 · 5 comments
Closed

Simplify error message with removing lifetime and reference information #76903

tronta opened this issue Sep 19, 2020 · 5 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints D-verbose Diagnostics: Too much output caused by a single piece of incorrect code. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@tronta
Copy link
Contributor

tronta commented Sep 19, 2020

The following code provides the following error message:

fn main() {
    "jjj".to_de();
}
error[E0599]: no method named `to_de` found for reference `&'static str` in the current scope
 --> src/main.rs:2:11
  |
2 |     "jjj".to_de();
  |           ^^^^^ method not found in `&'static str`

this could be reduced to

error[E0599]: no method named `to_de` found for `str` in the current scope
 --> src/main.rs:2:11
  |
2 |     "jjj".to_de();
  |           ^^^^^ method not found in `str`

as . is automatically dereferencing and the lifetime also does not matter for this error.

@jyn514 jyn514 added A-diagnostics Area: Messages for errors, warnings, and lints D-verbose Diagnostics: Too much output caused by a single piece of incorrect code. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Sep 19, 2020
@Aaron1011
Copy link
Member

If the method is missing, we cannot know what components of the type may or not matter. For example, the user could have typo'd the following hypothetical method:

impl &'static str {
	fn to_df(self) {}
}

@tronta
Copy link
Contributor Author

tronta commented Sep 19, 2020

Maybe I just don't get what exactly you mean, but what exactly is missing if I just see the error

error[E0599]: no method named `to_de` found for `str` in the current scope
 --> src/main.rs:2:11
  |
2 |     "jjj".to_de();
  |           ^^^^^ method not found in `str`

I personally don't miss &'static

@Aaron1011
Copy link
Member

I don't think we should be displaying a 'simplified' version of the actual type of the method receiver, based on where we think the actual method will be defined.

Also, using #![feature(unsized_locals)] allows you to actually have a local variable of type str (see #48055). If we 'simplify' the error message, the user can no longer tell if the local has type str or &'static str.

@tronta
Copy link
Contributor Author

tronta commented Sep 20, 2020

Ah. So maybe add that this is a type:

error[E0599]: no method named `to_de` found for type `str` in the current scope
 --> src/main.rs:2:11
  |
2 |     "jjj".to_de();
  |           ^^^^^ method not found for type `str`

@tronta tronta closed this as completed Sep 27, 2020
@tronta
Copy link
Contributor Author

tronta commented Sep 27, 2020

Ok, so I close it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints D-verbose Diagnostics: Too much output caused by a single piece of incorrect code. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants