Skip to content

False branches_sharing_code for bodies with macro call(s) #14873

@msix29

Description

@msix29

Summary

If needed, this is the file (currently editing - line numbers given by the lint may be off by a small amount).

Lint Name

branches_sharing_code

Reproducer

Given:

let equal_or_colon = if parse_args.is_type {
    maybe_next_token!(lexer, temp, TokenType::Symbol(Symbol::Colon));
    temp
} else {
    maybe_next_token!(lexer, temp, TokenType::Symbol(Symbol::Equal));
    temp
};

The maybe_next_token! macro takes a pat as the final argument (thus this can't be refactored). Clippy thinks both macro calls are the same when they clearly aren't. Full message:

all if blocks contain the same code at the start
for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#branches_sharing_code
`#[warn(clippy::branches_sharing_code)]` implied by `#[warn(clippy::nursery)]`clippy[branches_sharing_code](rust-analyzer-diagnostics-view:/diagnostic%20message%20[3]?3#file:///home/Ryo/dev/rust/luau/parser/src/impl/value/table.rs)

and

table.rs(113, 21): consider moving these statements before the if: `maybe_next_token!(lexer, temp, TokenType::Symbol(Symbol::Colon));
let equal_or_colon = if parse_args.is_type {`

Version

rustc 1.87.0 (17067e9ac 2025-05-09)
binary: rustc
commit-hash: 17067e9ac6d7ecb70e50f92c1944e545188d2359
commit-date: 2025-05-09
host: x86_64-unknown-linux-gnu
release: 1.87.0
LLVM version: 20.1.1

Additional Labels

No response

Metadata

Metadata

Assignees

Labels

C-bugCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't haveL-nurseryLint: Currently in the nursery group

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions