Skip to main content

Module macros

Module macros 

Source
Expand description

Utilities for analyzing macro invocations and expansions.

Re-exportsΒ§

use std::cell::Cell; πŸ”’
use std::sync::Arc; πŸ”’
use std::sync::OnceLock; πŸ”’
use crate::visitors::Descend; πŸ”’
use crate::visitors::for_each_expr_without_closures; πŸ”’
use crate::get_clippy_attr; πŸ”’
use crate::sym; πŸ”’
use arrayvec::ArrayVec; πŸ”’
use rustc_ast::FormatArgs; πŸ”’
use rustc_ast::FormatArgument; πŸ”’
use rustc_ast::FormatPlaceholder; πŸ”’
use rustc_data_structures::fx::FxHashMap; πŸ”’
use rustc_hir as hir; πŸ”’
use rustc_hir::Expr; πŸ”’
use rustc_hir::ExprKind; πŸ”’
use rustc_hir::HirId; πŸ”’
use rustc_hir::Node; πŸ”’
use rustc_hir::QPath; πŸ”’
use rustc_lint::LateContext; πŸ”’
use rustc_span::def_id::DefId; πŸ”’
use rustc_span::hygiene; πŸ”’
use rustc_span::hygiene::MacroKind; πŸ”’
use rustc_span::hygiene::SyntaxContext; πŸ”’
use rustc_span::BytePos; πŸ”’
use rustc_span::ExpnData; πŸ”’
use rustc_span::ExpnId; πŸ”’
use rustc_span::ExpnKind; πŸ”’
use rustc_span::Span; πŸ”’
use rustc_span::SpanData; πŸ”’
use rustc_span::Symbol; πŸ”’
use std::ops::ControlFlow; πŸ”’

MacrosΒ§

impl_hir_node πŸ”’

StructsΒ§

FormatArgsStorage
Stores AST [FormatArgs] nodes for use in late lint passes, as they are in a desugared form in the HIR
MacroCall
A macro call, like vec![1, 2, 3].

EnumsΒ§

FormatParamUsage
Where a format parameter is being used in the format string
PanicCall
A call to a function in std::rt or core::panicking that results in a panic, typically part of a panic!() expansion (often wrapped in a block) but may be called directly by other macros such as assert.

ConstantsΒ§

FORMAT_MACRO_DIAG_ITEMS πŸ”’
LAST_FIRST_NODE_IN_MACRO πŸ”’

TraitsΒ§

HirNode
A node with a HirId and a Span

FunctionsΒ§

expn_backtrace
Returns an iterator of expansions that created the given span
expn_is_local
Checks whether the expansion is the root expansion or a locally defined macro
find_assert_args
Finds the arguments of an assert! or debug_assert! macro call within the macro expansion
find_assert_args_inner πŸ”’
find_assert_eq_args
Finds the arguments of an assert_eq! or debug_assert_eq! macro call within the macro expansion
find_assert_within_debug_assert πŸ”’
find_format_arg_expr
Attempt to find the [rustc_hir::Expr] that corresponds to the [FormatArgument]’s value
first_node_in_macro
If node is the β€œfirst node” in a macro expansion, returns Some with the ExpnId of the macro call site (i.e. the parent of the macro expansion).
first_node_in_macro_uncached πŸ”’
first_node_macro_backtrace
Like macro_backtrace, but only returns macro calls where node is the β€œfirst node” of the macro call, as in first_node_in_macro.
format_arg_removal_span
Returns the [Span] of the value at index extended to the previous comma, e.g. for the value 10
format_args_inputs_span
Span covering the format string and values
format_placeholder_format_span
Span of the : and format specifiers
is_assert_arg πŸ”’
is_assert_macro
Is def_id of assert! or debug_assert!
is_format_macro
Returns true if a given Macro DefId is a format macro (e.g. println!)
is_panic
Is def_id of std::panic, core::panic or any inner implementation macros
macro_backtrace
Returns an iterator of macro expansions that created the given span. Note that desugaring expansions are skipped.
matching_root_macro_call
A combination of root_macro_call and is_diagnostic_item that returns a MacroCall at the root expansion if only it matches the given name.
root_macro_call
If the macro backtrace of span has a macro call at the root expansion (i.e. not a nested macro call), returns Some with the MacroCall
root_macro_call_first_node
Like root_macro_call, but only returns Some if node is the β€œfirst node” produced by the macro call, as in first_node_in_macro.
span_is_local
Checks whether the span is from the root expansion or a locally defined macro