pub struct State<'a> {
pub s: Printer,
comments: Option<Comments<'a>>,
ann: &'a (dyn PpAnn + 'a),
}
Fields§
§s: Printer
§comments: Option<Comments<'a>>
§ann: &'a (dyn PpAnn + 'a)
Implementations§
source§impl<'a> State<'a>
impl<'a> State<'a>
fn print_else(&mut self, els: Option<&Expr>)
fn print_if(&mut self, test: &Expr, blk: &Block, elseopt: Option<&Expr>)
fn print_call_post(&mut self, args: &[P<Expr>])
fn print_expr_maybe_paren(&mut self, expr: &Expr, prec: i8, fixup: FixupContext)
sourcefn print_expr_as_cond(&mut self, expr: &Expr)
fn print_expr_as_cond(&mut self, expr: &Expr)
Prints an expr using syntax that’s acceptable in a condition position, such as the cond
in
if cond { ... }
.
sourcefn cond_needs_par(expr: &Expr) -> bool
fn cond_needs_par(expr: &Expr) -> bool
Does expr
need parentheses when printed in a condition position?
These cases need parens due to the parse error observed in #26461: if return {}
parses as the erroneous construct if (return {})
, not if (return) {}
.
sourcepub(super) fn print_expr_cond_paren(
&mut self,
expr: &Expr,
needs_par: bool,
fixup: FixupContext,
)
pub(super) fn print_expr_cond_paren( &mut self, expr: &Expr, needs_par: bool, fixup: FixupContext, )
Prints expr
or (expr)
when needs_par
holds.
fn print_expr_vec(&mut self, exprs: &[P<Expr>])
pub(super) fn print_expr_anon_const( &mut self, expr: &AnonConst, attrs: &[Attribute], )
fn print_expr_repeat(&mut self, element: &Expr, count: &AnonConst)
fn print_expr_struct( &mut self, qself: &Option<P<QSelf>>, path: &Path, fields: &[ExprField], rest: &StructRest, )
fn print_expr_tup(&mut self, exprs: &[P<Expr>])
fn print_expr_call( &mut self, func: &Expr, args: &[P<Expr>], fixup: FixupContext, )
fn print_expr_method_call( &mut self, segment: &PathSegment, receiver: &Expr, base_args: &[P<Expr>], fixup: FixupContext, )
fn print_expr_binary( &mut self, op: BinOp, lhs: &Expr, rhs: &Expr, fixup: FixupContext, )
fn print_expr_unary(&mut self, op: UnOp, expr: &Expr, fixup: FixupContext)
fn print_expr_addr_of( &mut self, kind: BorrowKind, mutability: Mutability, expr: &Expr, fixup: FixupContext, )
pub(super) fn print_expr(&mut self, expr: &Expr, fixup: FixupContext)
pub(super) fn print_expr_outer_attr_style( &mut self, expr: &Expr, is_inline: bool, fixup: FixupContext, )
fn print_arm(&mut self, arm: &Arm)
fn print_closure_binder(&mut self, binder: &ClosureBinder)
fn print_movability(&mut self, movability: Movability)
fn print_capture_clause(&mut self, capture_clause: CaptureBy)
source§impl<'a> State<'a>
impl<'a> State<'a>
fn print_foreign_mod(&mut self, nmod: &ForeignMod, attrs: &[Attribute])
fn print_foreign_item(&mut self, item: &ForeignItem)
fn print_item_const( &mut self, ident: Ident, mutbl: Option<Mutability>, generics: &Generics, ty: &Ty, body: Option<&Expr>, vis: &Visibility, defaultness: Defaultness, )
fn print_associated_type( &mut self, ident: Ident, generics: &Generics, where_clauses: TyAliasWhereClauses, bounds: &GenericBounds, ty: Option<&Ty>, vis: &Visibility, defaultness: Defaultness, )
sourcepub(crate) fn print_item(&mut self, item: &Item)
pub(crate) fn print_item(&mut self, item: &Item)
Pretty-prints an item.
fn print_enum_def( &mut self, enum_definition: &EnumDef, generics: &Generics, ident: Ident, span: Span, visibility: &Visibility, )
fn print_variants(&mut self, variants: &[Variant], span: Span)
pub(crate) fn print_visibility(&mut self, vis: &Visibility)
fn print_defaultness(&mut self, defaultness: Defaultness)
pub(crate) fn print_record_struct_body( &mut self, fields: &[FieldDef], span: Span, )
fn print_struct( &mut self, struct_def: &VariantData, generics: &Generics, ident: Ident, span: Span, print_finalizer: bool, )
pub(crate) fn print_variant(&mut self, v: &Variant)
fn print_assoc_item(&mut self, item: &AssocItem)
fn print_delegation( &mut self, attrs: &[Attribute], vis: &Visibility, qself: &Option<P<QSelf>>, path: &Path, kind: DelegationKind<'_>, body: &Option<P<Block>>, )
fn print_fn_full( &mut self, sig: &FnSig, name: Ident, generics: &Generics, vis: &Visibility, defaultness: Defaultness, body: Option<&Block>, attrs: &[Attribute], )
pub(crate) fn print_fn( &mut self, decl: &FnDecl, header: FnHeader, name: Option<Ident>, generics: &Generics, )
pub(crate) fn print_fn_params_and_ret( &mut self, decl: &FnDecl, is_closure: bool, )
fn print_where_clause(&mut self, where_clause: &WhereClause)
fn print_where_clause_parts( &mut self, has_where_token: bool, predicates: &[WherePredicate], )
pub fn print_where_predicate(&mut self, predicate: &WherePredicate)
pub(crate) fn print_where_bound_predicate( &mut self, where_bound_predicate: &WhereBoundPredicate, )
fn print_use_tree(&mut self, tree: &UseTree)
source§impl<'a> State<'a>
impl<'a> State<'a>
pub fn new() -> State<'a>
fn commasep_cmnt<T, F, G>(&mut self, b: Breaks, elts: &[T], op: F, get_span: G)
fn commasep_exprs(&mut self, b: Breaks, exprs: &[P<Expr>])
pub fn print_opt_lifetime(&mut self, lifetime: &Option<Lifetime>)
pub fn print_assoc_item_constraint(&mut self, constraint: &AssocItemConstraint)
pub fn print_generic_arg(&mut self, generic_arg: &GenericArg)
pub fn print_type(&mut self, ty: &Ty)
fn print_trait_ref(&mut self, t: &TraitRef)
fn print_formal_generic_params(&mut self, generic_params: &[GenericParam])
fn print_poly_trait_ref(&mut self, t: &PolyTraitRef)
fn print_stmt(&mut self, st: &Stmt)
fn print_block(&mut self, blk: &Block)
fn print_block_unclosed_indent(&mut self, blk: &Block)
fn print_block_with_attrs(&mut self, blk: &Block, attrs: &[Attribute])
fn print_block_maybe_unclosed( &mut self, blk: &Block, attrs: &[Attribute], close_box: bool, )
sourcefn print_let(&mut self, pat: &Pat, expr: &Expr, fixup: FixupContext)
fn print_let(&mut self, pat: &Pat, expr: &Expr, fixup: FixupContext)
Print a let pat = expr
expression.
Parentheses are inserted surrounding expr
if a round-trip through the
parser would otherwise work out the wrong way in a condition position.
For example each of the following would mean the wrong thing without parentheses.
if let _ = (Struct {}) {}
if let _ = (true && false) {}
In a match guard, the second case still requires parens, but the first
case no longer does because anything until =>
is considered part of
the match guard expression. Parsing of the expression is not terminated
by {
in that position.
match () {
() if let _ = Struct {} => {}
() if let _ = (true && false) => {}
}
fn print_mac(&mut self, m: &MacCall)
fn print_inline_asm(&mut self, asm: &InlineAsm)
fn print_local_decl(&mut self, loc: &Local)
fn print_name(&mut self, name: Symbol)
fn print_qpath( &mut self, path: &Path, qself: &QSelf, colons_before_params: bool, )
fn print_pat(&mut self, pat: &Pat)
fn print_explicit_self(&mut self, explicit_self: &ExplicitSelf)
fn print_coroutine_kind(&mut self, coroutine_kind: CoroutineKind)
pub fn print_type_bounds(&mut self, bounds: &[GenericBound])
fn print_lifetime(&mut self, lifetime: Lifetime)
fn print_lifetime_bounds(&mut self, bounds: &GenericBounds)
fn print_generic_params(&mut self, generic_params: &[GenericParam])
pub fn print_mutability(&mut self, mutbl: Mutability, print_const: bool)
fn print_mt(&mut self, mt: &MutTy, print_const: bool)
fn print_param(&mut self, input: &Param, is_closure: bool)
fn print_fn_ret_ty(&mut self, fn_ret_ty: &FnRetTy)
fn print_ty_fn( &mut self, ext: Extern, safety: Safety, decl: &FnDecl, name: Option<Ident>, generic_params: &[GenericParam], )
fn print_fn_header_info(&mut self, header: FnHeader)
fn print_safety(&mut self, s: Safety)
fn print_constness(&mut self, s: Const)
fn print_is_auto(&mut self, s: IsAuto)
fn print_meta_item_lit(&mut self, lit: &MetaItemLit)
fn print_token_literal(&mut self, token_lit: Lit, span: Span)
fn print_symbol(&mut self, sym: Symbol, style: StrStyle)
fn print_inner_attributes_no_trailing_hardbreak( &mut self, attrs: &[Attribute], ) -> bool
fn print_outer_attributes_inline(&mut self, attrs: &[Attribute]) -> bool
fn print_attribute(&mut self, attr: &Attribute)
fn print_meta_list_item(&mut self, item: &MetaItemInner)
fn print_meta_item(&mut self, item: &MetaItem)
pub(crate) fn bounds_to_string(&self, bounds: &[GenericBound]) -> String
pub(crate) fn where_bound_predicate_to_string( &self, where_bound_predicate: &WhereBoundPredicate, ) -> String
pub(crate) fn tt_to_string(&self, tt: &TokenTree) -> String
pub(crate) fn path_segment_to_string(&self, p: &PathSegment) -> String
pub(crate) fn meta_list_item_to_string(&self, li: &MetaItemInner) -> String
pub(crate) fn attribute_to_string(&self, attr: &Attribute) -> String
Methods from Deref<Target = Printer>§
pub fn word_space<W: Into<Cow<'static, str>>>(&mut self, w: W)
pub fn popen(&mut self)
pub fn pclose(&mut self)
pub fn hardbreak_if_not_bol(&mut self)
pub fn space_if_not_bol(&mut self)
pub fn nbsp(&mut self)
pub fn word_nbsp<S: Into<Cow<'static, str>>>(&mut self, w: S)
sourcepub fn synth_comment(&mut self, text: impl Into<Cow<'static, str>>)
pub fn synth_comment(&mut self, text: impl Into<Cow<'static, str>>)
Synthesizes a comment that was not textually present in the original source file.
pub fn visual_align(&mut self)
pub fn break_offset(&mut self, n: usize, off: isize)
pub fn end(&mut self)
pub fn word<S: Into<Cow<'static, str>>>(&mut self, wrd: S)
fn spaces(&mut self, n: usize)
pub fn zerobreak(&mut self)
pub fn space(&mut self)
pub fn hardbreak(&mut self)
pub fn is_beginning_of_line(&self) -> bool
pub fn trailing_comma(&mut self)
pub fn trailing_comma_or_space(&mut self)
pub(crate) fn last_token(&self) -> Option<&Token>
pub(crate) fn last_token_still_buffered(&self) -> Option<&Token>
sourcepub(crate) fn replace_last_token_still_buffered(&mut self, token: Token)
pub(crate) fn replace_last_token_still_buffered(&mut self, token: Token)
Be very careful with this!
fn scan_eof(&mut self)
fn scan_begin(&mut self, token: BeginToken)
fn scan_end(&mut self)
fn scan_break(&mut self, token: BreakToken)
fn scan_string(&mut self, string: Cow<'static, str>)
pub(crate) fn offset(&mut self, offset: isize)
fn check_stream(&mut self)
fn advance_left(&mut self)
fn check_stack(&mut self, depth: usize)
fn get_top(&self) -> PrintFrame
fn print_begin(&mut self, token: BeginToken, size: isize)
fn print_end(&mut self)
fn print_break(&mut self, token: BreakToken, size: isize)
fn print_string(&mut self, string: &str)
Trait Implementations§
source§impl<'a> PrintState<'a> for State<'a>
impl<'a> PrintState<'a> for State<'a>
fn comments(&self) -> Option<&Comments<'a>>
fn comments_mut(&mut self) -> Option<&mut Comments<'a>>
fn ann_post(&mut self, ident: Ident)
fn print_generic_args(&mut self, args: &GenericArgs, colons_before_params: bool)
fn print_ident(&mut self, ident: Ident)
fn strsep<T, F>( &mut self, sep: &'static str, space_before: bool, b: Breaks, elts: &[T], op: F, )
fn commasep<T, F>(&mut self, b: Breaks, elts: &[T], op: F)
fn maybe_print_comment(&mut self, pos: BytePos) -> bool
fn print_comment(&mut self, cmnt: Comment)
fn peek_comment<'b>(&'b self) -> Option<&'b Comment>where
'a: 'b,
fn next_comment(&mut self) -> Option<Comment>
fn maybe_print_trailing_comment( &mut self, span: Span, next_pos: Option<BytePos>, )
fn print_remaining_comments(&mut self)
fn print_string(&mut self, st: &str, style: StrStyle)
fn print_inner_attributes(&mut self, attrs: &[Attribute]) -> bool
fn print_outer_attributes(&mut self, attrs: &[Attribute]) -> bool
fn print_either_attributes( &mut self, attrs: &[Attribute], kind: AttrStyle, is_inline: bool, trailing_hardbreak: bool, ) -> bool
fn print_attribute_inline(&mut self, attr: &Attribute, is_inline: bool)
fn print_attr_item(&mut self, item: &AttrItem, span: Span)
source§fn print_tt(&mut self, tt: &TokenTree, convert_dollar_crate: bool) -> Spacing
fn print_tt(&mut self, tt: &TokenTree, convert_dollar_crate: bool) -> Spacing
fn print_tts(&mut self, tts: &TokenStream, convert_dollar_crate: bool)
fn print_mac_common( &mut self, header: Option<MacHeader<'_>>, has_bang: bool, ident: Option<Ident>, delim: Delimiter, tts: &TokenStream, convert_dollar_crate: bool, span: Span, )
fn print_mac_def( &mut self, macro_def: &MacroDef, ident: &Ident, sp: Span, print_visibility: impl FnOnce(&mut Self), )
fn print_path(&mut self, path: &Path, colons_before_params: bool, depth: usize)
fn print_path_segment( &mut self, segment: &PathSegment, colons_before_params: bool, )
fn head<S: Into<Cow<'static, str>>>(&mut self, w: S)
fn bopen(&mut self)
fn bclose_maybe_open(&mut self, span: Span, empty: bool, close_box: bool)
fn bclose(&mut self, span: Span, empty: bool)
fn break_offset_if_not_bol(&mut self, n: usize, off: isize)
fn nonterminal_to_string(&self, nt: &Nonterminal) -> String
source§fn token_kind_to_string(&self, tok: &TokenKind) -> Cow<'static, str>
fn token_kind_to_string(&self, tok: &TokenKind) -> Cow<'static, str>
$crate
into its respective crate name.fn token_kind_to_string_ext( &self, tok: &TokenKind, convert_dollar_crate: Option<Span>, ) -> Cow<'static, str>
source§fn token_to_string(&self, token: &Token) -> Cow<'static, str>
fn token_to_string(&self, token: &Token) -> Cow<'static, str>
$crate
into its respective crate name.fn token_to_string_ext( &self, token: &Token, convert_dollar_crate: bool, ) -> Cow<'static, str>
fn ty_to_string(&self, ty: &Ty) -> String
fn pat_to_string(&self, pat: &Pat) -> String
fn expr_to_string(&self, e: &Expr) -> String
fn meta_item_lit_to_string(&self, lit: &MetaItemLit) -> String
fn stmt_to_string(&self, stmt: &Stmt) -> String
fn item_to_string(&self, i: &Item) -> String
fn path_to_string(&self, p: &Path) -> String
fn vis_to_string(&self, v: &Visibility) -> String
fn block_to_string(&self, blk: &Block) -> String
fn attr_item_to_string(&self, ai: &AttrItem) -> String
fn tts_to_string(&self, tokens: &TokenStream) -> String
fn to_string(f: impl FnOnce(&mut State<'_>)) -> String
Auto Trait Implementations§
impl<'a> Freeze for State<'a>
impl<'a> !RefUnwindSafe for State<'a>
impl<'a> !Send for State<'a>
impl<'a> !Sync for State<'a>
impl<'a> Unpin for State<'a>
impl<'a> !UnwindSafe for State<'a>
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§impl<T> WithSubscriber for T
impl<T> WithSubscriber for T
source§fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
source§fn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
impl<'a, T> Captures<'a> for Twhere
T: ?Sized,
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: 240 bytes