forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimpl-trait-lifetimes.rs
60 lines (50 loc) · 1.06 KB
/
impl-trait-lifetimes.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
trait Foo<T> {
fn foo(&self, _: T) { }
}
trait FooBar<'a> {
type Item;
}
mod foo {
fn fun(t: impl crate::Foo<&u32>, n: u32) {
t.foo(&n);
//~^ ERROR `n` does not live long enough
}
}
mod fun {
fn fun(t: impl Fn(&u32), n: u32) {
t(&n);
}
}
mod iterator_fun {
fn fun(t: impl Iterator<Item = impl Fn(&u32)>, n: u32) {
for elem in t {
elem(&n);
}
}
}
mod iterator_foo {
fn fun(t: impl Iterator<Item = impl crate::Foo<&u32>>, n: u32) {
for elem in t {
elem.foo(&n);
//~^ ERROR `n` does not live long enough
}
}
}
mod placeholder {
trait Placeholder<'a> {
fn foo(&self, _: &'a u32) {}
}
fn fun(t: impl Placeholder<'_>, n: u32) {
t.foo(&n);
//~^ ERROR `n` does not live long enough
}
}
mod stabilized {
trait InTrait {
fn in_trait(&self) -> impl Iterator<Item = &u32>;
}
fn foo1(_: impl Iterator<Item = &u32>) {}
fn foo2<'b>(_: impl crate::FooBar<'b, Item = &u32>) {}
}
fn main() {
}