Skip to content

Commit 2c35a49

Browse files
committed
Add more tests that exercise the well-formedness checking of lazy type aliases
1 parent a962594 commit 2c35a49

6 files changed

Lines changed: 138 additions & 22 deletions

File tree

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Test that we check the body at the definition site for well-formedness.
2+
3+
#![feature(lazy_type_alias)]
4+
5+
// unsatisified trait bounds
6+
type _A<T> = <T as std::ops::Mul>::Output; //~ ERROR cannot multiply `T` by `T`
7+
type _B = Vec<str>; //~ ERROR the size for values of type `str` cannot be known at compilation time
8+
9+
// unsatisfied outlives-bounds
10+
type _C<'a> = &'static &'a (); //~ ERROR reference has a longer lifetime than the data it references
11+
12+
// diverging const exprs
13+
type _D = [(); panic!()]; //~ ERROR evaluation panicked
14+
15+
// dyn incompatibility
16+
type _E = dyn Sized; //~ ERROR the trait `Sized` is not dyn compatible
17+
18+
fn main() {}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
error[E0277]: cannot multiply `T` by `T`
2+
--> $DIR/def-site-body-wf.rs:6:14
3+
|
4+
LL | type _A<T> = <T as std::ops::Mul>::Output;
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ no implementation for `T * T`
6+
|
7+
help: consider restricting type parameter `T` with trait `Mul`
8+
|
9+
LL | type _A<T: std::ops::Mul> = <T as std::ops::Mul>::Output;
10+
| +++++++++++++++
11+
12+
error[E0277]: the size for values of type `str` cannot be known at compilation time
13+
--> $DIR/def-site-body-wf.rs:7:11
14+
|
15+
LL | type _B = Vec<str>;
16+
| ^^^^^^^^ doesn't have a size known at compile-time
17+
|
18+
= help: the trait `Sized` is not implemented for `str`
19+
note: required by an implicit `Sized` bound in `Vec`
20+
--> $SRC_DIR/alloc/src/vec/mod.rs:LL:COL
21+
22+
error[E0491]: in type `&'static &'a ()`, reference has a longer lifetime than the data it references
23+
--> $DIR/def-site-body-wf.rs:10:1
24+
|
25+
LL | type _C<'a> = &'static &'a ();
26+
| ^^^^^^^^^^^
27+
|
28+
= note: the pointer is valid for the static lifetime
29+
note: but the referenced data is only valid for the lifetime `'a` as defined here
30+
--> $DIR/def-site-body-wf.rs:10:9
31+
|
32+
LL | type _C<'a> = &'static &'a ();
33+
| ^^
34+
35+
error[E0080]: evaluation panicked: explicit panic
36+
--> $DIR/def-site-body-wf.rs:13:16
37+
|
38+
LL | type _D = [(); panic!()];
39+
| ^^^^^^^^ evaluation of `_D::{constant#0}` failed here
40+
41+
error[E0038]: the trait `Sized` is not dyn compatible
42+
--> $DIR/def-site-body-wf.rs:16:11
43+
|
44+
LL | type _E = dyn Sized;
45+
| ^^^^^^^^^ `Sized` is not dyn compatible
46+
|
47+
= note: the trait is not dyn compatible because it requires `Self: Sized`
48+
= note: for a trait to be dyn compatible it needs to allow building a vtable
49+
for more information, visit <https://doc.rust-lang.org/reference/items/traits.html#dyn-compatibility>
50+
51+
error: aborting due to 5 previous errors
52+
53+
Some errors have detailed explanations: E0038, E0080, E0277, E0491.
54+
For more information about an error, try `rustc --explain E0038`.

tests/ui/lazy-type-alias/unsatisfied-bounds-type-alias-body.rs

Lines changed: 0 additions & 8 deletions
This file was deleted.

tests/ui/lazy-type-alias/unsatisfied-bounds-type-alias-body.stderr

Lines changed: 0 additions & 14 deletions
This file was deleted.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Test that we check usage sites of lazy type aliases, aka free alias types, for well-formedness.
2+
// We check trailing where-clauses separately in `trailing-where-clause.rs`.
3+
4+
#![feature(lazy_type_alias)]
5+
6+
type B<T: Copy> = T;
7+
8+
fn b<X>(_: B<X>) {}
9+
//~^ ERROR the trait bound `X: Copy` is not satisfied
10+
//~| ERROR the trait bound `X: Copy` is not satisfied
11+
12+
type A<'a: 'static> = &'a ();
13+
14+
fn a<'r>(_: A<'r>) {} //~ ERROR lifetime bound not satisfied
15+
16+
fn main() {}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
error[E0277]: the trait bound `X: Copy` is not satisfied
2+
--> $DIR/use-site-wf.rs:8:12
3+
|
4+
LL | fn b<X>(_: B<X>) {}
5+
| ^^^^ the trait `Copy` is not implemented for `X`
6+
|
7+
note: required by a bound on the type alias `B`
8+
--> $DIR/use-site-wf.rs:6:11
9+
|
10+
LL | type B<T: Copy> = T;
11+
| ^^^^ required by this bound
12+
help: consider restricting type parameter `X` with trait `Copy`
13+
|
14+
LL | fn b<X: std::marker::Copy>(_: B<X>) {}
15+
| +++++++++++++++++++
16+
17+
error[E0478]: lifetime bound not satisfied
18+
--> $DIR/use-site-wf.rs:14:13
19+
|
20+
LL | fn a<'r>(_: A<'r>) {}
21+
| ^^^^^
22+
|
23+
note: lifetime parameter instantiated with the lifetime `'r` as defined here
24+
--> $DIR/use-site-wf.rs:14:6
25+
|
26+
LL | fn a<'r>(_: A<'r>) {}
27+
| ^^
28+
= note: but lifetime parameter must outlive the static lifetime
29+
30+
error[E0277]: the trait bound `X: Copy` is not satisfied
31+
--> $DIR/use-site-wf.rs:8:12
32+
|
33+
LL | fn b<X>(_: B<X>) {}
34+
| ^^^^ the trait `Copy` is not implemented for `X`
35+
|
36+
note: required by a bound on the type alias `B`
37+
--> $DIR/use-site-wf.rs:6:11
38+
|
39+
LL | type B<T: Copy> = T;
40+
| ^^^^ required by this bound
41+
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
42+
help: consider restricting type parameter `X` with trait `Copy`
43+
|
44+
LL | fn b<X: std::marker::Copy>(_: B<X>) {}
45+
| +++++++++++++++++++
46+
47+
error: aborting due to 3 previous errors
48+
49+
Some errors have detailed explanations: E0277, E0478.
50+
For more information about an error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)