Struct rustc_ast_pretty::pprust::state::expr::FixupContext
source · pub(crate) struct FixupContext {
pub stmt: bool,
pub leftmost_subexpression_in_stmt: bool,
pub parenthesize_exterior_struct_lit: bool,
}
Fields§
§stmt: bool
Print expression such that it can be parsed back as a statement consisting of the original expression.
The effect of this is for binary operators in statement position to set
leftmost_subexpression_in_stmt
when printing their left-hand operand.
(match x {}) - 1; // match needs parens when LHS of binary operator
match x {}; // not when its own statement
leftmost_subexpression_in_stmt: bool
This is the difference between:
(match x {}) - 1; // subexpression needs parens
let _ = match x {} - 1; // no parens
There are 3 distinguishable contexts in which print_expr
might be
called with the expression $match
as its argument, where $match
represents an expression of kind ExprKind::Match
:
-
stmt=false leftmost_subexpression_in_stmt=false
Example:
let _ = $match - 1;
No parentheses required.
-
stmt=false leftmost_subexpression_in_stmt=true
Example:
$match - 1;
Must parenthesize
($match)
, otherwise parsing back the output as a statement would terminate the statement after the closing brace of the match, parsing-1;
as a separate statement. -
stmt=true leftmost_subexpression_in_stmt=false
Example:
$match;
No parentheses required.
parenthesize_exterior_struct_lit: bool
This is the difference between:
if let _ = (Struct {}) {} // needs parens
match () {
() if let _ = Struct {} => {} // no parens
}
Trait Implementations§
source§impl Clone for FixupContext
impl Clone for FixupContext
source§fn clone(&self) -> FixupContext
fn clone(&self) -> FixupContext
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for FixupContext
impl Debug for FixupContext
source§impl Default for FixupContext
impl Default for FixupContext
The default amount of fixing is minimal fixing. Fixups should be turned on in a targetted fashion where needed.
impl Copy for FixupContext
Auto Trait Implementations§
impl DynSend for FixupContext
impl DynSync for FixupContext
impl Freeze for FixupContext
impl RefUnwindSafe for FixupContext
impl Send for FixupContext
impl Sync for FixupContext
impl Unpin for FixupContext
impl UnwindSafe for FixupContext
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>
§impl<T> Pointable for T
impl<T> Pointable for T
source§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: 3 bytes