]> git.lizzy.rs Git - rust.git/blob - tests/ui/nll/relate_tys/var-appears-twice.rs
Auto merge of #101138 - Rejyr:diagnostic-migration-rustc-lint-pt2, r=davidtwco
[rust.git] / tests / 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 use std::cell::Cell;
6
7 type DoubleCell<A> = Cell<(A, A)>;
8 type DoublePair<A> = (A, A);
9
10 fn make_cell<'b>(x: &'b u32) -> Cell<(&'static u32, &'b u32)> {
11     panic!()
12 }
13
14 fn main() {
15     let a: &'static u32 = &22;
16     let b = 44;
17
18     // Here we get an error because `DoubleCell<_>` requires the same type
19     // on both parts of the `Cell`, and we can't have that.
20     let x: DoubleCell<_> = make_cell(&b); //~ ERROR
21
22     // Here we do not get an error because `DoublePair<_>` permits
23     // variance on the lifetimes involved.
24     let y: DoublePair<_> = make_cell(&b).get();
25 }