Module clippy_utils::check_proc_macro
source · Expand description
This module handles checking if the span given is from a proc-macro or not.
Proc-macros are capable of setting the span of every token they output to a few possible spans. This includes spans we can detect easily as coming from a proc-macro (e.g. the call site or the def site), and spans we can’t easily detect as such (e.g. the span of any token passed into the proc macro). This capability means proc-macros are capable of generating code with a span that looks like it was written by the user, but which should not be linted by clippy as it was generated by an external macro.
That brings us to this module. The current approach is to determine a small bit of text which
must exist at both the start and the end of an item (e.g. an expression or a path) assuming the
code was written, and check if the span contains that text. Note this will only work correctly
if the span is not from a macro_rules
based macro.
Macros
Enums
- The search pattern to look for. Used by
span_matches_pat
Traits
Functions
- Get the search patterns to use for the given expression
- Checks if the item likely came from a proc-macro.
- Checks if the span actually refers to an if expression
- Checks if the span actually refers to a match expression
- Get the search patterns to use for the given literal
- Get the search patterns to use for the given path
- Checks if the start and the end of the span’s text matches the patterns. This will return false if the span crosses multiple files or if source is not available.