Skip to content

Commit cba8b4c

Browse files
committed
add test and update existing tests
1 parent c0bd0c6 commit cba8b4c

15 files changed

+254
-59
lines changed

src/test/ui/feature-gates/feature-gate-type_alias_impl_trait.rs

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ type Foo = impl Debug;
66
//~^ ERROR could not find defining uses
77

88
struct Bar(Foo);
9+
//~^ ERROR type alias impl traits are not allowed as field types in structs
910
fn define() -> Bar {
1011
Bar(42) //~ ERROR mismatched types
1112
}

src/test/ui/feature-gates/feature-gate-type_alias_impl_trait.stderr

+19-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0308]: mismatched types
2-
--> $DIR/feature-gate-type_alias_impl_trait.rs:10:9
2+
--> $DIR/feature-gate-type_alias_impl_trait.rs:11:9
33
|
44
LL | type Foo = impl Debug;
55
| ---------- the expected opaque type
@@ -11,7 +11,7 @@ LL | Bar(42)
1111
found type `{integer}`
1212

1313
error[E0658]: type alias impl trait is not permitted here
14-
--> $DIR/feature-gate-type_alias_impl_trait.rs:16:19
14+
--> $DIR/feature-gate-type_alias_impl_trait.rs:17:19
1515
|
1616
LL | let x = || -> Foo2 { 42 };
1717
| ^^^^
@@ -20,7 +20,7 @@ LL | let x = || -> Foo2 { 42 };
2020
= help: add `#![feature(type_alias_impl_trait)]` to the crate attributes to enable
2121

2222
error[E0308]: mismatched types
23-
--> $DIR/feature-gate-type_alias_impl_trait.rs:23:18
23+
--> $DIR/feature-gate-type_alias_impl_trait.rs:24:18
2424
|
2525
LL | type Foo3 = impl Debug;
2626
| ---------- the found opaque type
@@ -34,7 +34,7 @@ LL | let y: i32 = x;
3434
found opaque type `impl Debug`
3535

3636
error[E0308]: mismatched types
37-
--> $DIR/feature-gate-type_alias_impl_trait.rs:26:13
37+
--> $DIR/feature-gate-type_alias_impl_trait.rs:27:13
3838
|
3939
LL | type Foo3 = impl Debug;
4040
| ---------- the expected opaque type
@@ -46,7 +46,7 @@ LL | define3(42)
4646
found type `{integer}`
4747

4848
error[E0658]: type alias impl trait is not permitted here
49-
--> $DIR/feature-gate-type_alias_impl_trait.rs:33:12
49+
--> $DIR/feature-gate-type_alias_impl_trait.rs:34:12
5050
|
5151
LL | let y: Foo4 = 42;
5252
| ^^^^
@@ -60,19 +60,30 @@ error: could not find defining uses
6060
LL | type Foo = impl Debug;
6161
| ^^^^^^^^^^
6262

63+
error: type alias impl traits are not allowed as field types in structs
64+
--> $DIR/feature-gate-type_alias_impl_trait.rs:8:1
65+
|
66+
LL | type Foo = impl Debug;
67+
| ---------------------- type alias defined here
68+
...
69+
LL | struct Bar(Foo);
70+
| ^^^^^^^^^^^---^^
71+
| |
72+
| this field contains a type alias impl trait
73+
6374
error: could not find defining uses
64-
--> $DIR/feature-gate-type_alias_impl_trait.rs:19:13
75+
--> $DIR/feature-gate-type_alias_impl_trait.rs:20:13
6576
|
6677
LL | type Foo3 = impl Debug;
6778
| ^^^^^^^^^^
6879

6980
error: could not find defining uses
70-
--> $DIR/feature-gate-type_alias_impl_trait.rs:29:13
81+
--> $DIR/feature-gate-type_alias_impl_trait.rs:30:13
7182
|
7283
LL | type Foo4 = impl Debug;
7384
| ^^^^^^^^^^
7485

75-
error: aborting due to 8 previous errors
86+
error: aborting due to 9 previous errors
7687

