Skip to content

Commit ea7999b

Browse files
committed
tests: add tests for lifetime and const params of opaque types.
1 parent 8807b00 commit ea7999b

File tree

4 files changed

+94
-27
lines changed

4 files changed

+94
-27
lines changed
Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,26 @@
1-
#![feature(type_alias_impl_trait)]
1+
#![feature(type_alias_impl_trait, const_generics)]
2+
#![allow(incomplete_features)]
23

34
use std::fmt::Debug;
45

56
fn main() {}
67

78
// test that unused generic parameters are ok
8-
type Two<T, U> = impl Debug;
9+
type TwoTys<T, U> = impl Debug;
10+
type TwoLifetimes<'a, 'b> = impl Debug;
11+
type TwoConsts<const X: usize, const Y: usize> = impl Debug;
912

10-
fn one<T: Debug>(t: T) -> Two<T, T> {
13+
fn one_ty<T: Debug>(t: T) -> TwoTys<T, T> {
14+
//~^ ERROR non-defining opaque type use in defining scope
15+
t
16+
}
17+
18+
fn one_lifetime<'a>(t: &'a u32) -> TwoLifetimes<'a, 'a> {
19+
//~^ ERROR non-defining opaque type use in defining scope
20+
t
21+
}
22+
23+
fn one_const<const N: usize>(t: *mut [u8; N]) -> TwoConsts<N, N> {
1124
//~^ ERROR non-defining opaque type use in defining scope
1225
t
1326
}
Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,38 @@
11
error: non-defining opaque type use in defining scope
2-
--> $DIR/generic_duplicate_param_use.rs:10:27
2+
--> $DIR/generic_duplicate_param_use.rs:13:30
33
|
4-
LL | fn one<T: Debug>(t: T) -> Two<T, T> {
5-
| ^^^^^^^^^
4+
LL | fn one_ty<T: Debug>(t: T) -> TwoTys<T, T> {
5+
| ^^^^^^^^^^^^
66
|
77
note: type used multiple times
8-
--> $DIR/generic_duplicate_param_use.rs:8:10
8+
--> $DIR/generic_duplicate_param_use.rs:9:13
99
|
10-
LL | type Two<T, U> = impl Debug;
11-
| ^ ^
10+
LL | type TwoTys<T, U> = impl Debug;
11+
| ^ ^
1212

13-
error: aborting due to previous error
13+
error: non-defining opaque type use in defining scope
14+
--> $DIR/generic_duplicate_param_use.rs:18:36
15+
|
16+
LL | fn one_lifetime<'a>(t: &'a u32) -> TwoLifetimes<'a, 'a> {
17+
| ^^^^^^^^^^^^^^^^^^^^
18+
|
19+
note: lifetime used multiple times
20+
--> $DIR/generic_duplicate_param_use.rs:10:19
21+
|
22+
LL | type TwoLifetimes<'a, 'b> = impl Debug;
23+
| ^^ ^^
24+
25+
error: non-defining opaque type use in defining scope
26+
--> $DIR/generic_duplicate_param_use.rs:23:50
27+
|
28+
LL | fn one_const<const N: usize>(t: *mut [u8; N]) -> TwoConsts<N, N> {
29+
| ^^^^^^^^^^^^^^^
30+
|
31+
note: constant used multiple times
32+
--> $DIR/generic_duplicate_param_use.rs:11:22
33+
|
34+
LL | type TwoConsts<const X: usize, const Y: usize> = impl Debug;
35+
| ^ ^
36+
37+
error: aborting due to 3 previous errors
1438

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,27 @@
1-
#![feature(type_alias_impl_trait)]
1+
#![feature(type_alias_impl_trait, const_generics)]
2+
#![allow(incomplete_features)]
3+
4+
use std::fmt::Debug;
25

36
fn main() {}
47

5-
type Cmp<T> = impl 'static;
6-
//~^ ERROR: at least one trait must be specified
8+
type OneTy<T> = impl Debug;
9+
type OneLifetime<'a> = impl Debug;
10+
type OneConst<const X: usize> = impl Debug;
711

12+
// Not defining uses, because they doesn't define *all* possible generics.
813

9-
// not a defining use, because it doesn't define *all* possible generics
10-
fn cmp() -> Cmp<u32> { //~ ERROR non-defining opaque type use in defining scope
14+
fn concrete_ty() -> OneTy<u32> {
15+
//~^ ERROR non-defining opaque type use in defining scope
1116
5u32
1217
}
18+
19+
fn concrete_lifetime() -> OneLifetime<'static> {
20+
//~^ ERROR non-defining opaque type use in defining scope
21+
6u32
22+
}
23+
24+
fn concrete_const() -> OneConst<{123}> {
25+
//~^ ERROR non-defining opaque type use in defining scope
26+
7u32
27+
}
Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,35 @@
1-
error: at least one trait must be specified
2-
--> $DIR/generic_nondefining_use.rs:5:15
1+
error: non-defining opaque type use in defining scope
2+
--> $DIR/generic_nondefining_use.rs:14:21
3+
|
4+
LL | fn concrete_ty() -> OneTy<u32> {
5+
| ^^^^^^^^^^
6+
|
7+
note: used non-generic type `u32` for generic parameter
8+
--> $DIR/generic_nondefining_use.rs:8:12
39
|
4-
LL | type Cmp<T> = impl 'static;
5-
| ^^^^^^^^^^^^
10+
LL | type OneTy<T> = impl Debug;
11+
| ^
612

713
error: non-defining opaque type use in defining scope
8-
--> $DIR/generic_nondefining_use.rs:10:13
14+
--> $DIR/generic_nondefining_use.rs:19:27
915
|
10-
LL | fn cmp() -> Cmp<u32> {
11-
| ^^^^^^^^
16+
LL | type OneLifetime<'a> = impl Debug;
17+
| -- cannot use static lifetime; use a bound lifetime instead or remove the lifetime parameter from the opaque type
18+
...
19+
LL | fn concrete_lifetime() -> OneLifetime<'static> {
20+
| ^^^^^^^^^^^^^^^^^^^^
21+
22+
error: non-defining opaque type use in defining scope
23+
--> $DIR/generic_nondefining_use.rs:24:24
1224
|
13-
note: used non-generic type `u32` for generic parameter
14-
--> $DIR/generic_nondefining_use.rs:5:10
25+
LL | fn concrete_const() -> OneConst<{123}> {
26+
| ^^^^^^^^^^^^^^^
27+
|
28+
note: used non-generic constant `123usize` for generic parameter
29+
--> $DIR/generic_nondefining_use.rs:10:21
1530
|
16-
LL | type Cmp<T> = impl 'static;
17-
| ^
31+
LL | type OneConst<const X: usize> = impl Debug;
32+
| ^
1833

19-
error: aborting due to 2 previous errors
34+
error: aborting due to 3 previous errors
2035

0 commit comments

Comments
 (0)