[−][src]Struct rustc_builtin_macros::format::Context
Fields
ecx: &'a mut ExtCtxt<'b>macsp: SpanThe macro's call site. References to unstable formatting internals must use this span to pass the stability checker.
fmtsp: SpanThe span of the format string literal.
args: Vec<P<Expr>>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}
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: StringThe 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: boolStays 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: usizeStarting offset of count argument slots.
count_args: Vec<Position>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![Exact(0), Exact(5), Exact(3)]
count_positions: FxHashMap<usize, usize>Relative slot numbers for count arguments.
count_positions_count: usizeNumber of count slots assigned.
curarg: usizeCurrent 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: usizeCurrent 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: boolWhether this format string came from a string literal, as opposed to a macro.
Implementations
impl<'a, 'b> Context<'a, 'b>[src]
pub(in format) fn resolve_name_inplace(
&self,
p: &mut Piece<'_>
)[src]
&self,
p: &mut Piece<'_>
)
pub(in format) fn verify_piece(
&mut self,
p: &Piece<'_>
)[src]
&mut self,
p: &Piece<'_>
)
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.
pub(in format) fn verify_count(
&mut self,
c: Count
)[src]
&mut self,
c: Count
)
pub(in format) fn describe_num_args(
&self
) -> Cow<'_, str>[src]
&self
) -> Cow<'_, str>
pub(in format) fn report_invalid_references(
&self,
numbered_position_args: bool
)[src]
&self,
numbered_position_args: bool
)
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.
pub(in format) fn verify_arg_type(
&mut self,
arg: Position,
ty: ArgumentType
)[src]
&mut self,
arg: Position,
ty: ArgumentType
)
Actually verifies and tracks a given format placeholder (a.k.a. argument).
pub(in format) fn build_index_map(
&mut self
)[src]
&mut self
)
Builds the mapping between format placeholders and argument objects.
pub(in format) fn rtpath(
ecx: &ExtCtxt<'_>,
s: Symbol
) -> Vec<Ident>[src]
ecx: &ExtCtxt<'_>,
s: Symbol
) -> Vec<Ident>
pub(in format) fn build_count(
&self,
c: Count
) -> P<Expr>[src]
&self,
c: Count
) -> P<Expr>
pub(in format) fn build_literal_string(
&mut self
) -> P<Expr>[src]
&mut self
) -> P<Expr>
Build a literal expression from the accumulated string literals
pub(in format) fn build_piece(
&mut self,
piece: &Piece<'a>,
arg_index_consumed: &mut Vec<usize>
) -> Option<P<Expr>>[src]
&mut self,
piece: &Piece<'a>,
arg_index_consumed: &mut Vec<usize>
) -> Option<P<Expr>>
Builds a static rt::Argument from a parse::Piece or append
to the literal string.
pub(in format) fn into_expr(
self
) -> P<Expr>[src]
self
) -> P<Expr>
Actually builds the expression which the format_args! block will be expanded to.
pub(in format) fn format_arg(
ecx: &ExtCtxt<'_>,
macsp: Span,
sp: Span,
ty: &ArgumentType,
arg: Ident
) -> P<Expr>[src]
ecx: &ExtCtxt<'_>,
macsp: Span,
sp: Span,
ty: &ArgumentType,
arg: Ident
) -> P<Expr>
Auto Trait Implementations
impl<'a, 'b> !RefUnwindSafe for Context<'a, 'b>
impl<'a, 'b> !Send for Context<'a, 'b>
impl<'a, 'b> !Sync for Context<'a, 'b>
impl<'a, 'b> Unpin for Context<'a, 'b> where
'b: 'a,
'b: 'a,
impl<'a, 'b> !UnwindSafe for Context<'a, 'b>
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized, [src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized, [src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized, [src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T[src]
impl<T> From<T> for T[src]
impl<T, U> Into<U> for T where
U: From<T>, [src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>, [src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>, [src]
U: TryFrom<T>,