7788
Some errors have detailed explanations: E0308, E0658.
7889
For more information about an error, try `rustc --explain E0308`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#![feature(min_type_alias_impl_trait)]
2+
3+
type ImplCopy = impl Copy;
4+
//~^ ERROR could not find defining uses
5+
6+
enum Wrapper {
7+
//~^ ERROR type alias impl traits are not allowed as field types in enums
8+
First(ImplCopy),
9+
Second
10+
}
11+
12+
type X = impl Iterator<Item = u64> + Unpin;
13+
//~^ ERROR could not find defining uses
14+
15+
struct Foo(X);
16+
//~^ ERROR type alias impl traits are not allowed as field types in structs
17+
18+
impl Foo {
19+
fn new(z: Vec<u64>) -> Self {
20+
Foo(z.into_iter())
21+
//~^ ERROR mismatched types
22+
}
23+
}
24+
25+
struct Bar {a : X}
26+
//~^ ERROR type alias impl traits are not allowed as field types in structs
27+
28+
impl Bar {
29+
fn new(z: Vec<u64>) -> Self {
30+
Bar {a: z.into_iter() }
31+
//~^ ERROR mismatched types
32+
}
33+
}
34+
35+
union MyUnion {
36+
//~^ ERROR type alias impl traits are not allowed as field types in unions
37+
a: X,
38+
//~^ ERROR unions may not contain fields that need dropping
39+
}
40+
41+
42+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
error[E0308]: mismatched types
2+
--> $DIR/reject-opaque_types-in-fields.rs:20:13
3+
|
4+
LL | type X = impl Iterator<Item = u64> + Unpin;
5+
| --------------------------------- the expected opaque type
6+
...
7+
LL | Foo(z.into_iter())
8+
| ^^^^^^^^^^^^^ expected opaque type, found struct `std::vec::IntoIter`
9+
|
10+
= note: expected opaque type `impl Iterator+Unpin`
11+
found struct `std::vec::IntoIter<u64>`
12+
13+
error[E0308]: mismatched types
14+
--> $DIR/reject-opaque_types-in-fields.rs:30:13
15+
|
16+
LL | type X = impl Iterator<Item = u64> + Unpin;
17+
| --------------------------------- the expected opaque type
18+
...
19+
LL | Bar {a: z.into_iter() }
20+
| ^^^^^^^^^^^^^ expected opaque type, found struct `std::vec::IntoIter`
21+
|
22+
= note: expected opaque type `impl Iterator+Unpin`
23+
found struct `std::vec::IntoIter<u64>`
24+
25+
error: could not find defining uses
26+
--> $DIR/reject-opaque_types-in-fields.rs:3:17
27+
|
28+
LL | type ImplCopy = impl Copy;
29+
| ^^^^^^^^^
30+
31+
error: type alias impl traits are not allowed as field types in enums
32+
--> $DIR/reject-opaque_types-in-fields.rs:6:1
33+
|
34+
LL | type ImplCopy = impl Copy;
35+
| -------------------------- type alias defined here
36+
...
37+
LL | / enum Wrapper {
38+
LL | |
39+
LL | | First(ImplCopy),
40+
| | -------- this field contains a type alias impl trait
41+
LL | | Second
42+
LL | | }
43+
| |_^
44+
45+
error: could not find defining uses
46+
--> $DIR/reject-opaque_types-in-fields.rs:12:10
47+
|
48+
LL | type X = impl Iterator<Item = u64> + Unpin;
49+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
50+
51+
error: type alias impl traits are not allowed as field types in structs
52+
--> $DIR/reject-opaque_types-in-fields.rs:15:1
53+
|
54+
LL | type X = impl Iterator<Item = u64> + Unpin;
55+
| ------------------------------------------- type alias defined here
56+
...
57+
LL | struct Foo(X);
58+
| ^^^^^^^^^^^-^^
59+
| |
60+
| this field contains a type alias impl trait
61+
62+
error: type alias impl traits are not allowed as field types in structs
63+
--> $DIR/reject-opaque_types-in-fields.rs:25:1
64+
|
65+
LL | type X = impl Iterator<Item = u64> + Unpin;
66+
| ------------------------------------------- type alias defined here
67+
...
68+
LL | struct Bar {a : X}
69+
| ^^^^^^^^^^^^-----^
70+
| |
71+
| this field contains a type alias impl trait
72+
73+
error: type alias impl traits are not allowed as field types in unions
74+
--> $DIR/reject-opaque_types-in-fields.rs:35:1
75+
|
76+
LL | type X = impl Iterator<Item = u64> + Unpin;
77+
| ------------------------------------------- type alias defined here
78+
...
79+
LL | / union MyUnion {
80+
LL | |
81+
LL | | a: X,
82+
| | ---- this field contains a type alias impl trait
83+
LL | |
84+
LL | | }
85+
| |_^
86+
87+
error[E0740]: unions may not contain fields that need dropping
88+
--> $DIR/reject-opaque_types-in-fields.rs:37:3
89+
|
90+
LL | a: X,
91+
| ^^^^
92+
|
93+
note: `std::mem::ManuallyDrop` can be used to wrap the type
94+
--> $DIR/reject-opaque_types-in-fields.rs:37:3
95+
|
96+
LL | a: X,
97+
| ^^^^
98+
99+
error: aborting due to 9 previous errors
100+
101+
Some errors have detailed explanations: E0308, E0740.
102+
For more information about an error, try `rustc --explain E0308`.

