]> git.lizzy.rs Git - rust.git/blob - src/test/ui/nll/relate_tys/var-appears-twice.rs
2f227c872598ffb47f261105226c9e3f09252ed4
[rust.git] / src / test / ui / nll / relate_tys / var-appears-twice.rs
1 // Test that the NLL `relate_tys` code correctly deduces that a
2 // function returning always its first argument can be upcast to one
3 // that returns either first or second argument.
4
5 #![feature(nll)]
6 #![allow(warnings)]
7
8 use std::cell::Cell;
9
10 type DoubleCell<A> = Cell<(A, A)>;
11 type DoublePair<A> = (A, A);
12
13 fn make_cell<'b>(x: &'b u32) -> Cell<(&'static u32, &'b u32)> {
14     panic!()
15 }
16
17 fn main() {
18     let a: &'static u32 = &22;
19     let b = 44;
20
21     // Here we get an error because `DoubleCell<_>` requires the same type
22     // on both parts of the `Cell`, and we can't have that.
23     let x: DoubleCell<_> = make_cell(&b); //~ ERROR
24
25     // Here we do not get an error because `DoublePair<_>` permits
26     // variance on the lifetimes involved.
27     let y: DoublePair<_> = make_cell(&b).get();
28 }