forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
ClosestAstOrMacro
to allow detecting macro expansions
Following PR rust-lang#72389, we create many more spans with `ExpnKind::Desugaring`. This exposed a latent bug in Clippy - only the top-most `ExpnData` is considered when checking if code is the result of a macro expansion. If code emitted by a macro expansion gets annotated with an `ExpnKind::Desugaring` (e.g. an operator or a for loop), Clippy will incorrectly act as though this code is not the result of a macro expansion. This PR introduces the `ClosestAstOrMacro` enum, which allows linting code to quickly determine if a given `Span` is the result of a macro expansion. For any `ExpnId`, we keep track of closest `ExpnKind::Macro` or `ExpnKind::AstPass` in the `call_site` chain. This is determined when the `ExpnData` is set for an `ExpnId`, which allows us to avoid walking the entire chain in Clippy.
- Loading branch information
Showing
2 changed files
with
74 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters