Skip to content

Commit cfe4bb7

Browse files
committed
Document the situation with unused_parens lint and braced macro calls
1 parent 377d35b commit cfe4bb7

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
@@ -675,6 +675,33 @@ trait UnusedDelimLint {
675675
}
676676

677677
// Check if LHS needs parens to prevent false-positives in cases like `fn x() -> u8 { ({ 0 } + 1) }`.
678+
//
679+
// FIXME: https://github.com/rust-lang/rust/issues/119426
680+
// The syntax tree in this code is from after macro expansion, so the
681+
// current implementation has both false negatives and false positives
682+
// related to expressions containing macros.
683+
//
684+
// macro_rules! m1 {
685+
// () => {
686+
// 1
687+
// };
688+
// }
689+
//
690+
// fn f1() -> u8 {
691+
// // Lint says parens are not needed, but they are.
692+
// (m1! {} + 1)
693+
// }
694+
//
695+
// macro_rules! m2 {
696+
// () => {
697+
// loop { break 1; }
698+
// };
699+
// }
700+
//
701+
// fn f2() -> u8 {
702+
// // Lint says parens are needed, but they are not.
703+
// (m2!() + 1)
704+
// }
678705
{
679706
let mut innermost = inner;
680707
loop {
@@ -686,10 +713,7 @@ trait UnusedDelimLint {
686713
ExprKind::Index(base, _subscript, _) => base,
687714
_ => break,
688715
};
689-
if match innermost.kind {
690-
ExprKind::MacCall(_) => false,
691-
_ => !classify::expr_requires_semi_to_be_stmt(innermost),
692-
} {
716+
if !classify::expr_requires_semi_to_be_stmt(innermost) {
693717
return true;
694718
}
695719
}

0 commit comments

Comments
 (0)