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Β§
- Format
Args Storage - Stores AST [
FormatArgs] nodes for use in late lint passes, as they are in a desugared form in the HIR - Macro
Call - A macro call, like
vec![1, 2, 3].
EnumsΒ§
- Format
Param Usage - Where a format parameter is being used in the format string
- Panic
Call - A call to a function in
std::rtorcore::panickingthat results in a panic, typically part of apanic!()expansion (often wrapped in a block) but may be called directly by other macros such asassert.
ConstantsΒ§
TraitsΒ§
- HirNode
- A node with a
HirIdand aSpan
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!ordebug_assert!macro call within the macro expansion - find_
assert_ πargs_ inner - find_
assert_ eq_ args - Finds the arguments of an
assert_eq!ordebug_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
nodeis the βfirst nodeβ in a macro expansion, returnsSomewith theExpnIdof 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 wherenodeis the βfirst nodeβ of the macro call, as infirst_node_in_macro. - format_
arg_ removal_ span - Returns the [
Span] of the value atindexextended to the previous comma, e.g. for the value10 - 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_idofassert!ordebug_assert! - is_
format_ macro - Returns true if a given Macro
DefIdis a format macro (e.g.println!) - is_
panic - Is
def_idofstd::panic,core::panicor 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_callandis_diagnostic_itemthat returns aMacroCallat the root expansion if only it matches the given name. - root_
macro_ call - If the macro backtrace of
spanhas a macro call at the root expansion (i.e. not a nested macro call), returnsSomewith theMacroCall - root_
macro_ call_ first_ node - Like
root_macro_call, but only returnsSomeifnodeis the βfirst nodeβ produced by the macro call, as infirst_node_in_macro. - span_
is_ local - Checks whether the span is from the root expansion or a locally defined macro