diff --git a/compiler/rustc_lint/src/unused.rs b/compiler/rustc_lint/src/unused.rs index a7836ea8e7a..13b3ef43a59 100644 --- a/compiler/rustc_lint/src/unused.rs +++ b/compiler/rustc_lint/src/unused.rs @@ -617,7 +617,10 @@ fn is_expr_delims_necessary( lhs_needs_parens || (followed_by_block && match &inner.kind { - ExprKind::Ret(_) | ExprKind::Break(..) | ExprKind::Yield(..) => true, + ExprKind::Ret(_) + | ExprKind::Break(..) + | ExprKind::Yield(..) + | ExprKind::Yeet(..) => true, ExprKind::Range(_lhs, Some(rhs), _limits) => { matches!(rhs.kind, ExprKind::Block(..)) } 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 index 0b3fe9371f7..71ebaea8ed2 100644 --- a/src/test/ui/lint/unused/issue-54538-unused-parens-lint.fixed +++ b/src/test/ui/lint/unused/issue-54538-unused-parens-lint.fixed @@ -1,6 +1,6 @@ // run-rustfix -#![feature(box_patterns, stmt_expr_attributes)] +#![feature(box_patterns, stmt_expr_attributes, yeet_expr)] #![allow( dead_code, @@ -25,6 +25,13 @@ fn _no_lint_attr() { let _x = #[allow(dead_code)] (1 + 2); } +fn _no_lint_yeet() -> Result<(), ()> { + #[allow(unreachable_code)] + if (do yeet) {} + + Ok(()) +} + // Don't lint in these cases (#64106). fn or_patterns_no_lint() { match Box::new(0) { diff --git a/src/test/ui/lint/unused/issue-54538-unused-parens-lint.rs b/src/test/ui/lint/unused/issue-54538-unused-parens-lint.rs index 1e78ec5f7d9..28b662dd024 100644 --- a/src/test/ui/lint/unused/issue-54538-unused-parens-lint.rs +++ b/src/test/ui/lint/unused/issue-54538-unused-parens-lint.rs @@ -1,6 +1,6 @@ // run-rustfix -#![feature(box_patterns, stmt_expr_attributes)] +#![feature(box_patterns, stmt_expr_attributes, yeet_expr)] #![allow( dead_code, @@ -25,6 +25,13 @@ fn _no_lint_attr() { let _x = #[allow(dead_code)] (1 + 2); } +fn _no_lint_yeet() -> Result<(), ()> { + #[allow(unreachable_code)] + if (do yeet) {} + + Ok(()) +} + // Don't lint in these cases (#64106). fn or_patterns_no_lint() { match Box::new(0) { diff --git a/src/test/ui/lint/unused/issue-54538-unused-parens-lint.stderr b/src/test/ui/lint/unused/issue-54538-unused-parens-lint.stderr index c73884663c8..a5e69e6d938 100644 --- a/src/test/ui/lint/unused/issue-54538-unused-parens-lint.stderr +++ b/src/test/ui/lint/unused/issue-54538-unused-parens-lint.stderr @@ -76,7 +76,7 @@ LL + let _ = |a: u8| 0; | error: unnecessary parentheses around pattern - --> $DIR/issue-54538-unused-parens-lint.rs:49:12 + --> $DIR/issue-54538-unused-parens-lint.rs:56:12 | LL | if let (0 | 1) = 0 {} | ^ ^ @@ -88,7 +88,7 @@ LL + if let 0 | 1 = 0 {} | error: unnecessary parentheses around pattern - --> $DIR/issue-54538-unused-parens-lint.rs:50:13 + --> $DIR/issue-54538-unused-parens-lint.rs:57:13 | LL | if let ((0 | 1),) = (0,) {} | ^ ^ @@ -100,7 +100,7 @@ LL + if let (0 | 1,) = (0,) {} | error: unnecessary parentheses around pattern - --> $DIR/issue-54538-unused-parens-lint.rs:51:13 + --> $DIR/issue-54538-unused-parens-lint.rs:58:13 | LL | if let [(0 | 1)] = [0] {} | ^ ^ @@ -112,7 +112,7 @@ LL + if let [0 | 1] = [0] {} | error: unnecessary parentheses around pattern - --> $DIR/issue-54538-unused-parens-lint.rs:52:16 + --> $DIR/issue-54538-unused-parens-lint.rs:59:16 | LL | if let 0 | (1 | 2) = 0 {} | ^ ^ @@ -124,7 +124,7 @@ LL + if let 0 | 1 | 2 = 0 {} | error: unnecessary parentheses around pattern - --> $DIR/issue-54538-unused-parens-lint.rs:54:15 + --> $DIR/issue-54538-unused-parens-lint.rs:61:15 | LL | if let TS((0 | 1)) = TS(0) {} | ^ ^ @@ -136,7 +136,7 @@ LL + if let TS(0 | 1) = TS(0) {} | error: unnecessary parentheses around pattern - --> $DIR/issue-54538-unused-parens-lint.rs:56:20 + --> $DIR/issue-54538-unused-parens-lint.rs:63:20 | LL | if let NS { f: (0 | 1) } = (NS { f: 0 }) {} | ^ ^ @@ -148,7 +148,7 @@ LL + if let NS { f: 0 | 1 } = (NS { f: 0 }) {} | error: unnecessary parentheses around pattern - --> $DIR/issue-54538-unused-parens-lint.rs:66:9 + --> $DIR/issue-54538-unused-parens-lint.rs:73:9 | LL | (_) => {} | ^ ^ @@ -160,7 +160,7 @@ LL + _ => {} | error: unnecessary parentheses around pattern - --> $DIR/issue-54538-unused-parens-lint.rs:67:9 + --> $DIR/issue-54538-unused-parens-lint.rs:74:9 | LL | (y) => {} | ^ ^ @@ -172,7 +172,7 @@ LL + y => {} | error: unnecessary parentheses around pattern - --> $DIR/issue-54538-unused-parens-lint.rs:68:9 + --> $DIR/issue-54538-unused-parens-lint.rs:75:9 | LL | (ref r) => {} | ^ ^ @@ -184,7 +184,7 @@ LL + ref r => {} | error: unnecessary parentheses around pattern - --> $DIR/issue-54538-unused-parens-lint.rs:69:9 + --> $DIR/issue-54538-unused-parens-lint.rs:76:9 | LL | (e @ 1...2) => {} | ^ ^ @@ -196,7 +196,7 @@ LL + e @ 1...2 => {} | error: unnecessary parentheses around pattern - --> $DIR/issue-54538-unused-parens-lint.rs:75:9 + --> $DIR/issue-54538-unused-parens-lint.rs:82:9 | LL | (e @ &(1...2)) => {} | ^ ^ @@ -208,7 +208,7 @@ LL + e @ &(1...2) => {} | error: unnecessary parentheses around pattern - --> $DIR/issue-54538-unused-parens-lint.rs:76:10 + --> $DIR/issue-54538-unused-parens-lint.rs:83:10 | LL | &(_) => {} | ^ ^ @@ -220,7 +220,7 @@ LL + &_ => {} | error: unnecessary parentheses around pattern - --> $DIR/issue-54538-unused-parens-lint.rs:87:9 + --> $DIR/issue-54538-unused-parens-lint.rs:94:9 | LL | (_) => {} | ^ ^ @@ -232,7 +232,7 @@ LL + _ => {} | error: unnecessary parentheses around pattern - --> $DIR/issue-54538-unused-parens-lint.rs:88:9 + --> $DIR/issue-54538-unused-parens-lint.rs:95:9 | LL | (y) => {} | ^ ^ @@ -244,7 +244,7 @@ LL + y => {} | error: unnecessary parentheses around pattern - --> $DIR/issue-54538-unused-parens-lint.rs:89:9 + --> $DIR/issue-54538-unused-parens-lint.rs:96:9 | LL | (ref r) => {} | ^ ^ @@ -256,7 +256,7 @@ LL + ref r => {} | error: unnecessary parentheses around pattern - --> $DIR/issue-54538-unused-parens-lint.rs:90:9 + --> $DIR/issue-54538-unused-parens-lint.rs:97:9 | LL | (e @ 1..=2) => {} | ^ ^ @@ -268,7 +268,7 @@ LL + e @ 1..=2 => {} | error: unnecessary parentheses around pattern - --> $DIR/issue-54538-unused-parens-lint.rs:96:9 + --> $DIR/issue-54538-unused-parens-lint.rs:103:9 | LL | (e @ &(1..=2)) => {} | ^ ^ @@ -280,7 +280,7 @@ LL + e @ &(1..=2) => {} | error: unnecessary parentheses around pattern - --> $DIR/issue-54538-unused-parens-lint.rs:97:10 + --> $DIR/issue-54538-unused-parens-lint.rs:104:10 | LL | &(_) => {} | ^ ^