]> git.proxmox.com Git - rustc.git/blob - src/test/run-pass/traits/trait-copy-guessing.rs
New upstream version 1.37.0+dfsg1
[rustc.git] / src / test / run-pass / traits / trait-copy-guessing.rs
1 // run-pass
2 #![allow(dead_code)]
3 // "guessing" in trait selection can affect `copy_or_move`. Check that this
4 // is correctly handled. I am not sure what is the "correct" behaviour,
5 // but we should at least not ICE.
6
7 use std::mem;
8
9 struct U([u8; 1337]);
10
11 struct S<'a,T:'a>(&'a T);
12 impl<'a, T> Clone for S<'a, T> { fn clone(&self) -> Self { S(self.0) } }
13 /// This impl triggers inference "guessing" - S<_>: Copy => _ = U
14 impl<'a> Copy for S<'a, Option<U>> {}
15
16 fn assert_impls_fn<R,T: Fn()->R>(_: &T){}
17
18 fn main() {
19 let n = None;
20 let e = S(&n);
21 let f = || {
22 // S being copy is critical for this to work
23 drop(e);
24 mem::size_of_val(e.0)
25 };
26 assert_impls_fn(&f);
27 assert_eq!(f(), 1337+1);
28
29 assert_eq!((|| {
30 // S being Copy is not critical here, but
31 // we check it anyway.
32 let n = None;
33 let e = S(&n);
34 let ret = mem::size_of_val(e.0);
35 drop(e);
36 ret
37 })(), 1337+1);
38 }