Use non-short suggestion for parenthesised ..=
This commit is contained in:
parent
c148714549
commit
c63df7c64f
3 changed files with 19 additions and 13 deletions
|
@ -1432,20 +1432,26 @@ impl EarlyLintPass for EllipsisInclusiveRangePatterns {
|
||||||
if let Some((start, end, join)) = endpoints {
|
if let Some((start, end, join)) = endpoints {
|
||||||
let msg = "`...` range patterns are deprecated";
|
let msg = "`...` range patterns are deprecated";
|
||||||
let suggestion = "use `..=` for an inclusive range";
|
let suggestion = "use `..=` for an inclusive range";
|
||||||
let (span, replacement) = if parenthesise {
|
if parenthesise {
|
||||||
*visit_subpats = false;
|
*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 {
|
} 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();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,5 +14,5 @@ warning: `...` range patterns are deprecated
|
||||||
--> $DIR/inclusive-range-pattern-syntax.rs:25:9
|
--> $DIR/inclusive-range-pattern-syntax.rs:25:9
|
||||||
|
|
|
|
||||||
LL | &1...2 => {}
|
LL | &1...2 => {}
|
||||||
| ^^^^^^ help: use `..=` for an inclusive range
|
| ^^^^^^ help: use `..=` for an inclusive range: `&(1..=2)`
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,7 @@ warning: `...` range patterns are deprecated
|
||||||
--> $DIR/range-inclusive-pattern-precedence.rs:24:9
|
--> $DIR/range-inclusive-pattern-precedence.rs:24:9
|
||||||
|
|
|
|
||||||
LL | &0...9 => {}
|
LL | &0...9 => {}
|
||||||
| ^^^^^^ help: use `..=` for an inclusive range
|
| ^^^^^^ help: use `..=` for an inclusive range: `&(0..=9)`
|
||||||
|
|
|
|
||||||
note: lint level defined here
|
note: lint level defined here
|
||||||
--> $DIR/range-inclusive-pattern-precedence.rs:19:9
|
--> $DIR/range-inclusive-pattern-precedence.rs:19:9
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue