Struct rustc_hir_pretty::State

source ·
pub struct State<'a> {
    pub s: Printer,
    pub(crate) comments: Option<Comments<'a>>,
    pub(crate) attrs: &'a dyn Fn(HirId) -> &'a [Attribute],
    pub(crate) ann: &'a (dyn PpAnn + 'a),
}

Fields§

§s: Printer§comments: Option<Comments<'a>>§attrs: &'a dyn Fn(HirId) -> &'a [Attribute]§ann: &'a (dyn PpAnn + 'a)

Implementations§

source§

impl<'a> State<'a>

source

pub fn print_node(&mut self, node: Node<'_>)

source§

impl<'a> State<'a>

source

pub fn new_from_input( sm: &'a SourceMap, filename: FileName, input: String, attrs: &'a dyn Fn(HirId) -> &'a [Attribute], ann: &'a dyn PpAnn ) -> State<'a>

source

pub(crate) fn attrs(&self, id: HirId) -> &'a [Attribute]

source§

impl<'a> State<'a>

source

pub fn bclose_maybe_open(&mut self, span: Span, close_box: bool)

source

pub fn bclose(&mut self, span: Span)

source

pub fn commasep_cmnt<T, F, G>( &mut self, b: Breaks, elts: &[T], op: F, get_span: G )where F: FnMut(&mut State<'_>, &T), G: FnMut(&T) -> Span,

source

pub fn commasep_exprs(&mut self, b: Breaks, exprs: &[Expr<'_>])

source

pub fn print_mod(&mut self, _mod: &Mod<'_>, attrs: &[Attribute])

source

pub fn print_opt_lifetime(&mut self, lifetime: &Lifetime)

source

pub fn print_type(&mut self, ty: &Ty<'_>)

source

pub fn print_foreign_item(&mut self, item: &ForeignItem<'_>)

source

pub(crate) fn print_associated_const( &mut self, ident: Ident, generics: &Generics<'_>, ty: &Ty<'_>, default: Option<BodyId> )

source

pub(crate) fn print_associated_type( &mut self, ident: Ident, generics: &Generics<'_>, bounds: Option<GenericBounds<'_>>, ty: Option<&Ty<'_>> )

source

pub(crate) fn print_item_type( &mut self, item: &Item<'_>, generics: &Generics<'_>, inner: impl Fn(&mut Self) )

source

pub fn print_item(&mut self, item: &Item<'_>)

Pretty-print an item

source

pub fn print_trait_ref(&mut self, t: &TraitRef<'_>)

source

pub(crate) fn print_formal_generic_params( &mut self, generic_params: &[GenericParam<'_>] )

source

pub(crate) fn print_poly_trait_ref(&mut self, t: &PolyTraitRef<'_>)

source

pub fn print_enum_def( &mut self, enum_definition: &EnumDef<'_>, generics: &Generics<'_>, name: Symbol, span: Span )

source

pub fn print_variants(&mut self, variants: &[Variant<'_>], span: Span)

source

pub fn print_defaultness(&mut self, defaultness: Defaultness)

source

pub fn print_struct( &mut self, struct_def: &VariantData<'_>, generics: &Generics<'_>, name: Symbol, span: Span, print_finalizer: bool )

source

pub fn print_variant(&mut self, v: &Variant<'_>)

source

pub fn print_method_sig( &mut self, ident: Ident, m: &FnSig<'_>, generics: &Generics<'_>, arg_names: &[Ident], body_id: Option<BodyId> )

source

pub fn print_trait_item(&mut self, ti: &TraitItem<'_>)

source

pub fn print_impl_item(&mut self, ii: &ImplItem<'_>)

source

pub fn print_local( &mut self, init: Option<&Expr<'_>>, els: Option<&Block<'_>>, decl: impl Fn(&mut Self) )

source

pub fn print_stmt(&mut self, st: &Stmt<'_>)

source

pub fn print_block(&mut self, blk: &Block<'_>)

source

pub fn print_block_unclosed(&mut self, blk: &Block<'_>)

source

pub fn print_block_with_attrs(&mut self, blk: &Block<'_>, attrs: &[Attribute])

source

pub fn print_block_maybe_unclosed( &mut self, blk: &Block<'_>, attrs: &[Attribute], close_box: bool )

source

pub(crate) fn print_else(&mut self, els: Option<&Expr<'_>>)

source

pub fn print_if( &mut self, test: &Expr<'_>, blk: &Expr<'_>, elseopt: Option<&Expr<'_>> )

source

pub fn print_array_length(&mut self, len: &ArrayLen)

source

pub fn print_anon_const(&mut self, constant: &AnonConst)

source

pub(crate) fn print_call_post(&mut self, args: &[Expr<'_>])

source

pub(crate) fn print_expr_maybe_paren(&mut self, expr: &Expr<'_>, prec: i8)

source

pub 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 { ... }.

source

pub(crate) fn print_expr_cond_paren(&mut self, expr: &Expr<'_>, needs_par: bool)

Prints expr or (expr) when needs_par holds.

source

pub(crate) fn print_let( &mut self, pat: &Pat<'_>, ty: Option<&Ty<'_>>, init: &Expr<'_> )

Print a let pat = expr expression.

source

pub(crate) fn cond_needs_par(expr: &Expr<'_>) -> bool

source

pub(crate) fn print_expr_vec(&mut self, exprs: &[Expr<'_>])

source

pub(crate) fn print_inline_const(&mut self, constant: &ConstBlock)

source

pub(crate) fn print_expr_repeat(&mut self, element: &Expr<'_>, count: &ArrayLen)

source

pub(crate) fn print_expr_struct( &mut self, qpath: &QPath<'_>, fields: &[ExprField<'_>], wth: Option<&Expr<'_>> )

source

pub(crate) fn print_expr_field(&mut self, field: &ExprField<'_>)

source

pub(crate) fn print_expr_tup(&mut self, exprs: &[Expr<'_>])

source

pub(crate) fn print_expr_call(&mut self, func: &Expr<'_>, args: &[Expr<'_>])

source

pub(crate) fn print_expr_method_call( &mut self, segment: &PathSegment<'_>, receiver: &Expr<'_>, args: &[Expr<'_>] )

source

pub(crate) fn print_expr_binary( &mut self, op: BinOp, lhs: &Expr<'_>, rhs: &Expr<'_> )

source

pub(crate) fn print_expr_unary(&mut self, op: UnOp, expr: &Expr<'_>)

source

pub(crate) fn print_expr_addr_of( &mut self, kind: BorrowKind, mutability: Mutability, expr: &Expr<'_> )

source

pub(crate) fn print_literal(&mut self, lit: &Lit)

source

pub(crate) fn print_inline_asm(&mut self, asm: &InlineAsm<'_>)

source

pub fn print_expr(&mut self, expr: &Expr<'_>)

source

pub fn print_local_decl(&mut self, loc: &Local<'_>)

source

pub fn print_name(&mut self, name: Symbol)

source

pub fn print_path<R>(&mut self, path: &Path<'_, R>, colons_before_params: bool)

source

pub fn print_path_segment(&mut self, segment: &PathSegment<'_>)

source

pub fn print_qpath(&mut self, qpath: &QPath<'_>, colons_before_params: bool)

source

pub(crate) fn print_generic_args( &mut self, generic_args: &GenericArgs<'_>, colons_before_params: bool )

source

pub fn print_type_binding(&mut self, binding: &TypeBinding<'_>)

source

pub fn print_pat(&mut self, pat: &Pat<'_>)

source

pub fn print_patfield(&mut self, field: &PatField<'_>)

source

pub fn print_param(&mut self, arg: &Param<'_>)

source

pub fn print_arm(&mut self, arm: &Arm<'_>)

source

pub fn print_fn( &mut self, decl: &FnDecl<'_>, header: FnHeader, name: Option<Symbol>, generics: &Generics<'_>, arg_names: &[Ident], body_id: Option<BodyId> )

source

pub(crate) fn print_closure_params( &mut self, decl: &FnDecl<'_>, body_id: BodyId )

source

pub fn print_capture_clause(&mut self, capture_clause: CaptureBy)

source

pub fn print_closure_binder( &mut self, binder: ClosureBinder, generic_params: &[GenericParam<'_>] )

source

pub fn print_bounds<'b>( &mut self, prefix: &'static str, bounds: impl IntoIterator<Item = &'b GenericBound<'b>> )

source

pub fn print_generic_params(&mut self, generic_params: &[GenericParam<'_>])

source

pub fn print_generic_param(&mut self, param: &GenericParam<'_>)

source

pub fn print_lifetime(&mut self, lifetime: &Lifetime)

source

pub fn print_where_clause(&mut self, generics: &Generics<'_>)

source

pub fn print_mutability(&mut self, mutbl: Mutability, print_const: bool)

source

pub fn print_mt(&mut self, mt: &MutTy<'_>, print_const: bool)

source

pub fn print_fn_output(&mut self, decl: &FnDecl<'_>)

source

pub fn print_ty_fn( &mut self, abi: Abi, unsafety: Unsafety, decl: &FnDecl<'_>, name: Option<Symbol>, generic_params: &[GenericParam<'_>], arg_names: &[Ident] )

source

pub fn print_fn_header_info(&mut self, header: FnHeader)

source

pub fn print_constness(&mut self, s: Constness)

source

pub fn print_unsafety(&mut self, s: Unsafety)

source

pub fn print_is_auto(&mut self, s: IsAuto)

Trait Implementations§

source§

impl Deref for State<'_>

§

type Target = Printer

The resulting type after dereferencing.
source§

fn deref(&self) -> &Self::Target

Dereferences the value.
source§

impl DerefMut for State<'_>

source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.
source§

impl<'a> PrintState<'a> for State<'a>

source§

fn comments(&mut self) -> &mut Option<Comments<'a>>

source§

fn print_ident(&mut self, ident: Ident)

source§

fn print_generic_args(&mut self, _: &GenericArgs, _colons_before_params: bool)

source§

fn strsep<T, F>( &mut self, sep: &'static str, space_before: bool, b: Breaks, elts: &[T], op: F )where F: FnMut(&mut Self, &T),

source§

fn commasep<T, F>(&mut self, b: Breaks, elts: &[T], op: F)where F: FnMut(&mut Self, &T),

source§

fn maybe_print_comment(&mut self, pos: BytePos) -> bool

source§

fn print_comment(&mut self, cmnt: &Comment)

source§

fn next_comment(&mut self) -> Option<Comment>

source§

fn maybe_print_trailing_comment( &mut self, span: Span, next_pos: Option<BytePos> )

source§

fn print_remaining_comments(&mut self)

source§

fn print_meta_item_lit(&mut self, lit: &MetaItemLit)

source§

fn print_token_literal(&mut self, token_lit: Lit, span: Span)

source§

fn print_string(&mut self, st: &str, style: StrStyle)

source§

fn print_symbol(&mut self, sym: Symbol, style: StrStyle)

source§

fn print_inner_attributes(&mut self, attrs: &[Attribute]) -> bool

source§

fn print_inner_attributes_no_trailing_hardbreak( &mut self, attrs: &[Attribute] ) -> bool

source§

fn print_outer_attributes(&mut self, attrs: &[Attribute]) -> bool

source§

fn print_inner_attributes_inline(&mut self, attrs: &[Attribute]) -> bool

source§

fn print_outer_attributes_inline(&mut self, attrs: &[Attribute]) -> bool

source§

fn print_either_attributes( &mut self, attrs: &[Attribute], kind: AttrStyle, is_inline: bool, trailing_hardbreak: bool ) -> bool

source§

fn print_attribute(&mut self, attr: &Attribute)

source§

fn print_attribute_inline(&mut self, attr: &Attribute, is_inline: bool)

source§

fn print_attr_item(&mut self, item: &AttrItem, span: Span)

source§

fn print_meta_list_item(&mut self, item: &NestedMetaItem)

source§

fn print_meta_item(&mut self, item: &MetaItem)

source§

fn print_tt(&mut self, tt: &TokenTree, convert_dollar_crate: bool)

This doesn’t deserve to be called “pretty” printing, but it should be meaning-preserving. A quick hack that might help would be to look at the spans embedded in the TTs to decide where to put spaces and newlines. But it’d be better to parse these according to the grammar of the appropriate macro, transcribe back into the grammar we just parsed from, and then pretty-print the resulting AST nodes (so, e.g., we print expression arguments as expressions). It can be done! I think.
source§

fn print_tts(&mut self, tts: &TokenStream, convert_dollar_crate: bool)

source§

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 )

source§

fn print_mac_def( &mut self, macro_def: &MacroDef, ident: &Ident, sp: Span, print_visibility: impl FnOnce(&mut Self) )

source§

fn print_path(&mut self, path: &Path, colons_before_params: bool, depth: usize)

source§

fn print_path_segment( &mut self, segment: &PathSegment, colons_before_params: bool )

source§

fn head<S>(&mut self, w: S)where S: Into<Cow<'static, str>>,

source§

fn bopen(&mut self)

source§

fn bclose_maybe_open(&mut self, span: Span, empty: bool, close_box: bool)

source§

fn bclose(&mut self, span: Span, empty: bool)

source§

fn break_offset_if_not_bol(&mut self, n: usize, off: isize)

source§

fn nonterminal_to_string(&self, nt: &Nonterminal) -> String

source§

fn token_kind_to_string(&self, tok: &TokenKind) -> Cow<'static, str>

Print the token kind precisely, without converting $crate into its respective crate name.
source§

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>

Print the token precisely, without converting $crate into its respective crate name.
source§

fn token_to_string_ext( &self, token: &Token, convert_dollar_crate: bool ) -> Cow<'static, str>

source§

fn ty_to_string(&self, ty: &Ty) -> String

source§

fn bounds_to_string(&self, bounds: &[GenericBound]) -> String

source§

fn where_bound_predicate_to_string( &self, where_bound_predicate: &WhereBoundPredicate ) -> String

source§

fn pat_to_string(&self, pat: &Pat) -> String

source§

fn expr_to_string(&self, e: &Expr) -> String

source§

fn meta_item_lit_to_string(&self, lit: &MetaItemLit) -> String

source§

fn tt_to_string(&self, tt: &TokenTree) -> String

source§

fn tts_to_string(&self, tokens: &TokenStream) -> String

source§

fn stmt_to_string(&self, stmt: &Stmt) -> String

source§

fn item_to_string(&self, i: &Item<ItemKind>) -> String

source§

fn assoc_item_to_string(&self, i: &Item<AssocItemKind>) -> String

source§

fn foreign_item_to_string(&self, i: &Item<ForeignItemKind>) -> String

source§

fn generic_params_to_string(&self, generic_params: &[GenericParam]) -> String

source§

fn path_to_string(&self, p: &Path) -> String

source§

fn path_segment_to_string(&self, p: &PathSegment) -> String

source§

fn vis_to_string(&self, v: &Visibility) -> String

source§

fn block_to_string(&self, blk: &Block) -> String

source§

fn meta_list_item_to_string(&self, li: &NestedMetaItem) -> String

source§

fn attr_item_to_string(&self, ai: &AttrItem) -> String

source§

fn attribute_to_string(&self, attr: &Attribute) -> String

source§

fn param_to_string(&self, arg: &Param) -> String

source§

fn to_string(f: impl FnOnce(&mut State<'_>)) -> String

Auto Trait Implementations§

§

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> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

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

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::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: 264 bytes