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

Noisy conflicting implementations error for a trait which has a const generic parameter that panics in multiple implementations #103369

Closed
Imberflur opened this issue Oct 21, 2022 · 3 comments · Fixed by #121308
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

@Imberflur
Copy link

I tried this code:

pub trait ConstGenericTrait<const N: u32> {}

impl ConstGenericTrait<{my_fn(1)}> for () {}

impl ConstGenericTrait<{my_fn(2)}> for () {}

const fn my_fn(v: u32) -> u32 {
    panic!("Some error occurred");
}

I expected to see this happen:

Only errors due to the const panic being displayed
error[[E0080]](https://doc.rust-lang.org/nightly/error-index.html#E0080): evaluation of constant value failed
 --> src/lib.rs:8:5
  |
3 | impl ConstGenericTrait<{my_fn(1)}> for () {}
  |                         -------- inside `<() as ConstGenericTrait<{my_fn(1)}>>::{constant#0}` at src/lib.rs:3:25
...
8 |     panic!("Some error occurred");
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |     |
  |     the evaluated program panicked at 'Some error occurred', src/lib.rs:8:5
  |     inside `my_fn` at /rustc/dcb376115066d111dbf5f13d5ac2a2dbe8c12add/library/core/src/panic.rs:57:9
  |
  = note: this error originates in the macro `$crate::panic::panic_2021` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)

error[[E0080]](https://doc.rust-lang.org/nightly/error-index.html#E0080): evaluation of constant value failed
 --> src/lib.rs:8:5
  |
5 | impl ConstGenericTrait<{my_fn(2)}> for () {}
  |                         -------- inside `<() as ConstGenericTrait<{my_fn(2)}>>::{constant#0}` at src/lib.rs:5:25
...
8 |     panic!("Some error occurred");
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |     |
  |     the evaluated program panicked at 'Some error occurred', src/lib.rs:8:5
  |     inside `my_fn` at /rustc/dcb376115066d111dbf5f13d5ac2a2dbe8c12add/library/core/src/panic.rs:57:9
  |
  = note: this error originates in the macro `$crate::panic::panic_2021` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)

Instead, this happened:

