Skip to content

Commit c63df7c

Browse files
committed
Use non-short suggestion for parenthesised ..=
1 parent c148714 commit c63df7c

File tree

3 files changed

+19
-13
lines changed

3 files changed

+19
-13
lines changed

src/librustc_lint/builtin.rs

+17-11
Original file line numberDiff line numberDiff line change
@@ -1432,20 +1432,26 @@ impl EarlyLintPass for EllipsisInclusiveRangePatterns {
14321432
if let Some((start, end, join)) = endpoints {
14331433
let msg = "`...` range patterns are deprecated";
14341434
let suggestion = "use `..=` for an inclusive range";
1435-
let (span, replacement) = if parenthesise {
1435+
if parenthesise {
14361436
*visit_subpats = false;
1437-
(pat.span, format!("&({}..={})", expr_to_string(&start), expr_to_string(&end)))
1437+
let mut err = cx.struct_span_lint(ELLIPSIS_INCLUSIVE_RANGE_PATTERNS, pat.span, msg);
1438+
err.span_suggestion_with_applicability(
1439+
pat.span,
1440+
suggestion,
1441+
format!("&({}..={})", expr_to_string(&start), expr_to_string(&end)),
1442+
Applicability::MachineApplicable,
1443+
);
1444+
err.emit();
14381445
} else {
1439-
(join, "..=".to_owned())
1446+
let mut err = cx.struct_span_lint(ELLIPSIS_INCLUSIVE_RANGE_PATTERNS, join, msg);
1447+
err.span_suggestion_short_with_applicability(
1448+
join,
1449+
suggestion,
1450+
"..=".to_owned(),
1451+
Applicability::MachineApplicable,
1452+
);
1453+
err.emit();
14401454
};
1441-
let mut err = cx.struct_span_lint(ELLIPSIS_INCLUSIVE_RANGE_PATTERNS, span, msg);
1442-
err.span_suggestion_short_with_applicability(
1443-
span,
1444-
suggestion,
1445-
replacement,
1446-
Applicability::MachineApplicable,
1447-
);
1448-
err.emit();
14491455
}
14501456
}
14511457
}

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

+1-1
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

+1-1
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)