Document the situation with unused_parens lint and braced macro calls
This commit is contained in:
parent
0ca322c774
commit
c6c18a0151
1 changed files with 28 additions and 4 deletions
|
@ -677,6 +677,33 @@ trait UnusedDelimLint {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if LHS needs parens to prevent false-positives in cases like `fn x() -> u8 { ({ 0 } + 1) }`.
|
// Check if LHS needs parens to prevent false-positives in cases like `fn x() -> u8 { ({ 0 } + 1) }`.
|
||||||
|
//
|
||||||
|
// FIXME: https://github.com/rust-lang/rust/issues/119426
|
||||||
|
// The syntax tree in this code is from after macro expansion, so the
|
||||||
|
// current implementation has both false negatives and false positives
|
||||||
|
// related to expressions containing macros.
|
||||||
|
//
|
||||||
|
// macro_rules! m1 {
|
||||||
|
// () => {
|
||||||
|
// 1
|
||||||
|
// };
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// fn f1() -> u8 {
|
||||||
|
// // Lint says parens are not needed, but they are.
|
||||||
|
// (m1! {} + 1)
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// macro_rules! m2 {
|
||||||
|
// () => {
|
||||||
|
// loop { break 1; }
|
||||||
|
// };
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// fn f2() -> u8 {
|
||||||
|
// // Lint says parens are needed, but they are not.
|
||||||
|
// (m2!() + 1)
|
||||||
|
// }
|
||||||
{
|
{
|
||||||
let mut innermost = inner;
|
let mut innermost = inner;
|
||||||
loop {
|
loop {
|
||||||
|
@ -688,10 +715,7 @@ trait UnusedDelimLint {
|
||||||
ExprKind::Index(base, _subscript, _) => base,
|
ExprKind::Index(base, _subscript, _) => base,
|
||||||
_ => break,
|
_ => break,
|
||||||
};
|
};
|
||||||
if match innermost.kind {
|
if !classify::expr_requires_semi_to_be_stmt(innermost) {
|
||||||
ExprKind::MacCall(_) => false,
|
|
||||||
_ => !classify::expr_requires_semi_to_be_stmt(innermost),
|
|
||||||
} {
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue