|
| 1 | +// Copyright 2017 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 that the NLL `relate_tys` code correctly deduces that a |
| 12 | +// function returning always its first argument can be upcast to one |
| 13 | +// that returns either first or second argument. |
| 14 | + |
| 15 | +#![feature(nll)] |
| 16 | +#![allow(warnings)] |
| 17 | + |
| 18 | +use std::cell::Cell; |
| 19 | + |
| 20 | +type DoubleCell<A> = Cell<(A, A)>; |
| 21 | +type DoublePair<A> = (A, A); |
| 22 | + |
| 23 | +fn make_cell<'b>(x: &'b u32) -> Cell<(&'static u32, &'b u32)> { |
| 24 | + panic!() |
| 25 | +} |
| 26 | + |
| 27 | +fn main() { |
| 28 | + let a: &'static u32 = &22; |
| 29 | + let b = 44; |
| 30 | + |
| 31 | + // Here we get an error because `DoubleCell<_>` requires the same type |
| 32 | + // on both parts of the `Cell`, and we can't have that. |
| 33 | + let x: DoubleCell<_> = make_cell(&b); //~ ERROR |
| 34 | + |
| 35 | + // Here we do not get an error because `DoublePair<_>` permits |
| 36 | + // variance on the lifetimes involved. |
| 37 | + let y: DoublePair<_> = make_cell(&b).get(); |
| 38 | +} |
0 commit comments