Skip to content

Commit 5af3b88

Browse files
committed
Document the situation with unused_parens lint and braced macro calls
1 parent 55edc08 commit 5af3b88

File tree

1 file changed

+28
-4
lines changed

1 file changed

+28
-4
lines changed

compiler/rustc_lint/src/unused.rs

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -663,6 +663,33 @@ trait UnusedDelimLint {
663663
}
664664

665665
// Check if LHS needs parens to prevent false-positives in cases like `fn x() -> u8 { ({ 0 } + 1) }`.
666+
//
667+
// FIXME: https://github.com/rust-lang/rust/issues/119426
668+
// The syntax tree in this code is from after macro expansion, so the
669+
// current implementation has both false negatives and false positives
670+
// related to expressions containing macros.
671+
//
672+
// macro_rules! m1 {
673+
// () => {
674+
// 1
675+
// };
676+
// }
677+
//
678+
// fn f1() -> u8 {
679+
// // Lint says parens are not needed, but they are.
680+
// (m1! {} + 1)
681+
// }
682+
//
683+
// macro_rules! m2 {
684+
// () => {
685+
// loop { break 1; }
686+
// };
687+
// }
688+
//
689+
// fn f2() -> u8 {
690+
// // Lint says parens are needed, but they are not.
691+
// (m2!() + 1)
692+
// }
666693
{
667694
let mut innermost = inner;
668695
loop {
@@ -674,10 +701,7 @@ trait UnusedDelimLint {
674701
ExprKind::Index(base, _subscript, _) => base,
675702
_ => break,
676703
};
677-
if match innermost.kind {
678-
ExprKind::MacCall(_) => false,
679-
_ => !classify::expr_requires_semi_to_be_stmt(innermost),
680-
} {
704+
if !classify::expr_requires_semi_to_be_stmt(innermost) {
681705
return true;
682706
}
683707
}

0 commit comments

Comments
 (0)