Expand description
hir_expand deals with macro expansion.
Specifically, it implements a concept of MacroFile – a file whose syntax
tree originates not from the text of some FileId, but from some macro
expansion.
Re-exports§
pub use crate::files::AstId;pub use crate::files::ErasedAstId;pub use crate::files::FileRange;pub use crate::files::InFile;pub use crate::files::InMacroFile;pub use crate::files::InRealFile;pub use intern;pub use tt;
Modules§
- attrs
- Defines the basics of attributes lowering.
- builtin
- Builtin macros and attributes
- cfg_
process 🔒 - Processes out
#[cfg]and#[cfg_attr]attributes from the input for the derive macro - change
- Defines a unit of change that can applied to the database to get the next state. Changes are transactional.
- declarative
- Compiled declarative macro expanders (
macro_rules!andmacro) - eager
- Eager expansion related utils
- files
- Things to wrap other things in file ids.
- fixup 🔒
- To make attribute macros work reliably when typing, we need to take care to fix up syntax errors in the code we’re passing to them.
- hygiene
- Machinery for hygienic macros.
- inert_
attr_ macro - Builtin attributes resolved by nameres.
- mod_
path - A lowering for
use-paths (more generally, paths without angle-bracketed segments). - name
- See
Name. - prettify_
macro_ 🔒expansion_ - Pretty printing of macros output.
- proc_
macro - Proc Macro Expander stuff
- span_
map - Span maps for real files and macro expansions.
Macros§
- __
known_ path - __path
- __
tool_ path - impl_
intern_ lookup - quote
- FIXME: It probably should implement in proc-macro
Structs§
- Attr
Macro Attr Ids - Declarative
Macro - This struct contains AST for a single
macro_rulesdefinition. What might be very confusing is that AST has almost exactly the same shape astt::TokenTree, but there’s a crucial difference: in macro rules,$identand$()*have special meaning (seeVarandRepeatdata structures) - Eager
Call Info - Editioned
File Id - Expand
Error - Expansion
Info - ExpansionInfo mainly describes how to map text range between src and expanded macro
- Macro
Call Id - Macro ids. That’s probably the tricksiest bit in rust-analyzer, and the reason why we use salsa at all.
- Macro
Call Loc - Macro
Call Styles - A set of
MacroCallStylevalues, allowing macros to indicate that they support more than one style. - Macro
DefId - Rendered
Expand Error - Value
Result
Enums§
- Attr
Macro 🔒Attr IdsRepr - Expand
Error Kind - Expand
To - In Rust, macros expand token trees to token trees. When we want to turn a
token tree into an AST node, we need to figure out what kind of AST node we
want: something like
foocan be a type, an expression, or a pattern. - HirFile
Id - Macro
Call Kind - Macro
Call Style - Macro
DefKind - Macro
Kind
Constants§
- TOKEN_
LIMIT 🔒 - Total limit on the number of tokens produced by any macro invocation.
Traits§
Functions§
- check_
tt_ 🔒count - expand_
unimplemented_ 🔒builtin_ macro - map_
node_ range_ up - Maps up the text range out of the expansion hierarchy back into the original file its from.
- map_
node_ range_ up_ rooted - Maps up the text range out of the expansion hierarchy back into the original file its from only
considering the root spans contained.
Unlike
map_node_range_up, this will not returnNoneif any anchors or syntax contexts differ. - prettify_
macro_ expansion - Inserts whitespace and replaces
$cratein macro expansions. - proc_
macro_ 🔒span - Retrieves the span to be used for a proc-macro expansions spans. This is a firewall query as it requires parsing the file, which we don’t want proc-macros to directly depend on as that would cause to frequent invalidations, mainly because of the parse queries being LRU cached. If they weren’t the invalidations would only happen if the user wrote in the file that defines the proc-macro.
- resolve_
span - span_
for_ offset - Looks up the span at the given offset.
- token_
tree_ 🔒to_ syntax_ node
Type Aliases§
- Expand
Result - Macro
ArgResult 🔒 - This is just to ensure the types of
MacroCallId::macro_arg_considering_derivesandMacroCallId::macro_argare the same.