Module 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Β§

impl_with_search_pat πŸ”’

EnumsΒ§

Pat
The search pattern to look for. Used by span_matches_pat

TraitsΒ§

WithSearchPat

FunctionsΒ§

attr_search_pat πŸ”’
expr_search_pat πŸ”’
Get the search patterns to use for the given expression
field_def_search_pat πŸ”’
fn_header_search_pat πŸ”’
fn_kind_pat πŸ”’
ident_search_pat πŸ”’
impl_item_search_pat πŸ”’
is_from_proc_macro
Checks if the item likely came from a proc-macro.
is_span_if
Checks if the span actually refers to an if expression
is_span_match
Checks if the span actually refers to a match expression
item_search_pat πŸ”’
lit_search_pat πŸ”’
Get the search patterns to use for the given literal
path_search_pat πŸ”’
qpath_search_pat πŸ”’
Get the search patterns to use for the given path
span_matches_pat πŸ”’
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.
trait_item_search_pat πŸ”’
ty_search_pat πŸ”’
variant_search_pat πŸ”’