Skip to content

Commit 4cd8492

Browse files
committed
test: Add regression test for ICE when projecting associated types through dyn traits
1 parent 1e1a394 commit 4cd8492

File tree

2 files changed

+77
-0
lines changed

2 files changed

+77
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Regression test for the projection bug in <https://github.com/rust-lang/rust/issues/123953>
2+
//
3+
// compile-flags: -Zincremental-verify-ich=yes -Cincremental=<dir> -Cdebuginfo=2
4+
5+
pub trait A {}
6+
pub trait B: A {}
7+
8+
pub trait Mirror {
9+
type Assoc: ?Sized;
10+
}
11+
12+
impl<T: ?Sized> Mirror for A {
13+
//~^ ERROR the type parameter `T` is not constrained by the impl trait, self type, or predicates [E0207]
14+
//~| WARN trait objects without an explicit `dyn` are deprecated [bare_trait_objects]
15+
//~| WARN this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021!
16+
type Assoc = T;
17+
}
18+
19+
pub fn foo<'a>(x: &'a <dyn A + 'static as Mirror>::Assoc) -> &'a <dyn B + 'static as Mirror>::Assoc {
20+
//~^ ERROR the trait bound `(dyn B + 'static): Mirror` is not satisfied [E0277]
21+
//~| ERROR the trait bound `(dyn B + 'static): Mirror` is not satisfied [E0277]
22+
static
23+
} //~ ERROR expected identifier, found `}`
24+
25+
pub fn main() {}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
error: expected identifier, found `}`
2+
--> $DIR/projection-dyn-associated-type.rs:23:1
3+
|
4+
LL | }
5+
| ^ expected identifier
6+
7+
warning: trait objects without an explicit `dyn` are deprecated
8+
--> $DIR/projection-dyn-associated-type.rs:12:28
9+
|
10+
LL | impl<T: ?Sized> Mirror for A {
11+
| ^
12+
|
13+
= warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021!
14+
= note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2021/warnings-promoted-to-error.html>
15+
= note: `#[warn(bare_trait_objects)]` (part of `#[warn(rust_2021_compatibility)]`) on by default
16+
help: if this is a dyn-compatible trait, use `dyn`
17+
|
18+
LL | impl<T: ?Sized> Mirror for dyn A {
19+
| +++
20+
help: alternatively use a blanket implementation to implement `Mirror` for all types that also implement `A`
21+
|
22+
LL - impl<T: ?Sized> Mirror for A {
23+
LL + impl<T: ?Sized, U: A> Mirror for U {
24+
|
25+
26+
error[E0207]: the type parameter `T` is not constrained by the impl trait, self type, or predicates
27+
--> $DIR/projection-dyn-associated-type.rs:12:6
28+
|
29+
LL | impl<T: ?Sized> Mirror for A {
30+
| ^ unconstrained type parameter
31+
32+
error[E0277]: the trait bound `(dyn B + 'static): Mirror` is not satisfied
33+
--> $DIR/projection-dyn-associated-type.rs:19:62
34+
|
35+
LL | pub fn foo<'a>(x: &'a <dyn A + 'static as Mirror>::Assoc) -> &'a <dyn B + 'static as Mirror>::Assoc {
36+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Mirror` is not implemented for `(dyn B + 'static)`
37+
|
38+
= help: the trait `Mirror` is implemented for `dyn A`
39+
40+
error[E0277]: the trait bound `(dyn B + 'static): Mirror` is not satisfied
41+
--> $DIR/projection-dyn-associated-type.rs:19:62
42+
|
43+
LL | pub fn foo<'a>(x: &'a <dyn A + 'static as Mirror>::Assoc) -> &'a <dyn B + 'static as Mirror>::Assoc {
44+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Mirror` is not implemented for `(dyn B + 'static)`
45+
|
46+
= help: the trait `Mirror` is implemented for `dyn A`
47+
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
48+
49+
error: aborting due to 4 previous errors; 1 warning emitted
50+
51+
Some errors have detailed explanations: E0207, E0277.
52+
For more information about an error, try `rustc --explain E0207`.

0 commit comments

Comments
 (0)