Skip to content

Commit 9ab3b0f

Browse files
varkorpietroalbini
authored andcommitted
Use non-short suggestion for parenthesised ..=
1 parent 0a26e79 commit 9ab3b0f

File tree

3 files changed

+19
-13
lines changed

3 files changed

+19
-13
lines changed

src/librustc_lint/builtin.rs

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1502,20 +1502,26 @@ impl EarlyLintPass for EllipsisInclusiveRangePatterns {
15021502
if let Some((start, end, join)) = endpoints {
15031503
let msg = "`...` range patterns are deprecated";
15041504
let suggestion = "use `..=` for an inclusive range";
1505-
let (span, replacement) = if parenthesise {
1505+
if parenthesise {
15061506
*visit_subpats = false;
1507-
(pat.span, format!("&({}..={})", expr_to_string(&start), expr_to_string(&end)))
1507+
let mut err = cx.struct_span_lint(ELLIPSIS_INCLUSIVE_RANGE_PATTERNS, pat.span, msg);
1508+
err.span_suggestion_with_applicability(
1509+
pat.span,
1510+
suggestion,
1511+
format!("&({}..={})", expr_to_string(&start), expr_to_string(&end)),
1512+
Applicability::MachineApplicable,
1513+
);
1514+
err.emit();
15081515
} else {
1509-
(join, "..=".to_owned())
1516+
let mut err = cx.struct_span_lint(ELLIPSIS_INCLUSIVE_RANGE_PATTERNS, join, msg);
1517+
err.span_suggestion_short_with_applicability(
1518+
join,
1519+
suggestion,
1520+
"..=".to_owned(),
1521+
Applicability::MachineApplicable,
1522+
);
1523+
err.emit();
15101524
};
1511-
let mut err = cx.struct_span_lint(ELLIPSIS_INCLUSIVE_RANGE_PATTERNS, span, msg);
1512-
err.span_suggestion_short_with_applicability(
1513-
span,
1514-
suggestion,
1515-
replacement,
1516-
Applicability::MachineApplicable,
1517-
);
1518-
err.emit();
15191525
}
15201526
}
15211527
}

src/test/ui/lint/inclusive-range-pattern-syntax.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@ warning: `...` range patterns are deprecated
1414
--> $DIR/inclusive-range-pattern-syntax.rs:25:9
1515
|
1616
LL | &1...2 => {}
17-
| ^^^^^^ help: use `..=` for an inclusive range
17+
| ^^^^^^ help: use `..=` for an inclusive range: `&(1..=2)`
1818

src/test/ui/range/range-inclusive-pattern-precedence.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ warning: `...` range patterns are deprecated
1414
--> $DIR/range-inclusive-pattern-precedence.rs:24:9
1515
|
1616
LL | &0...9 => {}
17-
| ^^^^^^ help: use `..=` for an inclusive range
17+
| ^^^^^^ help: use `..=` for an inclusive range: `&(0..=9)`
1818
|
1919
note: lint level defined here
2020
--> $DIR/range-inclusive-pattern-precedence.rs:19:9

0 commit comments

Comments
 (0)