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

Confusing additional errors following a [E0412]: cannot find type T in this scope #95408

Closed
ekuecks opened this issue Mar 28, 2022 · 1 comment · Fixed by #95749
Closed

Confusing additional errors following a [E0412]: cannot find type T in this scope #95408

ekuecks opened this issue Mar 28, 2022 · 1 comment · Fixed by #95749
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@ekuecks
Copy link

ekuecks commented Mar 28, 2022

Given the following code: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=c95a5c248a2a9b88242ae9bb08b1a836

fn foo() where T: Send {
    let s = "abc".to_string();
}

The current output is:

error[[E0412]](https://doc.rust-lang.org/nightly/error-index.html#E0412): cannot find type `T` in this scope
 [--> src/lib.rs:1:16
](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021#)  |
1 | fn foo() where T: Send {
  |       -        ^ not found in this scope
  |       |
  |       help: you might be missing a type parameter: `<T>`

error[[E0282]](https://doc.rust-lang.org/nightly/error-index.html#E0282): type annotations needed
 [--> src/lib.rs:2:19
](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021#)  |
2 |     let s = "abc".to_string();
  |                   ^^^^^^^^^ cannot infer type
  |
  = note: type must be known at this point

error[[E0599]](https://doc.rust-lang.org/nightly/error-index.html#E0599): no method named `to_string` found for reference `&'static str` in the current scope
 [--> src/lib.rs:2:19
](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021#)  |
2 |     let s = "abc".to_string();
  |                   ^^^^^^^^^ method not found in `&'static str`

Some errors have detailed explanations: E0282, E0412, E0599.
For more information about an error, try `rustc --explain E0282`.
error: could not compile `playground` due to 3 previous errors

The first error is great, but the other ones are quite strange. Ideally the output would not have them and look like:

error[[E0412]](https://doc.rust-lang.org/nightly/error-index.html#E0412): cannot find type `T` in this scope
 [--> src/lib.rs:1:16
](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021#)  |
1 | fn foo() where T: Send {
  |       -        ^ not found in this scope
  |       |
  |       help: you might be missing a type parameter: `<T>`

Output is the same on stable and nightly

@ekuecks ekuecks added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Mar 28, 2022
@compiler-errors
Copy link
Member

@rustbot claim

fee1-dead added a commit to fee1-dead-contrib/rust that referenced this issue Apr 15, 2022
only downgrade selection Error -> Ambiguous if type error is in predicate

That is, we don't care if there's a TypeError type in the ParamEnv.

Fixes rust-lang#95408
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this issue Apr 15, 2022
only downgrade selection Error -> Ambiguous if type error is in predicate

That is, we don't care if there's a TypeError type in the ParamEnv.

Fixes rust-lang#95408
@bors bors closed this as completed in 7478294 Apr 15, 2022
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 T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants