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

implied_bounds_entailment diagnostic when associated type not in scope #112321

Closed
DaniPopes opened this issue Jun 5, 2023 · 0 comments · Fixed by #112322
Closed

implied_bounds_entailment diagnostic when associated type not in scope #112321

DaniPopes opened this issue Jun 5, 2023 · 0 comments · Fixed by #112322
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

@DaniPopes
Copy link
Contributor

DaniPopes commented Jun 5, 2023

Code

trait Identity {
    type Identity;
}
impl<T> Identity for T {
    type Identity = T;
}

trait Trait {
    type Assoc: Identity;
    fn tokenize(&self) -> <Self::Assoc as Identity>::Identity;
}

impl Trait for () {
    type Assoc = DoesNotExist;
    fn tokenize(&self) -> <Self::Assoc as Identity>::Identity {
        unimplemented!()
    }
}

Current output

error[E0412]: cannot find type `DoesNotExist` in this scope
  --> issue.rs:14:18
   |
14 |     type Assoc = DoesNotExist;
   |                  ^^^^^^^^^^^^ not found in this scope

error: impl method assumes more implied bounds than the corresponding trait method
  --> issue.rs:15:5
   |
15 |     fn tokenize(&self) -> <Self::Assoc as Identity>::Identity {
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
   = note: for more information, see issue #105572 <https://github.com/rust-lang/rust/issues/105572>
   = note: `#[deny(implied_bounds_entailment)]` on by default

Desired output

error[E0412]: cannot find type `DoesNotExist` in this scope
  --> issue.rs:14:18
   |
14 |     type Assoc = DoesNotExist;
   |                  ^^^^^^^^^^^^ not found in this scope

Rationale and extra context

When implementing the trait, if the associated type is set to something that is not in scope / doesn't exist, the compiler emits a implied_bounds_entailment diagnostic. I don't think this should be emitted because there is no way to calculate a type's trait bounds when it doesn't even exist.

Might be related to #108544, but I decided to file a separate issue because this does not involve any lifetimes.

Other cases

No response

Anything else?

Tested with stable 1.70.0, beta 1.71.0-beta.1 and nightly 1.72.0-nightly (d59363a 2023-06-01)

@DaniPopes DaniPopes 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 Jun 5, 2023
@compiler-errors compiler-errors self-assigned this Jun 5, 2023
@bors bors closed this as completed in dcdd867 Jun 6, 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