tests: add tests for lifetime and const params of opaque types.
This commit is contained in:
parent
8807b00dd8
commit
ea7999b4f3
@ -1,13 +1,26 @@
|
||||
#![feature(type_alias_impl_trait)]
|
||||
#![feature(type_alias_impl_trait, const_generics)]
|
||||
#![allow(incomplete_features)]
|
||||
|
||||
use std::fmt::Debug;
|
||||
|
||||
fn main() {}
|
||||
|
||||
// test that unused generic parameters are ok
|
||||
type Two<T, U> = impl Debug;
|
||||
type TwoTys<T, U> = impl Debug;
|
||||
type TwoLifetimes<'a, 'b> = impl Debug;
|
||||
type TwoConsts<const X: usize, const Y: usize> = impl Debug;
|
||||
|
||||
fn one<T: Debug>(t: T) -> Two<T, T> {
|
||||
fn one_ty<T: Debug>(t: T) -> TwoTys<T, T> {
|
||||
//~^ ERROR non-defining opaque type use in defining scope
|
||||
t
|
||||
}
|
||||
|
||||
fn one_lifetime<'a>(t: &'a u32) -> TwoLifetimes<'a, 'a> {
|
||||
//~^ ERROR non-defining opaque type use in defining scope
|
||||
t
|
||||
}
|
||||
|
||||
fn one_const<const N: usize>(t: *mut [u8; N]) -> TwoConsts<N, N> {
|
||||
//~^ ERROR non-defining opaque type use in defining scope
|
||||
t
|
||||
}
|
||||
|
@ -1,14 +1,38 @@
|
||||
error: non-defining opaque type use in defining scope
|
||||
--> $DIR/generic_duplicate_param_use.rs:10:27
|
||||
--> $DIR/generic_duplicate_param_use.rs:13:30
|
||||
|
|
||||
LL | fn one<T: Debug>(t: T) -> Two<T, T> {
|
||||
| ^^^^^^^^^
|
||||
LL | fn one_ty<T: Debug>(t: T) -> TwoTys<T, T> {
|
||||
| ^^^^^^^^^^^^
|
||||
|
|
||||
note: type used multiple times
|
||||
--> $DIR/generic_duplicate_param_use.rs:8:10
|
||||
--> $DIR/generic_duplicate_param_use.rs:9:13
|
||||
|
|
||||
LL | type Two<T, U> = impl Debug;
|
||||
| ^ ^
|
||||
LL | type TwoTys<T, U> = impl Debug;
|
||||
| ^ ^
|
||||
|
||||
error: aborting due to previous error
|
||||
error: non-defining opaque type use in defining scope
|
||||
--> $DIR/generic_duplicate_param_use.rs:18:36
|
||||
|
|
||||
LL | fn one_lifetime<'a>(t: &'a u32) -> TwoLifetimes<'a, 'a> {
|
||||
| ^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
note: lifetime used multiple times
|
||||
--> $DIR/generic_duplicate_param_use.rs:10:19
|
||||
|
|
||||
LL | type TwoLifetimes<'a, 'b> = impl Debug;
|
||||
| ^^ ^^
|
||||
|
||||
error: non-defining opaque type use in defining scope
|
||||
--> $DIR/generic_duplicate_param_use.rs:23:50
|
||||
|
|
||||
LL | fn one_const<const N: usize>(t: *mut [u8; N]) -> TwoConsts<N, N> {
|
||||
| ^^^^^^^^^^^^^^^
|
||||
|
|
||||
note: constant used multiple times
|
||||
--> $DIR/generic_duplicate_param_use.rs:11:22
|
||||
|
|
||||
LL | type TwoConsts<const X: usize, const Y: usize> = impl Debug;
|
||||
| ^ ^
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
|
@ -1,12 +1,27 @@
|
||||
#![feature(type_alias_impl_trait)]
|
||||
#![feature(type_alias_impl_trait, const_generics)]
|
||||
#![allow(incomplete_features)]
|
||||
|
||||
use std::fmt::Debug;
|
||||
|
||||
fn main() {}
|
||||
|
||||
type Cmp<T> = impl 'static;
|
||||
//~^ ERROR: at least one trait must be specified
|
||||
type OneTy<T> = impl Debug;
|
||||
type OneLifetime<'a> = impl Debug;
|
||||
type OneConst<const X: usize> = impl Debug;
|
||||
|
||||
// Not defining uses, because they doesn't define *all* possible generics.
|
||||
|
||||
// not a defining use, because it doesn't define *all* possible generics
|
||||
fn cmp() -> Cmp<u32> { //~ ERROR non-defining opaque type use in defining scope
|
||||
fn concrete_ty() -> OneTy<u32> {
|
||||
//~^ ERROR non-defining opaque type use in defining scope
|
||||
5u32
|
||||
}
|
||||
|
||||
fn concrete_lifetime() -> OneLifetime<'static> {
|
||||
//~^ ERROR non-defining opaque type use in defining scope
|
||||
6u32
|
||||
}
|
||||
|
||||
fn concrete_const() -> OneConst<{123}> {
|
||||
//~^ ERROR non-defining opaque type use in defining scope
|
||||
7u32
|
||||
}
|
||||
|
@ -1,20 +1,35 @@
|
||||
error: at least one trait must be specified
|
||||
--> $DIR/generic_nondefining_use.rs:5:15
|
||||
|
|
||||
LL | type Cmp<T> = impl 'static;
|
||||
| ^^^^^^^^^^^^
|
||||
|
||||
error: non-defining opaque type use in defining scope
|
||||
--> $DIR/generic_nondefining_use.rs:10:13
|
||||
--> $DIR/generic_nondefining_use.rs:14:21
|
||||
|
|
||||
LL | fn cmp() -> Cmp<u32> {
|
||||
| ^^^^^^^^
|
||||
LL | fn concrete_ty() -> OneTy<u32> {
|
||||
| ^^^^^^^^^^
|
||||
|
|
||||
note: used non-generic type `u32` for generic parameter
|
||||
--> $DIR/generic_nondefining_use.rs:5:10
|
||||
--> $DIR/generic_nondefining_use.rs:8:12
|
||||
|
|
||||
LL | type Cmp<T> = impl 'static;
|
||||
| ^
|
||||
LL | type OneTy<T> = impl Debug;
|
||||
| ^
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
error: non-defining opaque type use in defining scope
|
||||
--> $DIR/generic_nondefining_use.rs:19:27
|
||||
|
|
||||
LL | type OneLifetime<'a> = impl Debug;
|
||||
| -- cannot use static lifetime; use a bound lifetime instead or remove the lifetime parameter from the opaque type
|
||||
...
|
||||
LL | fn concrete_lifetime() -> OneLifetime<'static> {
|
||||
| ^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: non-defining opaque type use in defining scope
|
||||
--> $DIR/generic_nondefining_use.rs:24:24
|
||||
|
|
||||
LL | fn concrete_const() -> OneConst<{123}> {
|
||||
| ^^^^^^^^^^^^^^^
|
||||
|
|
||||
note: used non-generic constant `123usize` for generic parameter
|
||||
--> $DIR/generic_nondefining_use.rs:10:21
|
||||
|
|
||||
LL | type OneConst<const X: usize> = impl Debug;
|
||||
| ^
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user