Skip to content

Fix negative traits coherence checks compile error message for type aliases #90259

Open

Description

@spastorino

Follow up of this comment on #90104

This test https://github.com/rust-lang/rust/pull/90104/files#diff-2c291b05493bf924a05c167ef3923655ca244b6fd8bc2303ffdc2ed2132498cc is giving an ungreat error message.

#![feature(rustc_attrs)]
#![feature(trait_alias)]

trait A {}
trait B {}
trait AB = A + B;

impl A for u32 {}
impl B for u32 {}

trait C {}
#[rustc_strict_coherence]
impl<T: AB> C for T {}
#[rustc_strict_coherence]
impl C for u32 {}
//~^ ERROR
// FIXME it's giving an ungreat error but unsure if we care given that it's using an internal rustc
// attribute and an artificial code path for testing purposes

fn main() {}

fails with ...

error[E0283]: type annotations needed
  --> $DIR/coherence-overlap-trait-alias.rs:15:6
   |
LL | impl C for u32 {}
   |      ^ cannot infer type for type `u32`
   |
   = note: cannot satisfy `u32: C`
note: required by a bound in `C`
  --> $DIR/coherence-overlap-trait-alias.rs:11:1
   |
LL | trait C {}
   | ^^^^^^^ required by this bound in `C`

error: aborting due to previous error

Error should mention about conflicting implementations for u32 or something like that. More similar to what happens without using the rustc_strict_coherence attribute.

Activity

  1. added
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    on Oct 25, 2021
  2. spastorino commented on Oct 25, 2021

    @spastorino
    MemberAuthor

    As an effect of @estebank's PR #89427 this error is now a bit better but it's still not there compared with the no strict version.
    Anyway, not a extremely important thing given that this can only be raised by using rustc_strict_coherence which is an internal rustc attribute.

  3. added
    A-diagnosticsArea: Messages for errors, warnings, and lints
    D-incorrectDiagnostics: A diagnostic that is giving misleading or incorrect information.
    on Oct 25, 2021
  4. added
    F-rustc_attrsInternal rustc attributes gated on the `#[rustc_attrs]` feature gate.
    on Mar 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsD-incorrectDiagnostics: A diagnostic that is giving misleading or incorrect information.F-negative_impls#![feature(negative_impls)]F-rustc_attrsInternal rustc attributes gated on the `#[rustc_attrs]` feature gate.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions