Skip to content

Commit 31478cd

Browse files
committed
Add more tests
1 parent 29f87ad commit 31478cd

File tree

6 files changed

+138
-0
lines changed

6 files changed

+138
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#![feature(type_alias_impl_trait)]
2+
3+
fn id(s: &str) -> &str {
4+
s
5+
}
6+
7+
type Opaque<'a> = impl Sized + 'a;
8+
9+
fn test(s: &str) -> (impl Fn(&str) -> Opaque<'_>, impl Fn(&str) -> Opaque<'_>) {
10+
(id, id) //~ ERROR expected generic lifetime parameter, found `'_`
11+
}
12+
13+
fn id2<'a, 'b>(s: (&'a str, &'b str)) -> (&'a str, &'b str) {
14+
s
15+
}
16+
17+
type Opaque2<'a> = impl Sized + 'a;
18+
19+
fn test2() -> impl for<'a, 'b> Fn((&'a str, &'b str)) -> (Opaque2<'a>, Opaque2<'b>) {
20+
id2 //~ ERROR expected generic lifetime parameter, found `'a`
21+
}
22+
23+
type Opaque3<'a> = impl Sized + 'a;
24+
25+
fn test3(s: &str) -> (impl Fn(&str) -> Opaque3<'_>, Opaque3<'_>) {
26+
(id, s) //~ ERROR expected generic lifetime parameter, found `'_`
27+
}
28+
29+
type Opaque4<'a> = impl Sized + 'a;
30+
fn test4(s: &str) -> (Opaque4<'_>, impl Fn(&str) -> Opaque4<'_>) {
31+
(s, id) //~ ERROR expected generic lifetime parameter, found `'_`
32+
}
33+
34+
type Inner<'a> = impl Sized;
35+
fn outer_impl() -> impl for<'a> Fn(&'a ()) -> Inner<'a> {
36+
|x| x //~ ERROR expected generic lifetime parameter, found `'a`
37+
}
38+
39+
fn main() {}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
error[E0792]: expected generic lifetime parameter, found `'_`
2+
--> $DIR/hkl_forbidden.rs:10:5
3+
|
4+
LL | type Opaque<'a> = impl Sized + 'a;
5+
| -- this generic parameter must be used with a generic lifetime parameter
6+
...
7+
LL | (id, id)
8+
| ^^^^^^^^
9+
10+
error[E0792]: expected generic lifetime parameter, found `'a`
11+
--> $DIR/hkl_forbidden.rs:20:5
12+
|
13+
LL | type Opaque2<'a> = impl Sized + 'a;
14+
| -- this generic parameter must be used with a generic lifetime parameter
15+
...
16+
LL | id2
17+
| ^^^
18+
19+
error[E0792]: expected generic lifetime parameter, found `'_`
20+
--> $DIR/hkl_forbidden.rs:26:5
21+
|
22+
LL | type Opaque3<'a> = impl Sized + 'a;
23+
| -- this generic parameter must be used with a generic lifetime parameter
24+
...
25+
LL | (id, s)
26+
| ^^^^^^^
27+
28+
error[E0792]: expected generic lifetime parameter, found `'_`
29+
--> $DIR/hkl_forbidden.rs:31:5
30+
|
31+
LL | type Opaque4<'a> = impl Sized + 'a;
32+
| -- this generic parameter must be used with a generic lifetime parameter
33+
LL | fn test4(s: &str) -> (Opaque4<'_>, impl Fn(&str) -> Opaque4<'_>) {
34+
LL | (s, id)
35+
| ^^^^^^^
36+
37+
error[E0792]: expected generic lifetime parameter, found `'a`
38+
--> $DIR/hkl_forbidden.rs:36:5
39+
|
40+
LL | type Inner<'a> = impl Sized;
41+
| -- this generic parameter must be used with a generic lifetime parameter
42+
LL | fn outer_impl() -> impl for<'a> Fn(&'a ()) -> Inner<'a> {
43+
LL | |x| x
44+
| ^^^^^
45+
46+
error: aborting due to 5 previous errors
47+
48+
For more information about this error, try `rustc --explain E0792`.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#![feature(type_alias_impl_trait)]
2+
//~^ ERROR: expected generic lifetime parameter, found `'a`
3+
4+
type Opaque<'a> = impl Sized + 'a;
5+
6+
trait Trait<'a> {
7+
type Assoc;
8+
}
9+
10+
impl<'a> Trait<'a> for () {
11+
type Assoc = ();
12+
}
13+
14+
fn test() -> &'static dyn for<'a> Trait<'a, Assoc = Opaque<'a>> {
15+
&()
16+
}
17+
18+
fn main() {}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
error[E0792]: expected generic lifetime parameter, found `'a`
2+
3+
error: aborting due to 1 previous error
4+
5+
For more information about this error, try `rustc --explain E0792`.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#![feature(type_alias_impl_trait)]
2+
3+
type Opaque<'a> = impl Sized + 'a;
4+
5+
fn foo<'a>(x: &'a ()) -> &'a () {
6+
x
7+
}
8+
9+
fn test() -> for<'a> fn(&'a ()) -> Opaque<'a> {
10+
foo //~ ERROR: mismatched types
11+
}
12+
13+
fn main() {}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
error[E0308]: mismatched types
2+
--> $DIR/hkl_forbidden3.rs:10:5
3+
|
4+
LL | type Opaque<'a> = impl Sized + 'a;
5+
| --------------- the expected opaque type
6+
...
7+
LL | foo
8+
| ^^^ one type is more general than the other
9+
|
10+
= note: expected fn pointer `for<'a> fn(&'a ()) -> Opaque<'a>`
11+
found fn pointer `for<'a> fn(&'a ()) -> &'a ()`
12+
13+
error: aborting due to 1 previous error
14+
15+
For more information about this error, try `rustc --explain E0308`.

0 commit comments

Comments
 (0)