]> git.lizzy.rs Git - rust.git/blob - src/test/ui/typeck/typeck-auto-trait-no-supertraits.rs
Auto merge of #54624 - arielb1:evaluate-outlives, r=nikomatsakis
[rust.git] / src / test / ui / typeck / typeck-auto-trait-no-supertraits.rs
1 // Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 // This test is for #29859, we need to ensure auto traits,
12 // (also known previously as default traits), do not have
13 // supertraits. Since the compiler synthesizes these
14 // instances on demand, we are essentially enabling
15 // users to write axioms if we view trait selection,
16 // as a proof system.
17 //
18 // For example the below test allows us to add the rule:
19 //  forall (T : Type), T : Copy
20 //
21 // Providing a copy instance for *any* type, which
22 // is most definitely unsound. Imagine copying a
23 // type that contains a mutable reference, enabling
24 // mutable aliasing.
25 //
26 // You can imagine an even more dangerous test,
27 // which currently compiles on nightly.
28 //
29 // fn main() {
30 //    let mut i = 10;
31 //    let (a, b) = copy(&mut i);
32 //    println!("{:?} {:?}", a, b);
33 // }
34
35 #![feature(optin_builtin_traits)]
36
37 auto trait Magic: Copy {} //~ ERROR E0568
38 impl<T:Magic> Magic for T {}
39
40 fn copy<T: Magic>(x: T) -> (T, T) { (x, x) }
41
42 #[derive(Debug)]
43 struct NoClone;
44
45 fn main() {
46     let (a, b) = copy(NoClone);
47     println!("{:?} {:?}", a, b);
48 }