summaryrefslogtreecommitdiffstats
path: root/tests/ui/deriving
diff options
context:
space:
mode:
Diffstat (limited to 'tests/ui/deriving')
-rw-r--r--tests/ui/deriving/issue-103157.stderr2
-rw-r--r--tests/ui/deriving/issue-105101.rs9
-rw-r--r--tests/ui/deriving/issue-105101.stderr29
-rw-r--r--tests/ui/deriving/multiple-defaults.rs41
-rw-r--r--tests/ui/deriving/multiple-defaults.stderr62
5 files changed, 104 insertions, 39 deletions
diff --git a/tests/ui/deriving/issue-103157.stderr b/tests/ui/deriving/issue-103157.stderr
index 01cce2a39..384899ea4 100644
--- a/tests/ui/deriving/issue-103157.stderr
+++ b/tests/ui/deriving/issue-103157.stderr
@@ -22,6 +22,6 @@ note: required by a bound in `AssertParamIsEq`
--> $SRC_DIR/core/src/cmp.rs:LL:COL
= note: this error originates in the derive macro `Eq` (in Nightly builds, run with -Z macro-backtrace for more info)
-error: aborting due to previous error
+error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0277`.
diff --git a/tests/ui/deriving/issue-105101.rs b/tests/ui/deriving/issue-105101.rs
deleted file mode 100644
index 1a377feb9..000000000
--- a/tests/ui/deriving/issue-105101.rs
+++ /dev/null
@@ -1,9 +0,0 @@
-// compile-flags: --crate-type=lib
-
-#[derive(Default)] //~ ERROR multiple declared defaults
-enum E {
- #[default]
- A,
- #[default]
- A, //~ ERROR defined multiple times
-}
diff --git a/tests/ui/deriving/issue-105101.stderr b/tests/ui/deriving/issue-105101.stderr
deleted file mode 100644
index 0f6f67043..000000000
--- a/tests/ui/deriving/issue-105101.stderr
+++ /dev/null
@@ -1,29 +0,0 @@
-error: multiple declared defaults
- --> $DIR/issue-105101.rs:3:10
- |
-LL | #[derive(Default)]
- | ^^^^^^^
-...
-LL | A,
- | - first default
-LL | #[default]
-LL | A,
- | - additional default
- |
- = note: only one variant can be default
- = note: this error originates in the derive macro `Default` (in Nightly builds, run with -Z macro-backtrace for more info)
-
-error[E0428]: the name `A` is defined multiple times
- --> $DIR/issue-105101.rs:8:5
- |
-LL | A,
- | - previous definition of the type `A` here
-LL | #[default]
-LL | A,
- | ^ `A` redefined here
- |
- = note: `A` must be defined only once in the type namespace of this enum
-
-error: aborting due to 2 previous errors
-
-For more information about this error, try `rustc --explain E0428`.
diff --git a/tests/ui/deriving/multiple-defaults.rs b/tests/ui/deriving/multiple-defaults.rs
new file mode 100644
index 000000000..2024a5520
--- /dev/null
+++ b/tests/ui/deriving/multiple-defaults.rs
@@ -0,0 +1,41 @@
+// compile-flags: --crate-type=lib
+
+// When we get multiple `#[default]` variants, we emit several tool-only suggestions
+// to remove all except one of the `#[default]`s.
+
+#[derive(Default)] //~ ERROR multiple declared defaults
+enum A {
+ #[default] //~ HELP make `B` default
+ #[default] //~ HELP make `A` default
+ A,
+ #[default] // also "HELP make `A` default", but compiletest can't handle multispans
+ B,
+}
+
+// Originally, we took each defaulted variant and emitted the suggestion for every variant
+// with a different identifier, causing an ICE when multiple variants have the same identifier:
+// https://github.com/rust-lang/rust/pull/105106
+#[derive(Default)] //~ ERROR multiple declared defaults
+enum E {
+ #[default] //~ HELP make `A` default
+ A,
+ #[default] //~ HELP make `A` default
+ A, //~ ERROR defined multiple times
+}
+
+// Then, we took each defaulted variant and emitted the suggestion for every variant
+// with a different span, causing an ICE when multiple variants have the same span:
+// https://github.com/rust-lang/rust/issues/118119
+macro_rules! m {
+ { $($id:ident)* } => {
+ #[derive(Default)] //~ ERROR multiple declared defaults
+ enum F {
+ $(
+ #[default]
+ $id,
+ )*
+ }
+ }
+}
+
+m! { A B }
diff --git a/tests/ui/deriving/multiple-defaults.stderr b/tests/ui/deriving/multiple-defaults.stderr
new file mode 100644
index 000000000..05fb6fecf
--- /dev/null
+++ b/tests/ui/deriving/multiple-defaults.stderr
@@ -0,0 +1,62 @@
+error: multiple declared defaults
+ --> $DIR/multiple-defaults.rs:6:10
+ |
+LL | #[derive(Default)]
+ | ^^^^^^^
+...
+LL | A,
+ | - first default
+LL | #[default] // also "HELP make `A` default", but compiletest can't handle multispans
+LL | B,
+ | - additional default
+ |
+ = note: only one variant can be default
+ = note: this error originates in the derive macro `Default` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: multiple declared defaults
+ --> $DIR/multiple-defaults.rs:18:10
+ |
+LL | #[derive(Default)]
+ | ^^^^^^^
+...
+LL | A,
+ | - first default
+LL | #[default]
+LL | A,
+ | - additional default
+ |
+ = note: only one variant can be default
+ = note: this error originates in the derive macro `Default` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0428]: the name `A` is defined multiple times
+ --> $DIR/multiple-defaults.rs:23:5
+ |
+LL | A,
+ | - previous definition of the type `A` here
+LL | #[default]
+LL | A,
+ | ^ `A` redefined here
+ |
+ = note: `A` must be defined only once in the type namespace of this enum
+
+error: multiple declared defaults
+ --> $DIR/multiple-defaults.rs:31:18
+ |
+LL | #[derive(Default)]
+ | ^^^^^^^
+...
+LL | $id,
+ | ---
+ | |
+ | first default
+ | additional default
+...
+LL | m! { A B }
+ | ---------- in this macro invocation
+ |
+ = note: only one variant can be default
+ = note: this error originates in the derive macro `Default` which comes from the expansion of the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: aborting due to 4 previous errors
+
+For more information about this error, try `rustc --explain E0428`.