]> git.lizzy.rs Git - rust.git/blob - tests/ui/auto-traits/typeck-auto-trait-no-supertraits.rs
Auto merge of #105603 - oli-obk:non_repeatable_queries, r=petrochenkov
[rust.git] / tests / ui / auto-traits / typeck-auto-trait-no-supertraits.rs
1 // This test is for #29859, we need to ensure auto traits,
2 // (also known previously as default traits), do not have
3 // supertraits. Since the compiler synthesizes these
4 // instances on demand, we are essentially enabling
5 // users to write axioms if we view trait selection,
6 // as a proof system.
7 //
8 // For example the below test allows us to add the rule:
9 //  forall (T : Type), T : Copy
10 //
11 // Providing a copy instance for *any* type, which
12 // is most definitely unsound. Imagine copying a
13 // type that contains a mutable reference, enabling
14 // mutable aliasing.
15 //
16 // You can imagine an even more dangerous test,
17 // which currently compiles on nightly.
18 //
19 // fn main() {
20 //    let mut i = 10;
21 //    let (a, b) = copy(&mut i);
22 //    println!("{:?} {:?}", a, b);
23 // }
24
25 #![feature(auto_traits)]
26 #![feature(negative_impls)]
27
28 auto trait Magic: Copy {} //~ ERROR E0568
29 impl<T:Magic> Magic for T {}
30
31 fn copy<T: Magic>(x: T) -> (T, T) { (x, x) }
32
33 #[derive(Debug)]
34 struct NoClone;
35
36 fn main() {
37     let (a, b) = copy(NoClone);
38     println!("{:?} {:?}", a, b);
39 }