]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/type-infer-generalize-ty-var.rs
Auto merge of #41282 - arielb1:missing-impl-item, r=petrochenkov
[rust.git] / src / test / run-pass / type-infer-generalize-ty-var.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 // Test a scenario where we generate a constraint like `?1 <: &?2`.
12 // In such a case, it is important that we instantiate `?1` with `&?3`
13 // where `?3 <: ?2`, and not with `&?2`. This is a regression test for
14 // #18653. The important thing is that we build.
15
16 use std::cell::RefCell;
17
18 enum Wrap<A> {
19     WrapSome(A),
20     WrapNone
21 }
22
23 use Wrap::*;
24
25 struct T;
26 struct U;
27
28 trait Get<T: ?Sized> {
29     fn get(&self) -> &T;
30 }
31
32 impl Get<MyShow + 'static> for Wrap<T> {
33     fn get(&self) -> &(MyShow + 'static) {
34         static x: usize = 42;
35         &x
36     }
37 }
38
39 impl Get<usize> for Wrap<U> {
40     fn get(&self) -> &usize {
41         static x: usize = 55;
42         &x
43     }
44 }
45
46 trait MyShow { fn dummy(&self) { } }
47 impl<'a> MyShow for &'a (MyShow + 'a) { }
48 impl MyShow for usize { }
49 fn constrain<'a>(rc: RefCell<&'a (MyShow + 'a)>) { }
50
51 fn main() {
52     let mut collection: Wrap<_> = WrapNone;
53
54     {
55         let __arg0 = Get::get(&collection);
56         let __args_cell = RefCell::new(__arg0);
57         constrain(__args_cell);
58     }
59     collection = WrapSome(T);
60 }