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

bad diagnostic for trait impl requirement #123292

Closed
Mark-Simulacrum opened this issue Mar 31, 2024 · 2 comments · Fixed by #123674
Closed

bad diagnostic for trait impl requirement #123292

Mark-Simulacrum opened this issue Mar 31, 2024 · 2 comments · Fixed by #123674
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-traits Area: Trait system D-confusing Diagnostics: Confusing error or lint that should be reworked. S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@Mark-Simulacrum
Copy link
Member

Noticed in Crater, seems like it's probably a regression but just in quality (this is entirely new AFAICT):

[INFO] [stderr] note: the requirement `_ <: _` appears on the `impl`'s method `try_from` but not on the corresponding trait's method
[INFO] [stderr]  --> $RUST/core/src/convert/mod.rs
[INFO] [stderr]   |
[INFO] [stderr]   = note: in this trait
[INFO] [stderr]  ::: $RUST/core/src/convert/mod.rs
[INFO] [stderr]   |
[INFO] [stderr]   = note: this trait's method doesn't have the requirement `_ <: _`

Saying that "_ <: _" is probably useless to 99% of readers, and <: in general feels a bit internal-y to me?

@Mark-Simulacrum Mark-Simulacrum added the A-diagnostics Area: Messages for errors, warnings, and lints label Mar 31, 2024
@fmease fmease added A-traits Area: Trait system T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. D-confusing Diagnostics: Confusing error or lint that should be reworked. E-needs-mcve Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example labels Mar 31, 2024
@fmease
Copy link
Member

fmease commented Apr 1, 2024

Inlining the reproducer (not minimized yet):

// requires dependency `enumorph`, version 0.1.2
#[derive(enumorph::Enumorph)]
enum Enum {
    A(u8),
    B { c: u8 },
}

fn main() {}
Compiler output diff (stable vs. nightly)
  error[E0119]: conflicting implementations of trait `TryFrom<Enum>` for type `u8`
   --> src/main.rs:4:12
    |
  3 |     A(u8),
    |       -- first implementation here
  4 |     B { c: u8 },
    |            ^^ conflicting implementation for `u8`
  
+ error[E0282]: type annotations needed
+    --> src/main.rs:3:7
+     |
+ 3   |     A(u8),
+     |       ^^ cannot infer type
+     |
+ note: the requirement `_ <: _` appears on the `impl`'s method `try_from` but not on the corresponding trait's method
+    --> /home/fmease/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/convert/mod.rs:687:8
+     |
+ 679 | pub trait TryFrom<T>: Sized {
+     |           ------- in this trait
+ ...
+ 687 |     fn try_from(value: T) -> Result<Self, Self::Error>;
+     |        ^^^^^^^^ this trait's method doesn't have the requirement `_ <: _`
+ 
  error[E0119]: conflicting implementations of trait `From<u8>` for type `Enum`
   --> src/main.rs:4:12
    |
  3 |     A(u8),
    |       -- first implementation here
  4 |     B { c: u8 },
    |            ^^ conflicting implementation for `Enum`
  
+ error[E0282]: type annotations needed
+    --> src/main.rs:4:12
+     |
+ 4   |     B { c: u8 },
+     |            ^^ cannot infer type
+     |
+ note: the requirement `_ <: _` appears on the `impl`'s method `try_from` but not on the corresponding trait's method
+    --> /home/fmease/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/convert/mod.rs:687:8
+     |
+ 679 | pub trait TryFrom<T>: Sized {
+     |           ------- in this trait
+ ...
+ 687 |     fn try_from(value: T) -> Result<Self, Self::Error>;
+     |        ^^^^^^^^ this trait's method doesn't have the requirement `_ <: _`
+ 

Meaning we previously suppressed those useless type annotations needed diagnostics. This smells like a regression caused by one of @oli-obk's PRs that make rustc continue analysis even if there were errors in some previous passes / stages.

@fmease
Copy link
Member

fmease commented Apr 1, 2024

Minimized:

//@ edition: 2021

struct Ty;

impl TryFrom<Ty> for u8 {
    type Error = Ty;
    fn try_from(_: Ty) -> Result<Self, Self::Error> {
        loop {}
    }
}

impl TryFrom<Ty> for u8 {
    type Error = Ty;
    fn try_from(_: Ty) -> Result<Self, Self::Error> {
        loop {}
    }
}

fn main() {}

@fmease fmease added S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue and removed E-needs-mcve Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example labels Apr 1, 2024
@oli-obk oli-obk self-assigned this Apr 1, 2024
bors added a commit to rust-lang-ci/rust that referenced this issue Apr 9, 2024
Silence some follow-up errors on trait impls in case the trait has conflicting or otherwise incoherent impls

fixes rust-lang#123292

Also removes a bunch of extra diagnostics that were introduced in rust-lang#121154 and rust-lang#120558
bors added a commit to rust-lang-ci/rust that referenced this issue Apr 10, 2024
Silence some follow-up errors on trait impls in case the trait has conflicting or otherwise incoherent impls

fixes rust-lang#123292

Also removes a bunch of extra diagnostics that were introduced in rust-lang#121154 and rust-lang#120558
@bors bors closed this as completed in 00ed4ed Apr 17, 2024
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 A-traits Area: Trait system D-confusing Diagnostics: Confusing error or lint that should be reworked. S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
3 participants