Skip to content

Commit a4ee7f8

Browse files
committed
Add regression test for 128705
1 parent 5dbf406 commit a4ee7f8

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Test that E0038 is not emitted twice for the same trait object coercion
2+
// regression test for issue <https://github.com/rust-lang/rust/issues/128705>
3+
4+
#![allow(dead_code)]
5+
6+
trait Tr {
7+
const N: usize;
8+
}
9+
10+
impl Tr for u8 {
11+
const N: usize = 1;
12+
}
13+
14+
fn main() {
15+
let x: &dyn Tr = &0_u8;
16+
//~^ ERROR E0038
17+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
error[E0038]: the trait `Tr` is not dyn compatible
2+
--> $DIR/no-duplicate-e0038.rs:15:17
3+
|
4+
LL | let x: &dyn Tr = &0_u8;
5+
| ^^ `Tr` is not dyn compatible
6+
|
7+
note: for a trait to be dyn compatible it needs to allow building a vtable
8+
for more information, visit <https://doc.rust-lang.org/reference/items/traits.html#dyn-compatibility>
9+
--> $DIR/no-duplicate-e0038.rs:7:11
10+
|
11+
LL | trait Tr {
12+
| -- this trait is not dyn compatible...
13+
LL | const N: usize;
14+
| ^ ...because it contains this associated `const`
15+
= help: consider moving `N` to another trait
16+
= help: only type `u8` implements `Tr`; consider using it directly instead.
17+
18+
error: aborting due to 1 previous error
19+
20+
For more information about this error, try `rustc --explain E0038`.

0 commit comments

Comments
 (0)