src/test/ui/lint/lint-ctypes-73249-3.full_tait.stderr

+11-11
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,18 @@ LL | #![cfg_attr(full_tait, feature(type_alias_impl_trait))]
77
= note: `#[warn(incomplete_features)]` on by default
88
= note: see issue #63063 <https://github.com/rust-lang/rust/issues/63063> for more information
99

10-
error: `extern` block uses type `impl Baz`, which is not FFI-safe
11-
--> $DIR/lint-ctypes-73249-3.rs:21:25
10+
error: type alias impl traits are not allowed as field types in structs
11+
--> $DIR/lint-ctypes-73249-3.rs:16:1
1212
|
13-
LL | pub fn lint_me() -> A;
14-
| ^ not FFI-safe
15-
|
16-
note: the lint level is defined here
17-
--> $DIR/lint-ctypes-73249-3.rs:5:9
18-
|
19-
LL | #![deny(improper_ctypes)]
20-
| ^^^^^^^^^^^^^^^
21-
= note: opaque types have no C equivalent
13+
LL | type Qux = impl Baz;
14+
| -------------------- type alias defined here
15+
...
16+
LL | / pub struct A {
17+
LL | |
18+
LL | | x: Qux,
19+
| | ------ this field contains a type alias impl trait
20+
LL | | }
21+
| |_^
2222

2323
error: aborting due to previous error; 1 warning emitted
2424

Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
error: `extern` block uses type `impl Baz`, which is not FFI-safe
2-
--> $DIR/lint-ctypes-73249-3.rs:21:25
1+
error: type alias impl traits are not allowed as field types in structs
2+
--> $DIR/lint-ctypes-73249-3.rs:16:1
33
|
4-
LL | pub fn lint_me() -> A;
5-
| ^ not FFI-safe
6-
|
7-
note: the lint level is defined here
8-
--> $DIR/lint-ctypes-73249-3.rs:5:9
9-
|
10-
LL | #![deny(improper_ctypes)]
11-
| ^^^^^^^^^^^^^^^
12-
= note: opaque types have no C equivalent
4+
LL | type Qux = impl Baz;
5+
| -------------------- type alias defined here
6+
...
7+
LL | / pub struct A {
8+
LL | |
9+
LL | | x: Qux,
10+
| | ------ this field contains a type alias impl trait
11+
LL | | }
12+
| |_^
1313

1414
error: aborting due to previous error
1515

src/test/ui/lint/lint-ctypes-73249-3.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@ fn assign() -> Qux { 3 }
1414

