Skip to content

Commit c6c18a0

Browse files
committed
Document the situation with unused_parens lint and braced macro calls
1 parent 0ca322c commit c6c18a0

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
@@ -677,6 +677,33 @@ trait UnusedDelimLint {
677677
}
678678

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

0 commit comments

Comments
 (0)