]> git.lizzy.rs Git - rust.git/blob - tests/ui/type-alias-impl-trait/issue-84660-unsoundness.rs
Auto merge of #106916 - lukas-code:overlapping-substs, r=estebank
[rust.git] / tests / ui / type-alias-impl-trait / issue-84660-unsoundness.rs
1 // Another example from issue #84660, this time weaponized as a safe transmute: an opaque type in an
2 // impl header being accepted was used to create unsoundness.
3
4 #![feature(type_alias_impl_trait)]
5
6 trait Foo {}
7 impl Foo for () {}
8 type Bar = impl Foo;
9 fn _defining_use() -> Bar {}
10
11 trait Trait<T, In> {
12     type Out;
13     fn convert(i: In) -> Self::Out;
14 }
15
16 impl<In, Out> Trait<Bar, In> for Out {
17     type Out = Out;
18     fn convert(_i: In) -> Self::Out {
19         unreachable!();
20     }
21 }
22
23 impl<In, Out> Trait<(), In> for Out { //~ ERROR conflicting implementations of trait `Trait<Bar, _>`
24     type Out = In;
25     fn convert(i: In) -> Self::Out {
26         i
27     }
28 }
29
30 fn transmute<In, Out>(i: In) -> Out {
31     <Out as Trait<Bar, In>>::convert(i)
32 }
33
34 fn main() {
35     let d;
36     {
37         let x = "Hello World".to_string();
38         d = transmute::<&String, &String>(&x);
39     }
40     println!("{}", d);
41 }