]>
git.proxmox.com Git - rustc.git/blob - src/test/ui/nll/ty-outlives/projection-two-region-trait-bound-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<'a, 'b>>::AssocType`
12 // to outlive `'a` and there are two bounds in the trait definition of
13 // `Anything` -- i.e., we know that `AssocType` outlives `'a` and
14 // `'b`. In this case, it's not clear what is the best way to satisfy
15 // the trait bound, and hence we propagate it to the caller as a type
18 // compile-flags:-Zborrowck=mir -Zverbose
21 #![feature(rustc_attrs)]
25 trait Anything
<'a
, 'b
> {
26 type AssocType
: 'a
+ 'b
;
29 fn with_signature
<'a
, T
, F
>(cell
: Cell
<&'
a ()>, t
: T
, op
: F
)
31 F
: FnOnce(Cell
<&'
a ()>, T
),
36 fn require
<'a
, 'b
, 'c
, T
>(_cell
: Cell
<&'
a ()>, _t
: T
)
44 fn no_relationships_late
<'a
, 'b
, 'c
, T
>(cell
: Cell
<&'
a ()>, t
: T
)
48 with_signature(cell
, t
, |cell
, t
| require(cell
, t
));
49 //~^ WARNING not reporting region error due to nll
50 //~| ERROR associated type `<T as Anything<'_#5r, '_#6r>>::AssocType` may not live long enough
54 fn no_relationships_early
<'a
, 'b
, 'c
, T
>(cell
: Cell
<&'
a ()>, t
: T
)
59 with_signature(cell
, t
, |cell
, t
| require(cell
, t
));
60 //~^ WARNING not reporting region error due to nll
61 //~| ERROR associated type `<T as Anything<'_#6r, '_#7r>>::AssocType` may not live long enough
65 fn projection_outlives
<'a
, 'b
, 'c
, T
>(cell
: Cell
<&'
a ()>, t
: T
)
70 // This error is unfortunate. This code ought to type-check: we
71 // are projecting `<T as Anything<'b>>::AssocType`, and we know
72 // that this outlives `'a` because of the where-clause. However,
73 // the way the region checker works, we don't register this
74 // outlives obligation, and hence we get an error: this is because
75 // what we see is a projection like `<T as
76 // Anything<'?0>>::AssocType`, and we don't yet know if `?0` will
77 // equal `'b` or not, so we ignore the where-clause. Obviously we
78 // can do better here with a more involved verification step.
80 with_signature(cell
, t
, |cell
, t
| require(cell
, t
));
81 //~^ WARNING not reporting region error due to nll
82 //~| ERROR associated type `<T as Anything<'_#6r, '_#7r>>::AssocType` may not live long enough
86 fn elements_outlive1
<'a
, 'b
, 'c
, T
>(cell
: Cell
<&'
a ()>, t
: T
)
91 with_signature(cell
, t
, |cell
, t
| require(cell
, t
));
95 fn elements_outlive2
<'a
, 'b
, 'c
, T
>(cell
: Cell
<&'
a ()>, t
: T
)
100 with_signature(cell
, t
, |cell
, t
| require(cell
, t
));
104 fn two_regions
<'a
, 'b
, T
>(cell
: Cell
<&'
a ()>, t
: T
)
108 with_signature(cell
, t
, |cell
, t
| require(cell
, t
));
109 //~^ WARNING not reporting region error due to nll
110 //~| ERROR does not outlive free region
114 fn two_regions_outlive
<'a
, 'b
, T
>(cell
: Cell
<&'
a ()>, t
: T
)
119 with_signature(cell
, t
, |cell
, t
| require(cell
, t
));
123 fn one_region
<'a
, T
>(cell
: Cell
<&'
a ()>, t
: T
)
127 // Note that in this case the closure still propagates an external
128 // requirement between two variables in its signature, but the
129 // creator maps both those two region variables to `'a` on its
131 with_signature(cell
, t
, |cell
, t
| require(cell
, t
));