about summary refs log tree commit diff
path: root/src/test
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2023-01-07 10:04:39 +0000
committerbors <bors@rust-lang.org>2023-01-07 10:04:39 +0000
commitd72b7d2d2a64f5f77b919a1428873b4d4149f60d (patch)
treeca570384bdb2bdea5ad9465e3d3b31fad97cf644 /src/test
parent472651aa104dea3e358da78c2548ab035cfaf434 (diff)
parent077fae94a175408d8d7624af8a9fb96ce71bf3c3 (diff)
downloadrust-d72b7d2d2a64f5f77b919a1428873b4d4149f60d.tar.gz
rust-d72b7d2d2a64f5f77b919a1428873b4d4149f60d.zip
Auto merge of #106283 - JulianKnodt:enum_err, r=cjgillot
Add help diag. for `const = Enum` missing braces around `Enum`

Previously it was not clear why this errored or if it was even supported, as there was no diagnostic that suggested wrapping it in braces.

Thus, add a simple diagnostic that suggests wrapping enum variants in braces.

Fixes #105927
Diffstat (limited to 'src/test')
-rw-r--r--src/test/ui/const-generics/assoc_const_eq_diagnostic.rs18
-rw-r--r--src/test/ui/const-generics/assoc_const_eq_diagnostic.stderr33
2 files changed, 51 insertions, 0 deletions
diff --git a/src/test/ui/const-generics/assoc_const_eq_diagnostic.rs b/src/test/ui/const-generics/assoc_const_eq_diagnostic.rs
new file mode 100644
index 00000000000..4d0aaf88e40
--- /dev/null
+++ b/src/test/ui/const-generics/assoc_const_eq_diagnostic.rs
@@ -0,0 +1,18 @@
+#![feature(associated_const_equality)]
+
+pub enum Mode {
+    Cool,
+}
+
+pub trait Parse {
+    const MODE: Mode;
+}
+
+pub trait CoolStuff: Parse<MODE = Mode::Cool> {}
+//~^ ERROR expected associated constant bound
+//~| ERROR expected type
+
+fn no_help() -> Mode::Cool {}
+//~^ ERROR expected type, found variant
+
+fn main() {}
diff --git a/src/test/ui/const-generics/assoc_const_eq_diagnostic.stderr b/src/test/ui/const-generics/assoc_const_eq_diagnostic.stderr
new file mode 100644
index 00000000000..ba727ee0ea3
--- /dev/null
+++ b/src/test/ui/const-generics/assoc_const_eq_diagnostic.stderr
@@ -0,0 +1,33 @@
+error[E0573]: expected type, found variant `Mode::Cool`
+  --> $DIR/assoc_const_eq_diagnostic.rs:11:35
+   |
+LL | pub trait CoolStuff: Parse<MODE = Mode::Cool> {}
+   |                                   ^^^^^^^^^^
+   |                                   |
+   |                                   not a type
+   |                                   help: try using the variant's enum: `Mode`
+
+error[E0573]: expected type, found variant `Mode::Cool`
+  --> $DIR/assoc_const_eq_diagnostic.rs:15:17
+   |
+LL | fn no_help() -> Mode::Cool {}
+   |                 ^^^^^^^^^^
+   |                 |
+   |                 not a type
+   |                 help: try using the variant's enum: `Mode`
+
+error: expected associated constant bound, found type
+  --> $DIR/assoc_const_eq_diagnostic.rs:11:28
+   |
+LL | pub trait CoolStuff: Parse<MODE = Mode::Cool> {}
+   |                            ^^^^^^^^^^^^^^^^^ help: if equating a const, try wrapping with braces: `MODE = { const }`
+   |
+note: associated constant defined here
+  --> $DIR/assoc_const_eq_diagnostic.rs:8:5
+   |
+LL |     const MODE: Mode;
+   |     ^^^^^^^^^^^^^^^^
+
+error: aborting due to 3 previous errors
+
+For more information about this error, try `rustc --explain E0573`.