In addition to the expected errors there is a conflicting implementation error showing the const generic as `[const error]`
error[[E0119]](https://doc.rust-lang.org/nightly/error-index.html#E0119): conflicting implementations of trait `ConstGenericTrait<[const error]>` for type `()`
 --> src/lib.rs:5:1
  |
3 | impl ConstGenericTrait<{my_fn(1)}> for () {}
  | ----------------------------------------- first implementation here
4 |
5 | impl ConstGenericTrait<{my_fn(2)}> for () {}
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `()`

This introduces excessive noise in the error output when there are many implementations like this.

https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=5d63f992f258ee299a5d13cfa4b0d4a1

Meta

Present on all toolchains on the playground (at the time of posting):
image

Locally I'm using an older nightly toolchain:
rustc --version --verbose:

rustc 1.63.0-nightly (dc80ca78b 2022-06-21)
binary: rustc
commit-hash: dc80ca78b6ec2b6bba02560470347433bcd0bb3c
commit-date: 2022-06-21
host: x86_64-unknown-linux-gnu
release: 1.63.0-nightly
LLVM version: 14.0.5

@Imberflur Imberflur added the C-bug Category: This is a bug. label Oct 21, 2022
@Imberflur
Copy link
Author

I meant to use the Diagnostic issue template but I guess I clicked on the wrong one...

@Rageking8
Copy link
Contributor

I meant to use the Diagnostic issue template but I guess I clicked on the wrong one...

No worries.
@rustbot label +T-compiler +A-diagnostics -C-bug

@rustbot rustbot 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. and removed C-bug Category: This is a bug. labels Oct 22, 2022
@Imberflur
Copy link
Author

Imberflur commented Feb 17, 2023

Update: I found some additional variants to this issue. If the first const evaluation is successful it still reports a conflicting implementation error but reports the first successful value in the error (playground):

pub trait ConstGenericTrait<const N: u32> {}

impl ConstGenericTrait<{my_fn(3)}> for () {}

impl ConstGenericTrait<{my_fn(1)}> for () {}

impl ConstGenericTrait<{my_fn(2)}> for () {}

const fn my_fn(v: u32) -> u32 {
    if v == 2 { 
        panic!("Some error occurred")
    } else {
        v
    }
}
error[[E0080]](https://doc.rust-lang.org/stable/error_codes/E0080.html): evaluation of constant value failed
  --> src/lib.rs:11:9
   |
11 |         panic!("Some error occurred")
   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the evaluated program panicked at 'Some error occurred', src/lib.rs:11:9
   |
note: inside `my_fn`
  --> src/lib.rs:11:9
   |
11 |         panic!("Some error occurred")
   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: inside `<() as ConstGenericTrait<{my_fn(2)}>>::{constant#0}`
  --> src/lib.rs:7:25
   |
7  | impl ConstGenericTrait<{my_fn(2)}> for () {}
   |                         ^^^^^^^^
   = note: this error originates in the macro `$crate::panic::panic_2021` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)

error[[E0119]](https://doc.rust-lang.org/stable/error_codes/E0119.html): conflicting implementations of trait `ConstGenericTrait<3>` for type `()`
 --> src/lib.rs:7:1
  |
3 | impl ConstGenericTrait<{my_fn(3)}> for () {}
  | ----------------------------------------- first implementation here
...
7 | impl ConstGenericTrait<{my_fn(2)}> for () {}
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `()`

And if the first evaluation fails (but the others would be successful) it sees all implemenations as conflicting and shows the original ConstGenericTrait<[const error]> (playground):

pub trait ConstGenericTrait<const N: u32> {}

impl ConstGenericTrait<{my_fn(2)}> for () {}

impl ConstGenericTrait<{my_fn(3)}> for () {}

impl ConstGenericTrait<{my_fn(1)}> for () {}

const fn my_fn(v: u32) -> u32 {
    if v == 2 { 
        panic!("Some error occurred")
    } else {
        v
    }
}
error[[E0080]](https://doc.rust-lang.org/stable/error_codes/E0080.html): evaluation of constant value failed
  --> src/lib.rs:11:9
   |
11 |         panic!("Some error occurred")
   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the evaluated program panicked at 'Some error occurred', src/lib.rs:11:9
   |
note: inside `my_fn`
  --> src/lib.rs:11:9
   |
11 |         panic!("Some error occurred")
   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: inside `<() as ConstGenericTrait<{my_fn(2)}>>::{constant#0}`
  --> src/lib.rs:3:25
   |
3  | impl ConstGenericTrait<{my_fn(2)}> for () {}
   |                         ^^^^^^^^
   = note: this error originates in the macro `$crate::panic::panic_2021` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)

error[[E0119]](https://doc.rust-lang.org/stable/error_codes/E0119.html): conflicting implementations of trait `ConstGenericTrait<[const error]>` for type `()`
 --> src/lib.rs:5:1
  |
3 | impl ConstGenericTrait<{my_fn(2)}> for () {}
  | ----------------------------------------- first implementation here
4 |
5 | impl ConstGenericTrait<{my_fn(3)}> for () {}
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `()`

error[[E0119]](https://doc.rust-lang.org/stable/error_codes/E0119.html): conflicting implementations of trait `ConstGenericTrait<[const error]>` for type `()`
 --> src/lib.rs:7:1
  |
3 | impl ConstGenericTrait<{my_fn(2)}> for () {}
  | ----------------------------------------- first implementation here
...
7 | impl ConstGenericTrait<{my_fn(1)}> for () {}
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `()`

Compiler version 1.67.1

kadiwa4 added a commit to kadiwa4/rust that referenced this issue Feb 19, 2024
bors added a commit to rust-lang-ci/rust that referenced this issue Feb 20, 2024
Rollup of 10 pull requests

Successful merges:

 - rust-lang#120716 (Change leak check and suspicious auto trait lint warning messages)
 - rust-lang#121195 (unstable-book: Separate testing and production sanitizers)
 - rust-lang#121205 (Merge `CompilerError::CompilationFailed` and `CompilerError::ICE`.)
 - rust-lang#121233 (Move the extra directives for `Mode::CoverageRun` into `iter_header`)
 - rust-lang#121256 (Allow AST and HIR visitors to return `ControlFlow`)
 - rust-lang#121307 (Drive-by `DUMMY_SP` -> `Span` and fmt changes)
 - rust-lang#121308 (Add regression test for rust-lang#103369)
 - rust-lang#121310 (Remove an old hack for rustdoc)
 - rust-lang#121311 (Make `is_nonoverlapping` `#[inline]`)
 - rust-lang#121319 (return `ty::Error` when equating `ty::Error`)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors closed this as completed in 930566f Feb 20, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Feb 20, 2024
Rollup merge of rust-lang#121308 - kadiwa4:test_103369, r=TaKO8Ki

Add regression test for rust-lang#103369

The issue was fixed in 1.70.0.
Closes rust-lang#103369.
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.

3 participants