Skip to content

Commit 98a39cc

Browse files
authored
Merge pull request #1826 from dtolnay/leftmosthelper
Merge leftmost_subexpression_with_operator and leftmost_subexpression into one method
2 parents 15220b9 + 19d93ba commit 98a39cc

2 files changed

Lines changed: 19 additions & 23 deletions

File tree

src/expr.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3306,7 +3306,7 @@ pub(crate) mod printing {
33063306
&e.left,
33073307
Precedence::of(&e.left) <= Precedence::Range,
33083308
tokens,
3309-
fixup.leftmost_subexpression(),
3309+
fixup.leftmost_subexpression_with_operator(false, false),
33103310
);
33113311
e.eq_token.to_tokens(tokens);
33123312
print_subexpression(
@@ -3475,7 +3475,11 @@ pub(crate) mod printing {
34753475
&e.expr,
34763476
Precedence::of(&e.expr) < Precedence::Cast,
34773477
tokens,
3478-
fixup.leftmost_subexpression(),
3478+
fixup.leftmost_subexpression_with_operator(
3479+
#[cfg(feature = "full")]
3480+
false,
3481+
false,
3482+
),
34793483
);
34803484
e.as_token.to_tokens(tokens);
34813485
e.ty.to_tokens(tokens);

src/fixup.rs

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,11 @@ impl FixupContext {
195195
///
196196
/// Not every expression has a leftmost subexpression. For example neither
197197
/// `-$a` nor `[$a]` have one.
198-
pub fn leftmost_subexpression(self) -> Self {
198+
pub fn leftmost_subexpression_with_operator(
199+
self,
200+
#[cfg(feature = "full")] next_operator_can_begin_expr: bool,
201+
next_operator_can_begin_generics: bool,
202+
) -> Self {
199203
FixupContext {
200204
#[cfg(feature = "full")]
201205
stmt: false,
@@ -209,10 +213,10 @@ impl FixupContext {
209213
#[cfg(feature = "full")]
210214
rightmost_subexpression: false,
211215
#[cfg(feature = "full")]
212-
next_operator_can_begin_expr: false,
216+
next_operator_can_begin_expr,
213217
#[cfg(feature = "full")]
214218
next_operator_can_continue_expr: true,
215-
next_operator_can_begin_generics: false,
219+
next_operator_can_begin_generics,
216220
..self
217221
}
218222
}
@@ -242,22 +246,6 @@ impl FixupContext {
242246
}
243247
}
244248

245-
/// Transform this fixup into the one that should apply when printing a
246-
/// leftmost subexpression followed by punctuation that is legal as the
247-
/// first token of an expression.
248-
pub fn leftmost_subexpression_with_operator(
249-
self,
250-
#[cfg(feature = "full")] next_operator_can_begin_expr: bool,
251-
next_operator_can_begin_generics: bool,
252-
) -> Self {
253-
FixupContext {
254-
#[cfg(feature = "full")]
255-
next_operator_can_begin_expr,
256-
next_operator_can_begin_generics,
257-
..self.leftmost_subexpression()
258-
}
259-
}
260-
261249
/// Transform this fixup into the one that should apply when printing the
262250
/// rightmost subexpression of the current expression.
263251
///
@@ -393,10 +381,14 @@ fn test_leftmost_rightmost_invariant() {
393381
};
394382
assert_eq!(i, BITS);
395383
assert_eq!(
396-
fixup.leftmost_subexpression().rightmost_subexpression(),
384+
fixup
385+
.leftmost_subexpression_with_operator(false, false)
386+
.rightmost_subexpression(),
397387
FixupContext {
398388
rightmost_subexpression: true,
399-
..fixup.rightmost_subexpression().leftmost_subexpression()
389+
..fixup
390+
.rightmost_subexpression()
391+
.leftmost_subexpression_with_operator(false, false)
400392
},
401393
);
402394
}

0 commit comments

Comments
 (0)