1515
#[repr(C)]
1616
pub struct A {
17+
//~^ ERROR type alias impl traits are not allowed as field types in structs
1718
x: Qux,
1819
}
1920

2021
extern "C" {
21-
pub fn lint_me() -> A; //~ ERROR: uses type `impl Baz`
22+
pub fn lint_me() -> A;
2223
}
2324

2425
fn main() {}

src/test/ui/lint/lint-ctypes-73249-5.full_tait.stderr

+11-11
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,18 @@ LL | #![cfg_attr(full_tait, feature(type_alias_impl_trait))]
77
= note: `#[warn(incomplete_features)]` on by default
88
= note: see issue #63063 <https://github.com/rust-lang/rust/issues/63063> for more information
99

10-
error: `extern` block uses type `impl Baz`, which is not FFI-safe
11-
--> $DIR/lint-ctypes-73249-5.rs:21:25
10+
error: type alias impl traits are not allowed as field types in structs
11+
--> $DIR/lint-ctypes-73249-5.rs:16:1
1212
|
13-
LL | pub fn lint_me() -> A;
14-
| ^ not FFI-safe
15-
|
16-
note: the lint level is defined here
17-
--> $DIR/lint-ctypes-73249-5.rs:5:9
18-
|
19-
LL | #![deny(improper_ctypes)]
20-
| ^^^^^^^^^^^^^^^
21-
= note: opaque types have no C equivalent
13+
LL | type Qux = impl Baz;
14+
| -------------------- type alias defined here
15+
...
16+
LL | / pub struct A {
17+
LL | |
18+
LL | | x: Qux,
19+
| | ------ this field contains a type alias impl trait
20+
LL | | }
21+
| |_^
2222

2323
error: aborting due to previous error; 1 warning emitted
2424

Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
error: `extern` block uses type `impl Baz`, which is not FFI-safe
2-
--> $DIR/lint-ctypes-73249-5.rs:21:25
1+
error: type alias impl traits are not allowed as field types in structs
2+
--> $DIR/lint-ctypes-73249-5.rs:16:1
33
|
4-
LL | pub fn lint_me() -> A;
5-
| ^ not FFI-safe
6-
|
7-
note: the lint level is defined here
8-
--> $DIR/lint-ctypes-73249-5.rs:5:9
9-
|
10-
LL | #![deny(improper_ctypes)]
11-
| ^^^^^^^^^^^^^^^
12-
= note: opaque types have no C equivalent
4+
LL | type Qux = impl Baz;
5+
| -------------------- type alias defined here
6+
...
7+
LL | / pub struct A {
8+
LL | |
9+
LL | | x: Qux,
10+
| | ------ this field contains a type alias impl trait
11+
LL | | }
12+
| |_^
1313

1414
error: aborting due to previous error
1515

src/test/ui/lint/lint-ctypes-73249-5.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@ fn assign() -> Qux { 3 }
1414

1515
#[repr(transparent)]
1616
pub struct A {
17+
//~^ ERROR type alias impl traits are not allowed as field types in structs
1718
x: Qux,
1819
}
1920

2021
extern "C" {
21-
pub fn lint_me() -> A; //~ ERROR: uses type `impl Baz`
22+
pub fn lint_me() -> A;
2223
}
2324

2425
fn main() {}

src/test/ui/type-alias-impl-trait/cross_crate_ice.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
// aux-build:cross_crate_ice.rs
2-
// build-pass (FIXME(62277): could be check-pass?)
32

43
extern crate cross_crate_ice;
54

65
struct Bar(cross_crate_ice::Foo);
6+
//~^ type alias impl traits are not allowed as field types in structs
77

88
impl Bar {
99
fn zero(&self) -> &cross_crate_ice::Foo {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
error: type alias impl traits are not allowed as field types in structs
2+
--> $DIR/cross_crate_ice.rs:5:1
3+
|
4+
LL | struct Bar(cross_crate_ice::Foo);
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
7+
error: aborting due to previous error
8+

0 commit comments

Comments
 (0)