Skip to content

Commit 7e199b1

Browse files
committed
Add ui test: suggest-struct-or-union-add-generic-impl-trait.rs
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
1 parent d7ed32b commit 7e199b1

2 files changed

+81
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
//@ edition:2021
2+
trait Trait {}
3+
4+
struct Foo1 {
5+
a: Trait,
6+
//~^ ERROR expected a type, found a trait
7+
b: u32,
8+
}
9+
10+
struct Foo2 {
11+
a: i32,
12+
b: Trait,
13+
//~^ ERROR expected a type, found a trait
14+
}
15+
16+
17+
enum Enum1 {
18+
A(Trait),
19+
//~^ ERROR expected a type, found a trait
20+
B(u32),
21+
}
22+
23+
enum Enum2 {
24+
A(u32),
25+
B(Trait),
26+
//~^ ERROR expected a type, found a trait
27+
}
28+
29+
30+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
error[E0782]: expected a type, found a trait
2+
--> $DIR/suggest-struct-or-union-add-generic-impl-trait.rs:5:8
3+
|
4+
LL | a: Trait,
5+
| ^^^^^
6+
|
7+
help: you might be missing a type parameter
8+
|
9+
LL ~ struct Foo1<T: Trait> {
10+
LL ~ a: T,
11+
|
12+
13+
error[E0782]: expected a type, found a trait
14+
--> $DIR/suggest-struct-or-union-add-generic-impl-trait.rs:12:8
15+
|
16+
LL | b: Trait,
17+
| ^^^^^
18+
|
19+
help: you can add the `dyn` keyword if you want a trait object
20+
|
21+
LL | b: dyn Trait,
22+
| +++
23+
24+
error[E0782]: expected a type, found a trait
25+
--> $DIR/suggest-struct-or-union-add-generic-impl-trait.rs:18:7
26+
|
27+
LL | A(Trait),
28+
| ^^^^^
29+
|
30+
help: you might be missing a type parameter
31+
|
32+
LL ~ enum Enum1<T: Trait> {
33+
LL ~ A(T),
34+
|
35+
36+
error[E0782]: expected a type, found a trait
37+
--> $DIR/suggest-struct-or-union-add-generic-impl-trait.rs:25:7
38+
|
39+
LL | B(Trait),
40+
| ^^^^^
41+
|
42+
help: you might be missing a type parameter
43+
|
44+
LL ~ enum Enum2<T: Trait> {
45+
LL | A(u32),
46+
LL ~ B(T),
47+
|
48+
49+
error: aborting due to 4 previous errors
50+
51+
For more information about this error, try `rustc --explain E0782`.

0 commit comments

Comments
 (0)