]>
git.proxmox.com Git - rustc.git/blob - src/test/ui/nll/ty-outlives/projection-one-region-closure.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.
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.
11 // Test cases where we constrain `<T as Anything<'b>>::AssocType` to
12 // outlive `'a` and there are no bounds in the trait definition of
13 // `Anything`. This means that the constraint can only be satisfied in two
16 // - by ensuring that `T: 'a` and `'b: 'a`, or
17 // - by something in the where clauses.
19 // As of this writing, the where clause option does not work because
20 // of limitations in our region inferencing system (this is true both
21 // with and without NLL). See `projection_outlives`.
23 // Ensuring that both `T: 'a` and `'b: 'a` holds does work (`elements_outlive`).
25 // compile-flags:-Zborrowck=mir -Zverbose
28 #![feature(rustc_attrs)]
36 fn with_signature
<'a
, T
, F
>(cell
: Cell
<&'
a ()>, t
: T
, op
: F
)
38 F
: FnOnce(Cell
<&'
a ()>, T
),
43 fn require
<'a
, 'b
, T
>(_cell
: Cell
<&'
a ()>, _t
: T
)
51 fn no_relationships_late
<'a
, 'b
, T
>(cell
: Cell
<&'
a ()>, t
: T
)
55 with_signature(cell
, t
, |cell
, t
| require(cell
, t
));
56 //~^ WARNING not reporting region error due to nll
57 //~| ERROR the parameter type `T` may not live long enough
58 //~| ERROR does not outlive free region
62 fn no_relationships_early
<'a
, 'b
, T
>(cell
: Cell
<&'
a ()>, t
: T
)
67 with_signature(cell
, t
, |cell
, t
| require(cell
, t
));
68 //~^ WARNING not reporting region error due to nll
69 //~| ERROR the parameter type `T` may not live long enough
70 //~| ERROR does not outlive free region
74 fn projection_outlives
<'a
, 'b
, T
>(cell
: Cell
<&'
a ()>, t
: T
)
79 // This error is unfortunate. This code ought to type-check: we
80 // are projecting `<T as Anything<'b>>::AssocType`, and we know
81 // that this outlives `'a` because of the where-clause. However,
82 // the way the region checker works, we don't register this
83 // outlives obligation, and hence we get an error: this is because
84 // what we see is a projection like `<T as
85 // Anything<'?0>>::AssocType`, and we don't yet know if `?0` will
86 // equal `'b` or not, so we ignore the where-clause. Obviously we
87 // can do better here with a more involved verification step.
89 with_signature(cell
, t
, |cell
, t
| require(cell
, t
));
90 //~^ WARNING not reporting region error due to nll
91 //~| ERROR the parameter type `T` may not live long enough
92 //~| ERROR free region `ReEarlyBound(1, 'b)` does not outlive free region `ReEarlyBound(0, 'a)`
96 fn elements_outlive
<'a
, 'b
, T
>(cell
: Cell
<&'
a ()>, t
: T
)
102 with_signature(cell
, t
, |cell
, t
| require(cell
, t
));