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 `'static`. In this case, we don't get any errors, and in fact
13 // we don't even propagate constraints from the closures to the callers.
15 // compile-flags:-Zborrowck=mir -Zverbose
19 #![feature(dyn_trait)]
20 #![feature(rustc_attrs)]
25 type AssocType: 'static;
28 fn with_signature<'a, T, F>(cell: Cell<&'a ()>, t: T, op: F)
30 F: FnOnce(Cell<&'a ()>, T),
35 fn require<'a, 'b, T>(_cell: Cell<&'a ()>, _t: T)
43 fn no_relationships_late<'a, 'b, T>(cell: Cell<&'a ()>, t: T)
47 with_signature(cell, t, |cell, t| require(cell, t));
51 fn no_relationships_early<'a, 'b, T>(cell: Cell<&'a ()>, t: T)
56 with_signature(cell, t, |cell, t| require(cell, t));
60 fn projection_outlives<'a, 'b, T>(cell: Cell<&'a ()>, t: T)
65 // This error is unfortunate. This code ought to type-check: we
66 // are projecting `<T as Anything<'b>>::AssocType`, and we know
67 // that this outlives `'a` because of the where-clause. However,
68 // the way the region checker works, we don't register this
69 // outlives obligation, and hence we get an error: this is because
70 // what we see is a projection like `<T as
71 // Anything<'?0>>::AssocType`, and we don't yet know if `?0` will
72 // equal `'b` or not, so we ignore the where-clause. Obviously we
73 // can do better here with a more involved verification step.
75 with_signature(cell, t, |cell, t| require(cell, t));
79 fn elements_outlive<'a, 'b, T>(cell: Cell<&'a ()>, t: T)
84 with_signature(cell, t, |cell, t| require(cell, t));
88 fn one_region<'a, T>(cell: Cell<&'a ()>, t: T)
92 // Note that in this case the closure still propagates an external
93 // requirement between two variables in its signature, but the
94 // creator maps both those two region variables to `'a` on its
96 with_signature(cell, t, |cell, t| require(cell, t));