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 spurious E0283 when a generic trait is implemented over &'a T and a nonexistent type #106351

Closed
Heliozoa opened this issue Jan 1, 2023 · 1 comment · Fixed by #106309
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

@Heliozoa
Copy link
Contributor

Heliozoa commented Jan 1, 2023

Inspired by https://users.rust-lang.org/t/creating-daemon-processes/86832/3

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

pub struct S;

trait Generic<T> {}

impl<'a, T> Generic<&'a T> for S {}
impl Generic<Type> for S {}

The current output is:

Compiling playground v0.0.1 (/playground)
error[[E0412]](https://doc.rust-lang.org/stable/error-index.html#E0412): cannot find type `Type` in this scope
 --> src/lib.rs:6:14
  |
6 | impl Generic<Type> for S {}
  |              ^^^^ not found in this scope
  |
help: consider importing one of these items
  |
1 | [use postgres::types::Type;](https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=112302a0ad4af6da9c2acf936c4defea#)
  |
1 | [use postgres_types::Type;](https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=112302a0ad4af6da9c2acf936c4defea#)
  |
1 | [use psl_types::Type;](https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=112302a0ad4af6da9c2acf936c4defea#)
  |
1 | [use publicsuffix::Type;](https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=112302a0ad4af6da9c2acf936c4defea#)
  |
    and 6 other candidates

error[[E0283]](https://doc.rust-lang.org/stable/error-index.html#E0283): type annotations needed: cannot satisfy `S: Generic<&'a T>`
 --> src/lib.rs:5:13
  |
5 | impl<'a, T> Generic<&'a T> for S {}
  |             ^^^^^^^^^^^^^^
  |
note: multiple `impl`s satisfying `S: Generic<&'a T>` found
 --> src/lib.rs:5:1
  |
5 | impl<'a, T> Generic<&'a T> for S {}
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6 | impl Generic<Type> for S {}
  | ^^^^^^^^^^^^^^^^^^^^^^^^

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

Ideally the output should not include the second error E0283 as it doesn't make sense.

Interestingly, this problem disappears if the lifetime parameter is dropped from the first impl. The code

pub struct S;

trait Generic<T> {}

impl Generic<u32> for S {}
impl Generic<&'static u32> for S {}
impl Generic<Type> for S {}

results in the expected compiler output:

Compiling playground v0.0.1 (/playground)
error[[E0412]](https://doc.rust-lang.org/stable/error-index.html#E0412): cannot find type `Type` in this scope
 --> src/lib.rs:7:14
  |
7 | impl Generic<Type> for S {}
  |              ^^^^ not found in this scope
  |
help: consider importing one of these items
  |
1 | [use postgres::types::Type;](https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=112302a0ad4af6da9c2acf936c4defea#)
  |
1 | [use postgres_types::Type;](https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=112302a0ad4af6da9c2acf936c4defea#)
  |
1 | [use psl_types::Type;](https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=112302a0ad4af6da9c2acf936c4defea#)
  |
1 | [use publicsuffix::Type;](https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=112302a0ad4af6da9c2acf936c4defea#)
  |
    and 6 other candidates

For more information about this error, try `rustc --explain E0412`.
error: could not compile `playground` due to previous error
@Heliozoa Heliozoa 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 Jan 1, 2023
@compiler-errors
Copy link
Member

Modified #106309 so that the PR fixes this as well:

RUST ➜  rust2 git:(prefer-non-err-candidates) ✗ rustc +rust2 ~/test.rs
error[E0412]: cannot find type `Type` in this scope
 --> /home/ubuntu/test.rs:6:14
  |
6 | impl Generic<Type> for S {}
  |     -        ^^^^ not found in this scope
  |     |
  |     help: you might be missing a type parameter: `<Type>`

error: aborting due to previous error

@compiler-errors compiler-errors self-assigned this Jan 1, 2023
JohnTitor pushed a commit to JohnTitor/rust that referenced this issue Jan 9, 2023
…didates, r=oli-obk

Prefer non-`[type error]` candidates during selection

Fixes rust-lang#102130
Fixes rust-lang#106351

r? types

note: Alternatively we could filter out error where-clauses during param-env construction? But we still need to filter out impls with errors during `match_impl`, I think.
compiler-errors added a commit to compiler-errors/rust that referenced this issue Jan 9, 2023
…didates, r=oli-obk

Prefer non-`[type error]` candidates during selection

Fixes rust-lang#102130
Fixes rust-lang#106351

r? types

note: Alternatively we could filter out error where-clauses during param-env construction? But we still need to filter out impls with errors during `match_impl`, I think.
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this issue Jan 12, 2023
…didates, r=oli-obk

Prefer non-`[type error]` candidates during selection

Fixes rust-lang#102130
Fixes rust-lang#106351

r? types

note: Alternatively we could filter out error where-clauses during param-env construction? But we still need to filter out impls with errors during `match_impl`, I think.
@bors bors closed this as completed in 9b538e8 Jan 12, 2023
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