From a4ee7f896486006e3bf6e9ddbf59670c6ead10ee Mon Sep 17 00:00:00 2001 From: reddevilmidzy Date: Fri, 21 Nov 2025 23:03:39 +0900 Subject: [PATCH] Add regression test for 128705 --- .../dyn-compatibility/no-duplicate-e0038.rs | 17 ++++++++++++++++ .../no-duplicate-e0038.stderr | 20 +++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 tests/ui/dyn-compatibility/no-duplicate-e0038.rs create mode 100644 tests/ui/dyn-compatibility/no-duplicate-e0038.stderr diff --git a/tests/ui/dyn-compatibility/no-duplicate-e0038.rs b/tests/ui/dyn-compatibility/no-duplicate-e0038.rs new file mode 100644 index 000000000000..283164596d06 --- /dev/null +++ b/tests/ui/dyn-compatibility/no-duplicate-e0038.rs @@ -0,0 +1,17 @@ +// Test that E0038 is not emitted twice for the same trait object coercion +// regression test for issue + +#![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 +} diff --git a/tests/ui/dyn-compatibility/no-duplicate-e0038.stderr b/tests/ui/dyn-compatibility/no-duplicate-e0038.stderr new file mode 100644 index 000000000000..94037387c3e1 --- /dev/null +++ b/tests/ui/dyn-compatibility/no-duplicate-e0038.stderr @@ -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 + --> $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`.