struct Context<'a, 'b> {
Show 24 fields ecx: &'a mut ExtCtxt<'b>, macsp: Span, fmtsp: Span, args: Vec<FormatArg>, num_captured_args: usize, arg_types: Vec<Vec<usize>>, arg_unique_types: Vec<Vec<ArgumentType>>, names: FxHashMap<Symbol, usize>, literal: String, pieces: Vec<P<Expr>>, str_pieces: Vec<P<Expr>>, all_pieces_simple: bool, arg_index_map: Vec<Vec<usize>>, count_args_index_offset: usize, count_args: Vec<usize>, count_positions: FxHashMap<usize, usize>, count_positions_count: usize, curarg: usize, curpiece: usize, invalid_refs: Vec<(usize, usize)>, arg_spans: Vec<Span>, arg_with_formatting: Vec<FormatSpec<'a>>, is_literal: bool, unused_names_lint: PositionalNamedArgsLint,
}

Fields

ecx: &'a mut ExtCtxt<'b>macsp: Span

The macro’s call site. References to unstable formatting internals must use this span to pass the stability checker.

fmtsp: Span

The span of the format string literal.

args: Vec<FormatArg>

List of parsed argument expressions. Named expressions are resolved early, and are appended to the end of argument expressions.

Example showing the various data structures in motion:

  • Original: "{foo:o} {:o} {foo:x} {0:x} {1:o} {:x} {1:x} {0:o}"
  • Implicit argument resolution: "{foo:o} {0:o} {foo:x} {0:x} {1:o} {1:x} {1:x} {0:o}"
  • Name resolution: "{2:o} {0:o} {2:x} {0:x} {1:o} {1:x} {1:x} {0:o}"
  • arg_types (in JSON): [[0, 1, 0], [0, 1, 1], [0, 1]]
  • arg_unique_types (in simplified JSON): [["o", "x"], ["o", "x"], ["o", "x"]]
  • names (in JSON): {"foo": 2}
num_captured_args: usize

The number of arguments that were added by implicit capturing.

arg_types: Vec<Vec<usize>>

Placeholder slot numbers indexed by argument.

arg_unique_types: Vec<Vec<ArgumentType>>

Unique format specs seen for each argument.

names: FxHashMap<Symbol, usize>

Map from named arguments to their resolved indices.

literal: String

The latest consecutive literal strings, or empty if there weren’t any.

pieces: Vec<P<Expr>>

Collection of the compiled rt::Argument structures

str_pieces: Vec<P<Expr>>

Collection of string literals

all_pieces_simple: bool

Stays true if all formatting parameters are default (as in “{}{}”).

arg_index_map: Vec<Vec<usize>>

Mapping between positional argument references and indices into the final generated static argument array. We record the starting indices corresponding to each positional argument, and number of references consumed so far for each argument, to facilitate correct Position mapping in build_piece. In effect this can be seen as a “flattened” version of arg_unique_types.

Again with the example described above in docstring for args:

  • arg_index_map (in JSON): [[0, 1, 0], [2, 3, 3], [4, 5]]
count_args_index_offset: usize

Starting offset of count argument slots.

count_args: Vec<usize>

Count argument slots and tracking data structures. Count arguments are separately tracked for de-duplication in case multiple references are made to one argument. For example, in this format string:

  • Original: "{:.*} {:.foo$} {1:.*} {:.0$}"
  • Implicit argument resolution: "{1:.0$} {2:.foo$} {1:.3$} {4:.0$}"
  • Name resolution: "{1:.0$} {2:.5$} {1:.3$} {4:.0$}"
  • count_positions (in JSON): {0: 0, 5: 1, 3: 2}
  • count_args: vec![0, 5, 3]
count_positions: FxHashMap<usize, usize>

Relative slot numbers for count arguments.

count_positions_count: usize

Number of count slots assigned.

curarg: usize

Current position of the implicit positional arg pointer, as if it still existed in this phase of processing. Used only for all_pieces_simple tracking in build_piece.

curpiece: usize

Current piece being evaluated, used for error reporting.

invalid_refs: Vec<(usize, usize)>

Keep track of invalid references to positional arguments.

arg_spans: Vec<Span>

Spans of all the formatting arguments, in order.

arg_with_formatting: Vec<FormatSpec<'a>>

All the formatting arguments that have formatting flags set, in order for diagnostics.

is_literal: bool

Whether this format string came from a string literal, as opposed to a macro.

unused_names_lint: PositionalNamedArgsLint

Implementations

The number of arguments that were explicitly given.

Verifies one piece of a parse string, and remembers it if valid. All errors are not emitted as fatal so we can continue giving errors about this and possibly other format strings.

Handle invalid references to positional arguments. Output different errors for the case where all arguments are positional and for when there are named arguments or numbered positional arguments in the format string.

Actually verifies and tracks a given format placeholder (a.k.a. argument).

Builds the mapping between format placeholders and argument objects.

Build a literal expression from the accumulated string literals

Builds a static rt::Argument from a parse::Piece or append to the literal string.

Actually builds the expression which the format_args! block will be expanded to.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.

Layout

Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...) attributes. Please see the Rust Reference’s “Type Layout” chapter for details on type layout guarantees.

Size: 424 bytes