1
Fork 0

Add ui test: suggest-struct-or-union-add-generic-impl-trait.rs

Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
This commit is contained in:
xizheyin 2025-03-06 16:23:23 +08:00
parent d7ed32b0c0
commit 7e199b10c9
No known key found for this signature in database
GPG key ID: 0A0D90BE99CEDEAD
2 changed files with 81 additions and 0 deletions

View file

@ -0,0 +1,30 @@
//@ edition:2021
trait Trait {}
struct Foo1 {
a: Trait,
//~^ ERROR expected a type, found a trait
b: u32,
}
struct Foo2 {
a: i32,
b: Trait,
//~^ ERROR expected a type, found a trait
}
enum Enum1 {
A(Trait),
//~^ ERROR expected a type, found a trait
B(u32),
}
enum Enum2 {
A(u32),
B(Trait),
//~^ ERROR expected a type, found a trait
}
fn main() {}

View file

@ -0,0 +1,51 @@
error[E0782]: expected a type, found a trait
--> $DIR/suggest-struct-or-union-add-generic-impl-trait.rs:5:8
|
LL | a: Trait,
| ^^^^^
|
help: you might be missing a type parameter
|
LL ~ struct Foo1<T: Trait> {
LL ~ a: T,
|
error[E0782]: expected a type, found a trait
--> $DIR/suggest-struct-or-union-add-generic-impl-trait.rs:12:8
|
LL | b: Trait,
| ^^^^^
|
help: you can add the `dyn` keyword if you want a trait object
|
LL | b: dyn Trait,
| +++
error[E0782]: expected a type, found a trait
--> $DIR/suggest-struct-or-union-add-generic-impl-trait.rs:18:7
|
LL | A(Trait),
| ^^^^^
|
help: you might be missing a type parameter
|
LL ~ enum Enum1<T: Trait> {
LL ~ A(T),
|
error[E0782]: expected a type, found a trait
--> $DIR/suggest-struct-or-union-add-generic-impl-trait.rs:25:7
|
LL | B(Trait),
| ^^^^^
|
help: you might be missing a type parameter
|
LL ~ enum Enum2<T: Trait> {
LL | A(u32),
LL ~ B(T),
|
error: aborting due to 4 previous errors
For more information about this error, try `rustc --explain E0782`.