]> git.proxmox.com Git - rustc.git/blob - src/test/compile-fail/typeck-auto-trait-no-supertraits.rs
New upstream version 1.23.0+dfsg1
[rustc.git] / src / test / compile-fail / 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 trait Magic: Copy {} //~ ERROR E0568
38 #[allow(auto_impl)]
39 impl Magic for .. {}
40 impl<T:Magic> Magic for T {}
41
42 fn copy<T: Magic>(x: T) -> (T, T) { (x, x) }
43
44 #[derive(Debug)]
45 struct NoClone;
46
47 fn main() {
48 let (a, b) = copy(NoClone);
49 println!("{:?} {:?}", a, b);
50 }