Add regression test for 128705

This commit is contained in:
reddevilmidzy 2025-11-21 23:03:39 +09:00
parent 5dbf4069dc
commit a4ee7f8964
2 changed files with 37 additions and 0 deletions

View file

@ -0,0 +1,17 @@
// Test that E0038 is not emitted twice for the same trait object coercion
// regression test for issue <https://github.com/rust-lang/rust/issues/128705>
#![allow(dead_code)]
trait Tr {
const N: usize;
}
impl Tr for u8 {
const N: usize = 1;
}
fn main() {
let x: &dyn Tr = &0_u8;
//~^ ERROR E0038
}

View file

@ -0,0 +1,20 @@
error[E0038]: the trait `Tr` is not dyn compatible
--> $DIR/no-duplicate-e0038.rs:15:17
|
LL | let x: &dyn Tr = &0_u8;
| ^^ `Tr` is not dyn compatible
|
note: for a trait to be dyn compatible it needs to allow building a vtable
for more information, visit <https://doc.rust-lang.org/reference/items/traits.html#dyn-compatibility>
--> $DIR/no-duplicate-e0038.rs:7:11
|
LL | trait Tr {
| -- this trait is not dyn compatible...
LL | const N: usize;
| ^ ...because it contains this associated `const`
= help: consider moving `N` to another trait
= help: only type `u8` implements `Tr`; consider using it directly instead.
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0038`.