about summary refs log tree commit diff
path: root/tests/ui/pattern
diff options
context:
space:
mode:
authorEzra Shaw <ezrasure@outlook.com>2023-01-13 14:14:26 +1300
committerEzra Shaw <ezrasure@outlook.com>2023-01-14 12:51:20 +1300
commit1babece1e8888151b1b248367eb1017450dc107c (patch)
tree9217eb814c5955ebbc5a52eba0a541cc7c7a3056 /tests/ui/pattern
parent61a415be590113b4935464ef0aaf3b4e7713a077 (diff)
downloadrust-1babece1e8888151b1b248367eb1017450dc107c.tar.gz
rust-1babece1e8888151b1b248367eb1017450dc107c.zip
suggest fix for attempted integer identifier in patterns
Diffstat (limited to 'tests/ui/pattern')
-rw-r--r--tests/ui/pattern/issue-106552.rs7
-rw-r--r--tests/ui/pattern/issue-106552.stderr35
2 files changed, 42 insertions, 0 deletions
diff --git a/tests/ui/pattern/issue-106552.rs b/tests/ui/pattern/issue-106552.rs
new file mode 100644
index 00000000000..aa2c141e05e
--- /dev/null
+++ b/tests/ui/pattern/issue-106552.rs
@@ -0,0 +1,7 @@
+fn main() {
+    let 5 = 6;
+    //~^ error refutable pattern in local binding [E0005]
+
+    let x @ 5 = 6;
+    //~^ error refutable pattern in local binding [E0005]
+}
diff --git a/tests/ui/pattern/issue-106552.stderr b/tests/ui/pattern/issue-106552.stderr
new file mode 100644
index 00000000000..ed5d40c0968
--- /dev/null
+++ b/tests/ui/pattern/issue-106552.stderr
@@ -0,0 +1,35 @@
+error[E0005]: refutable pattern in local binding
+  --> $DIR/issue-106552.rs:2:9
+   |
+LL |     let 5 = 6;
+   |         ^ patterns `i32::MIN..=4_i32` and `6_i32..=i32::MAX` not covered
+   |
+   = note: `let` bindings require an "irrefutable pattern", like a `struct` or an `enum` with only one variant
+   = note: for more information, visit https://doc.rust-lang.org/book/ch18-02-refutability.html
+   = note: the matched value is of type `i32`
+help: you might want to use `if let` to ignore the variants that aren't matched
+   |
+LL |     if let 5 = 6 { todo!() }
+   |     ++           ~~~~~~~~~~~
+help: alternatively, you could prepend the pattern with an underscore to define a new named variable; identifiers cannot begin with digits
+   |
+LL |     let _5 = 6;
+   |         +
+
+error[E0005]: refutable pattern in local binding
+  --> $DIR/issue-106552.rs:5:9
+   |
+LL |     let x @ 5 = 6;
+   |         ^^^^^ patterns `i32::MIN..=4_i32` and `6_i32..=i32::MAX` not covered
+   |
+   = note: `let` bindings require an "irrefutable pattern", like a `struct` or an `enum` with only one variant
+   = note: for more information, visit https://doc.rust-lang.org/book/ch18-02-refutability.html
+   = note: the matched value is of type `i32`
+help: you might want to use `let else` to handle the variants that aren't matched
+   |
+LL |     let x @ 5 = 6 else { todo!() };
+   |                   ++++++++++++++++
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0005`.