Closed
Description
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.
Meta
Present on all toolchains on the playground (at the time of posting):
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