Crate hir_expand

source ·
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§

Modules§

  • A higher level attributes based on TokenTree, with also some shortcuts.
  • Builtin macros and attributes
  • Defines a unit of change that can applied to the database to get the next state. Changes are transactional.
  • Defines database & queries for macro expansion.
  • Compiled declarative macro expanders (macro_rules! and macro)
  • Eager expansion related utils
  • Things to wrap other things in file ids.
  • Machinery for hygienic macros.
  • Builtin attributes resolved by nameres.
  • A lowering for use-paths (more generally, paths without angle-bracketed segments).
  • See Name.
  • Proc Macro Expander stuff
  • Span maps for real files and macro expansions.

Macros§

Structs§

  • This struct contains AST for a single macro_rules definition. What might be very confusing is that AST has almost exactly the same shape as tt::TokenTree, but there’s a crucial difference: in macro rules, $ident and $()* have special meaning (see Var and Repeat data structures)
  • ExpansionInfo mainly describes how to map text range between src and expanded macro
  • Input to the analyzer is a set of files, where each file is identified by FileId and contains source code. However, another source of source code in Rust are macros: each macro can be thought of as producing a “temporary file”. To assign an id to such a file, we use the id of the macro call that produced the file. So, a HirFileId is either a FileId (source code written by user), or a MacroCallId (source code produced by macro).
  • MacroCallId identifies a particular macro invocation, like println!("Hello, {}", world).

Enums§

  • 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 foo can be a type, an expression, or a pattern.

Traits§

Functions§

  • Maps up the text range out of the expansion hierarchy back into the original file its from.
  • Maps up the text range out of the expansion hierarchy back into the original file its from. This version will aggregate the ranges of all spans with the same anchor and syntax context.
  • 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 return None if any anchors or syntax contexts differ.
  • Inserts whitespace and replaces $crate in macro expansions.
  • Looks up the span at the given offset.

Type Aliases§