Skip to content

Commit

Permalink
Use non-short suggestion for parenthesised ..=
Browse files Browse the repository at this point in the history
  • Loading branch information
varkor authored and pietroalbini committed Nov 19, 2018
1 parent 0a26e79 commit 9ab3b0f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 13 deletions.
28 changes: 17 additions & 11 deletions src/librustc_lint/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1502,20 +1502,26 @@ impl EarlyLintPass for EllipsisInclusiveRangePatterns {
if let Some((start, end, join)) = endpoints {
let msg = "`...` range patterns are deprecated";
let suggestion = "use `..=` for an inclusive range";
let (span, replacement) = if parenthesise {
if parenthesise {
*visit_subpats = false;
(pat.span, format!("&({}..={})", expr_to_string(&start), expr_to_string(&end)))
let mut err = cx.struct_span_lint(ELLIPSIS_INCLUSIVE_RANGE_PATTERNS, pat.span, msg);
err.span_suggestion_with_applicability(
pat.span,
suggestion,
format!("&({}..={})", expr_to_string(&start), expr_to_string(&end)),
Applicability::MachineApplicable,
);
err.emit();
} else {
(join, "..=".to_owned())
let mut err = cx.struct_span_lint(ELLIPSIS_INCLUSIVE_RANGE_PATTERNS, join, msg);
err.span_suggestion_short_with_applicability(
join,
suggestion,
"..=".to_owned(),
Applicability::MachineApplicable,
);
err.emit();
};
let mut err = cx.struct_span_lint(ELLIPSIS_INCLUSIVE_RANGE_PATTERNS, span, msg);
err.span_suggestion_short_with_applicability(
span,
suggestion,
replacement,
Applicability::MachineApplicable,
);
err.emit();
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/lint/inclusive-range-pattern-syntax.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ warning: `...` range patterns are deprecated
--> $DIR/inclusive-range-pattern-syntax.rs:25:9
|
LL | &1...2 => {}
| ^^^^^^ help: use `..=` for an inclusive range
| ^^^^^^ help: use `..=` for an inclusive range: `&(1..=2)`

Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ warning: `...` range patterns are deprecated
--> $DIR/range-inclusive-pattern-precedence.rs:24:9
|
LL | &0...9 => {}
| ^^^^^^ help: use `..=` for an inclusive range
| ^^^^^^ help: use `..=` for an inclusive range: `&(0..=9)`
|
note: lint level defined here
--> $DIR/range-inclusive-pattern-precedence.rs:19:9
Expand Down

0 comments on commit 9ab3b0f

Please sign in to comment.