about summary refs log tree commit diff
path: root/src/test/ui/const-generics
diff options
context:
space:
mode:
authorkadmin <julianknodt@gmail.com>2022-12-30 05:09:09 +0000
committerkadmin <julianknodt@gmail.com>2023-01-03 23:26:57 +0000
commit077fae94a175408d8d7624af8a9fb96ce71bf3c3 (patch)
tree2a98c4029967cb4212063a957b6d7c382832964d /src/test/ui/const-generics
parent2c7536eaae59b44ff5259183ca98384129d69dd0 (diff)
downloadrust-077fae94a175408d8d7624af8a9fb96ce71bf3c3.tar.gz
rust-077fae94a175408d8d7624af8a9fb96ce71bf3c3.zip
Add note about wrapping in braces
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.
Diffstat (limited to 'src/test/ui/const-generics')
-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`.