summaryrefslogtreecommitdiffstats
path: root/src/test/ui/lint/unused/issue-54538-unused-parens-lint.fixed
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
commit698f8c2f01ea549d77d7dc3338a12e04c11057b9 (patch)
tree173a775858bd501c378080a10dca74132f05bc50 /src/test/ui/lint/unused/issue-54538-unused-parens-lint.fixed
parentInitial commit. (diff)
downloadrustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.tar.xz
rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.zip
Adding upstream version 1.64.0+dfsg1.upstream/1.64.0+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/test/ui/lint/unused/issue-54538-unused-parens-lint.fixed')
-rw-r--r--src/test/ui/lint/unused/issue-54538-unused-parens-lint.fixed106
1 files changed, 106 insertions, 0 deletions
diff --git a/src/test/ui/lint/unused/issue-54538-unused-parens-lint.fixed b/src/test/ui/lint/unused/issue-54538-unused-parens-lint.fixed
new file mode 100644
index 000000000..0b3fe9371
--- /dev/null
+++ b/src/test/ui/lint/unused/issue-54538-unused-parens-lint.fixed
@@ -0,0 +1,106 @@
+// run-rustfix
+
+#![feature(box_patterns, stmt_expr_attributes)]
+
+#![allow(
+ dead_code,
+ ellipsis_inclusive_range_patterns,
+ irrefutable_let_patterns,
+ unreachable_patterns,
+ unused_mut,
+ unused_variables
+)]
+#![deny(unused_parens)]
+
+fn lint_on_top_level() {
+ let a = 0; //~ ERROR unnecessary parentheses around pattern
+ for a in 0..1 {} //~ ERROR unnecessary parentheses around pattern
+ if let a = 0 {} //~ ERROR unnecessary parentheses around pattern
+ while let a = 0 {} //~ ERROR unnecessary parentheses around pattern
+ fn foo(a: u8) {} //~ ERROR unnecessary parentheses around pattern
+ let _ = |a: u8| 0; //~ ERROR unnecessary parentheses around pattern
+}
+
+fn _no_lint_attr() {
+ let _x = #[allow(dead_code)] (1 + 2);
+}
+
+// Don't lint in these cases (#64106).
+fn or_patterns_no_lint() {
+ match Box::new(0) {
+ box (0 | 1) => {} // Should not lint as `box 0 | 1` binds as `(box 0) | 1`.
+ _ => {}
+ }
+
+ match 0 {
+ x @ (0 | 1) => {} // Should not lint as `x @ 0 | 1` binds as `(x @ 0) | 1`.
+ _ => {}
+ }
+
+ if let &(0 | 1) = &0 {} // Should also not lint.
+ if let &mut (0 | 1) = &mut 0 {} // Same.
+
+ fn foo((Ok(a) | Err(a)): Result<u8, u8>) {} // Doesn't parse if we remove parens for now.
+
+ let _ = |(Ok(a) | Err(a)): Result<u8, u8>| 1; // `|Ok(a) | Err(a)| 1` parses as bit-or.
+}
+
+fn or_patterns_will_lint() {
+ if let 0 | 1 = 0 {} //~ ERROR unnecessary parentheses around pattern
+ if let (0 | 1,) = (0,) {} //~ ERROR unnecessary parentheses around pattern
+ if let [0 | 1] = [0] {} //~ ERROR unnecessary parentheses around pattern
+ if let 0 | 1 | 2 = 0 {} //~ ERROR unnecessary parentheses around pattern
+ struct TS(u8);
+ if let TS(0 | 1) = TS(0) {} //~ ERROR unnecessary parentheses around pattern
+ struct NS { f: u8 }
+ if let NS { f: 0 | 1 } = (NS { f: 0 }) {} //~ ERROR unnecessary parentheses around pattern
+}
+
+// Don't lint on `&(mut x)` because `&mut x` means something else (#55342).
+fn deref_mut_binding_no_lint() {
+ let &(mut x) = &0;
+}
+
+fn main() {
+ match 1 {
+ _ => {} //~ ERROR unnecessary parentheses around pattern
+ y => {} //~ ERROR unnecessary parentheses around pattern
+ ref r => {} //~ ERROR unnecessary parentheses around pattern
+ e @ 1...2 => {} //~ ERROR unnecessary parentheses around pattern
+ (1...2) => {} // Non ambiguous range pattern should not warn
+ e @ (3...4) => {} // Non ambiguous range pattern should not warn
+ }
+
+ match &1 {
+ e @ &(1...2) => {} //~ ERROR unnecessary parentheses around pattern
+ &_ => {} //~ ERROR unnecessary parentheses around pattern
+ e @ &(1...2) => {} // Ambiguous range pattern should not warn
+ &(1...2) => {} // Ambiguous range pattern should not warn
+ }
+
+ match &1 {
+ e @ &(1...2) | e @ &(3...4) => {} // Complex ambiguous pattern should not warn
+ &_ => {}
+ }
+
+ match 1 {
+ _ => {} //~ ERROR unnecessary parentheses around pattern
+ y => {} //~ ERROR unnecessary parentheses around pattern
+ ref r => {} //~ ERROR unnecessary parentheses around pattern
+ e @ 1..=2 => {} //~ ERROR unnecessary parentheses around pattern
+ (1..=2) => {} // Non ambiguous range pattern should not warn
+ e @ (3..=4) => {} // Non ambiguous range pattern should not warn
+ }
+
+ match &1 {
+ e @ &(1..=2) => {} //~ ERROR unnecessary parentheses around pattern
+ &_ => {} //~ ERROR unnecessary parentheses around pattern
+ e @ &(1..=2) => {} // Ambiguous range pattern should not warn
+ &(1..=2) => {} // Ambiguous range pattern should not warn
+ }
+
+ match &1 {
+ e @ &(1..=2) | e @ &(3..=4) => {} // Complex ambiguous pattern should not warn
+ &_ => {}
+ }
+}