]> git.proxmox.com Git - rustc.git/blob - src/test/ui/nll/ty-outlives/projection-implied-bounds.rs
New upstream version 1.63.0+dfsg1
[rustc.git] / src / test / ui / nll / ty-outlives / projection-implied-bounds.rs
1 // Test that we can deduce when projections like `T::Item` outlive the
2 // function body. Test that this does not imply that `T: 'a` holds.
3
4 // compile-flags:-Zverbose
5
6 use std::cell::Cell;
7
8 fn twice<F, T>(mut value: T, mut f: F)
9 where
10 F: FnMut(&T, Cell<&Option<T::Item>>),
11 T: Iterator,
12 {
13 let mut n = value.next();
14 f(&value, Cell::new(&n));
15 f(&value, Cell::new(&n));
16 }
17
18 fn generic1<T: Iterator>(value: T) {
19 // No error here:
20 twice(value, |value_ref, item| invoke1(item));
21 }
22
23 fn invoke1<'a, T>(x: Cell<&'a Option<T>>)
24 where
25 T: 'a,
26 {
27 }
28
29 fn generic2<T: Iterator>(value: T) {
30 twice(value, |value_ref, item| invoke2(value_ref, item));
31 //~^ ERROR the parameter type `T` may not live long enough
32 }
33
34 fn invoke2<'a, T, U>(a: &T, b: Cell<&'a Option<U>>)
35 where
36 T: 'a,
37 {
38 }
39
40 fn main() {}