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.



  • The search pattern to look for. Used by span_matches_pat