@@ -113,10 +113,7 @@ impl<'a> Sugg<'a> {
113
113
/// function variants of `Sugg`, since these use different snippet functions.
114
114
fn hir_from_snippet(expr: &hir::Expr<'_>, mut get_snippet: impl FnMut(Span) -> Cow<'a, str>) -> Self {
115
115
if let Some(range) = higher::Range::hir(expr) {
116
- let op = match range.limits {
117
- ast::RangeLimits::HalfOpen => AssocOp::DotDot,
118
- ast::RangeLimits::Closed => AssocOp::DotDotEq,
119
- };
116
+ let op = AssocOp::Range(range.limits);
120
117
let start = range.start.map_or("".into(), |expr| get_snippet(expr.span));
121
118
let end = range.end.map_or("".into(), |expr| get_snippet(expr.span));
122
119
@@ -178,8 +175,6 @@ impl<'a> Sugg<'a> {
178
175
ctxt: SyntaxContext,
179
176
app: &mut Applicability,
180
177
) -> Self {
181
- use rustc_ast::ast::RangeLimits;
182
-
183
178
let mut snippet = |span: Span| snippet_with_context(cx, span, ctxt, default, app).0;
184
179
185
180
match expr.kind {
@@ -228,13 +223,8 @@ impl<'a> Sugg<'a> {
228
223
| ast::ExprKind::Err(_)
229
224
| ast::ExprKind::Dummy
230
225
| ast::ExprKind::UnsafeBinderCast(..) => Sugg::NonParen(snippet(expr.span)),
231
- ast::ExprKind::Range(ref lhs, ref rhs, RangeLimits::HalfOpen) => Sugg::BinOp(
232
- AssocOp::DotDot,
233
- lhs.as_ref().map_or("".into(), |lhs| snippet(lhs.span)),
234
- rhs.as_ref().map_or("".into(), |rhs| snippet(rhs.span)),
235
- ),
236
- ast::ExprKind::Range(ref lhs, ref rhs, RangeLimits::Closed) => Sugg::BinOp(
237
- AssocOp::DotDotEq,
226
+ ast::ExprKind::Range(ref lhs, ref rhs, limits) => Sugg::BinOp(
227
+ AssocOp::Range(limits),
238
228
lhs.as_ref().map_or("".into(), |lhs| snippet(lhs.span)),
239
229
rhs.as_ref().map_or("".into(), |rhs| snippet(rhs.span)),
240
230
),
@@ -326,11 +316,8 @@ impl<'a> Sugg<'a> {
326
316
327
317
/// Convenience method to create the `<lhs>..<rhs>` or `<lhs>...<rhs>`
328
318
/// suggestion.
329
- pub fn range(self, end: &Self, limit: ast::RangeLimits) -> Sugg<'static> {
330
- match limit {
331
- ast::RangeLimits::HalfOpen => make_assoc(AssocOp::DotDot, &self, end),
332
- ast::RangeLimits::Closed => make_assoc(AssocOp::DotDotEq, &self, end),
333
- }
319
+ pub fn range(self, end: &Self, limits: ast::RangeLimits) -> Sugg<'static> {
320
+ make_assoc(AssocOp::Range(limits), &self, end)
334
321
}
335
322
336
323
/// Adds parentheses to any expression that might need them. Suitable to the
@@ -370,8 +357,7 @@ fn binop_to_string(op: AssocOp, lhs: &str, rhs: &str) -> String {
370
357
AssocOp::Assign => format!("{lhs} = {rhs}"),
371
358
AssocOp::AssignOp(op) => format!("{lhs} {}= {rhs}", op.as_str()),
372
359
AssocOp::As => format!("{lhs} as {rhs}"),
373
- AssocOp::DotDot => format!("{lhs}..{rhs}"),
374
- AssocOp::DotDotEq => format!("{lhs}..={rhs}"),
360
+ AssocOp::Range(limits) => format!("{lhs}{}{rhs}", limits.as_str()),
375
361
}
376
362
}
377
363
@@ -590,7 +576,7 @@ enum Associativity {
590
576
/// associative.
591
577
#[must_use]
592
578
fn associativity(op: AssocOp) -> Associativity {
593
- use rustc_ast::util::parser::AssocOp::{As, Assign, AssignOp, Binary, DotDot, DotDotEq };
579
+ use rustc_ast::util::parser::AssocOp::{As, Assign, AssignOp, Binary, Range };
594
580
use ast::BinOpKind::{
595
581
Add, BitAnd, BitOr, BitXor, Div, Eq, Gt, Ge, And, Or, Lt, Le, Rem, Mul, Ne, Shl, Shr, Sub,
596
582
};
@@ -599,7 +585,7 @@ fn associativity(op: AssocOp) -> Associativity {
599
585
Assign | AssignOp(_) => Associativity::Right,
600
586
Binary(Add | BitAnd | BitOr | BitXor | And | Or | Mul) | As => Associativity::Both,
601
587
Binary(Div | Eq | Gt | Ge | Lt | Le | Rem | Ne | Shl | Shr | Sub) => Associativity::Left,
602
- DotDot | DotDotEq => Associativity::None,
588
+ Range(_) => Associativity::None,
603
589
}
604
590
}
605
591
0 commit comments