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