-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: add tests for lifetime and const params of opaque types.
- Loading branch information
Showing
4 changed files
with
94 additions
and
27 deletions.
There are no files selected for viewing
19 changes: 16 additions & 3 deletions
19
src/test/ui/type-alias-impl-trait/generic_duplicate_param_use.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
38 changes: 31 additions & 7 deletions
38
src/test/ui/type-alias-impl-trait/generic_duplicate_param_use.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
|
25 changes: 20 additions & 5 deletions
25
src/test/ui/type-alias-impl-trait/generic_nondefining_use.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
39 changes: 27 additions & 12 deletions
39
src/test/ui/type-alias-impl-trait/generic_nondefining_use.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,35 @@ | ||
error: at least one trait must be specified | ||
--> $DIR/generic_nondefining_use.rs:5:15 | ||
error: non-defining opaque type use in defining scope | ||
--> $DIR/generic_nondefining_use.rs:14:21 | ||
| | ||
LL | fn concrete_ty() -> OneTy<u32> { | ||
| ^^^^^^^^^^ | ||
| | ||
note: used non-generic type `u32` for generic parameter | ||
--> $DIR/generic_nondefining_use.rs:8:12 | ||
| | ||
LL | type Cmp<T> = impl 'static; | ||
| ^^^^^^^^^^^^ | ||
LL | type OneTy<T> = impl Debug; | ||
| ^ | ||
|
||
error: non-defining opaque type use in defining scope | ||
--> $DIR/generic_nondefining_use.rs:10:13 | ||
--> $DIR/generic_nondefining_use.rs:19:27 | ||
| | ||
LL | fn cmp() -> Cmp<u32> { | ||
| ^^^^^^^^ | ||
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 | ||
| | ||
note: used non-generic type `u32` for generic parameter | ||
--> $DIR/generic_nondefining_use.rs:5:10 | ||
LL | fn concrete_const() -> OneConst<{123}> { | ||
| ^^^^^^^^^^^^^^^ | ||
| | ||
note: used non-generic constant `123usize` for generic parameter | ||
--> $DIR/generic_nondefining_use.rs:10:21 | ||
| | ||
LL | type Cmp<T> = impl 'static; | ||
| ^ | ||
LL | type OneConst<const X: usize> = impl Debug; | ||
| ^ | ||
|
||
error: aborting due to 2 previous errors | ||
error: aborting due to 3 previous errors | ||
|