Skip to content

Commit b1e856a

Browse files
Rollup merge of #77663 - HeroicKatora:regression-tests-27675-object-safe, r=Aaron1011
Add compile fail test for issue 27675 A recently merged PR (#73905) strengthened the checks on bounds of associated items. This rejects the attack path of #27675 which consisted of constructing a `dyn Trait<Item=T>` where `T` would not fulfill the bounds required on `Item` of the `Trait` behind the dyn object. This regression test, extracted from [the weaponized instance](#27675 (comment)), checks that this is rejected.
2 parents 7edb7e7 + ea206f2 commit b1e856a

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/// The compiler previously did not properly check the bound of `From` when it was used from type
2+
/// of the dyn trait object (use in `copy_any` below). Since the associated type is under user
3+
/// control in this usage, the compiler could be tricked to believe any type implemented any trait.
4+
/// This would ICE, except for pure marker traits like `Copy`. It did not require providing an
5+
/// instance of the dyn trait type, only name said type.
6+
trait Setup {
7+
type From: Copy;
8+
}
9+
10+
fn copy<U: Setup + ?Sized>(from: &U::From) -> U::From {
11+
*from
12+
}
13+
14+
pub fn copy_any<T>(t: &T) -> T {
15+
copy::<dyn Setup<From=T>>(t)
16+
//~^ ERROR the trait bound `T: Copy` is not satisfied
17+
}
18+
19+
fn main() {}

0 commit comments

Comments
 (0)