about summary refs log tree commit diff
diff options
context:
space:
mode:
authorxizheyin <xizheyin@smail.nju.edu.cn>2025-03-06 16:23:23 +0800
committerxizheyin <xizheyin@smail.nju.edu.cn>2025-03-06 16:23:23 +0800
commit7e199b10c9efc765024d5bad1f964ddaf6b9a131 (patch)
tree7f78dafb429a10b00dcfcb3db955fd2880234fb8
parentd7ed32b0c079719b611d78bbd16f6dc695d831d4 (diff)
downloadrust-7e199b10c9efc765024d5bad1f964ddaf6b9a131.tar.gz
rust-7e199b10c9efc765024d5bad1f964ddaf6b9a131.zip
Add ui test: suggest-struct-or-union-add-generic-impl-trait.rs
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
-rw-r--r--tests/ui/suggestions/suggest-struct-or-union-add-generic-impl-trait.rs30
-rw-r--r--tests/ui/suggestions/suggest-struct-or-union-add-generic-impl-trait.stderr51
2 files changed, 81 insertions, 0 deletions
diff --git a/tests/ui/suggestions/suggest-struct-or-union-add-generic-impl-trait.rs b/tests/ui/suggestions/suggest-struct-or-union-add-generic-impl-trait.rs
new file mode 100644
index 00000000000..9963b5be4f2
--- /dev/null
+++ b/tests/ui/suggestions/suggest-struct-or-union-add-generic-impl-trait.rs
@@ -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() {}
diff --git a/tests/ui/suggestions/suggest-struct-or-union-add-generic-impl-trait.stderr b/tests/ui/suggestions/suggest-struct-or-union-add-generic-impl-trait.stderr
new file mode 100644
index 00000000000..433196919ca
--- /dev/null
+++ b/tests/ui/suggestions/suggest-struct-or-union-add-generic-impl-trait.stderr
@@ -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`.