Skip to content

Commit 20b20b2

Browse files
committed
add known-bug tests
1 parent 13471d3 commit 20b20b2

8 files changed

+137
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// chek-fail
2+
// known-bug: #108639
3+
4+
trait Trait {
5+
type Item<'a>: 'a;
6+
}
7+
8+
fn assert_static<T: 'static>(_: T) {}
9+
fn relate<T>(_: T, _: T) {}
10+
11+
fn test_args<I: Trait>() {
12+
let closure = |a, b| {
13+
relate(&a, b);
14+
assert_static(a);
15+
};
16+
closure(None::<I::Item<'_>>, &None::<I::Item<'_>>);
17+
}
18+
19+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
error[E0310]: the associated type `<I as Trait>::Item<'_>` may not live long enough
2+
--> $DIR/type-test-subject-non-trivial-region.rs:14:9
3+
|
4+
LL | assert_static(a);
5+
| ^^^^^^^^^^^^^^^^
6+
|
7+
= help: consider adding an explicit lifetime bound `<I as Trait>::Item<'_>: 'static`...
8+
= note: ...so that the type `<I as Trait>::Item<'_>` will meet its required lifetime bounds
9+
10+
error: aborting due to previous error
11+
12+
For more information about this error, try `rustc --explain E0310`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// check-fail
2+
// known-bug: #107426
3+
4+
use std::marker::PhantomData;
5+
#[derive(Clone, Copy)]
6+
pub struct Scope<'a>(&'a PhantomData<&'a mut &'a ()>);
7+
fn event<'a, F: FnMut() + 'a>(_: Scope<'a>, _: F) {}
8+
fn make_fn<'a>(_: Scope<'a>) -> impl Fn() + Copy + 'a {
9+
|| {}
10+
}
11+
12+
fn foo(cx: Scope) {
13+
let open_toggle = make_fn(cx);
14+
15+
|| event(cx, open_toggle);
16+
}
17+
18+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
error: `make_fn::{opaque#0}<'_>` does not live long enough
2+
--> $DIR/type-test-subject-opaque-1.rs:15:8
3+
|
4+
LL | || event(cx, open_toggle);
5+
| ^^^^^^^^^^^^^^^^^^^^^^
6+
7+
error: aborting due to previous error
8+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// check-fail
2+
// known-bug: #107516
3+
4+
fn iter1<'a: 'a>() -> impl Iterator<Item = &'static str> {
5+
None.into_iter()
6+
}
7+
8+
fn iter2<'a>() -> impl Iterator<Item = &'a str> {
9+
None.into_iter()
10+
}
11+
12+
struct Bivar<'a, I: Iterator<Item = &'a str> + 'a>(I);
13+
14+
fn main() {
15+
let _ = || Bivar(iter1());
16+
let _ = || Bivar(iter2());
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
error[E0310]: the opaque type `iter1<'_>::{opaque#0}` may not live long enough
2+
--> $DIR/type-test-subject-opaque-2.rs:15:16
3+
|
4+
LL | let _ = || Bivar(iter1());
5+
| ^^^^^^^^^^^^^^
6+
|
7+
= help: consider adding an explicit lifetime bound `iter1<'_>::{opaque#0}: 'static`...
8+
= note: ...so that the type `impl Iterator<Item = &'static str>` will meet its required lifetime bounds
9+
10+
error: `iter2<'_>::{opaque#0}<'_>` does not live long enough
11+
--> $DIR/type-test-subject-opaque-2.rs:16:16
12+
|
13+
LL | let _ = || Bivar(iter2());
14+
| ^^^^^^^^^^^^^^
15+
16+
error: aborting due to 2 previous errors
17+
18+
For more information about this error, try `rustc --explain E0310`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// check-fail
2+
// known-bug: #108635
3+
4+
trait Trait {
5+
type Item<'a>: 'a;
6+
}
7+
8+
fn assert_static<T: 'static>(_: T) {}
9+
10+
fn test_args<I: Trait>() {
11+
let closure = |a, _b| assert_static(a);
12+
13+
closure(None::<I::Item<'_>>, &None::<I::Item<'_>>);
14+
}
15+
16+
fn test_upvars<I: Trait>() {
17+
let upvars = (None::<I::Item<'_>>, &None::<I::Item<'_>>);
18+
let _closure = || {
19+
let (a, _b) = upvars;
20+
assert_static(a);
21+
};
22+
}
23+
24+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
error[E0310]: the associated type `<I as Trait>::Item<'_>` may not live long enough
2+
--> $DIR/type-test-subject-unnamed-region.rs:11:27
3+
|
4+
LL | let closure = |a, _b| assert_static(a);
5+
| ^^^^^^^^^^^^^^^^
6+
|
7+
= help: consider adding an explicit lifetime bound `<I as Trait>::Item<'_>: 'static`...
8+
= note: ...so that the type `<I as Trait>::Item<'_>` will meet its required lifetime bounds
9+
10+
error[E0310]: the associated type `<I as Trait>::Item<'_>` may not live long enough
11+
--> $DIR/type-test-subject-unnamed-region.rs:20:9
12+
|
13+
LL | assert_static(a);
14+
| ^^^^^^^^^^^^^^^^
15+
|
16+
= help: consider adding an explicit lifetime bound `<I as Trait>::Item<'_>: 'static`...
17+
= note: ...so that the type `<I as Trait>::Item<'_>` will meet its required lifetime bounds
18+
19+
error: aborting due to 2 previous errors
20+
21+
For more information about this error, try `rustc --explain E0310`.

0 commit comments

Comments
 (0)