11use crate :: pp:: Breaks :: Inconsistent ;
2+ use crate :: pprust:: state:: fixup:: FixupContext ;
23use crate :: pprust:: state:: { AnnNode , PrintState , State , INDENT_UNIT } ;
34use ast:: { ForLoopKind , MatchKind } ;
45use itertools:: { Itertools , Position } ;
@@ -14,78 +15,6 @@ use rustc_ast::{
1415} ;
1516use std:: fmt:: Write ;
1617
17- #[ derive( Copy , Clone , Debug ) ]
18- pub ( crate ) struct FixupContext {
19- /// Print expression such that it can be parsed back as a statement
20- /// consisting of the original expression.
21- ///
22- /// The effect of this is for binary operators in statement position to set
23- /// `leftmost_subexpression_in_stmt` when printing their left-hand operand.
24- ///
25- /// ```ignore (illustrative)
26- /// (match x {}) - 1; // match needs parens when LHS of binary operator
27- ///
28- /// match x {}; // not when its own statement
29- /// ```
30- pub stmt : bool ,
31-
32- /// This is the difference between:
33- ///
34- /// ```ignore (illustrative)
35- /// (match x {}) - 1; // subexpression needs parens
36- ///
37- /// let _ = match x {} - 1; // no parens
38- /// ```
39- ///
40- /// There are 3 distinguishable contexts in which `print_expr` might be
41- /// called with the expression `$match` as its argument, where `$match`
42- /// represents an expression of kind `ExprKind::Match`:
43- ///
44- /// - stmt=false leftmost_subexpression_in_stmt=false
45- ///
46- /// Example: `let _ = $match - 1;`
47- ///
48- /// No parentheses required.
49- ///
50- /// - stmt=false leftmost_subexpression_in_stmt=true
51- ///
52- /// Example: `$match - 1;`
53- ///
54- /// Must parenthesize `($match)`, otherwise parsing back the output as a
55- /// statement would terminate the statement after the closing brace of
56- /// the match, parsing `-1;` as a separate statement.
57- ///
58- /// - stmt=true leftmost_subexpression_in_stmt=false
59- ///
60- /// Example: `$match;`
61- ///
62- /// No parentheses required.
63- pub leftmost_subexpression_in_stmt : bool ,
64-
65- /// This is the difference between:
66- ///
67- /// ```ignore (illustrative)
68- /// if let _ = (Struct {}) {} // needs parens
69- ///
70- /// match () {
71- /// () if let _ = Struct {} => {} // no parens
72- /// }
73- /// ```
74- pub parenthesize_exterior_struct_lit : bool ,
75- }
76-
77- /// The default amount of fixing is minimal fixing. Fixups should be turned on
78- /// in a targeted fashion where needed.
79- impl Default for FixupContext {
80- fn default ( ) -> Self {
81- FixupContext {
82- stmt : false ,
83- leftmost_subexpression_in_stmt : false ,
84- parenthesize_exterior_struct_lit : false ,
85- }
86- }
87- }
88-
8918impl < ' a > State < ' a > {
9019 fn print_else ( & mut self , els : Option < & ast:: Expr > ) {
9120 if let Some ( _else) = els {
0 commit comments