Improve diagnostic for missing space in range pattern
This commit is contained in:
parent
a9985cf172
commit
4ab75de934
6 changed files with 24 additions and 21 deletions
|
@ -203,8 +203,9 @@ parse_inclusive_range_extra_equals = unexpected `=` after inclusive range
|
||||||
.suggestion_remove_eq = use `..=` instead
|
.suggestion_remove_eq = use `..=` instead
|
||||||
.note = inclusive ranges end with a single equals sign (`..=`)
|
.note = inclusive ranges end with a single equals sign (`..=`)
|
||||||
|
|
||||||
parse_inclusive_range_match_arrow = unexpected `=>` after open range
|
parse_inclusive_range_match_arrow = unexpected `>` after inclusive range
|
||||||
.suggestion_add_space = add a space between the pattern and `=>`
|
.label = this is parsed as an inclusive range `..=`
|
||||||
|
.suggestion = add a space between the pattern and `=>`
|
||||||
|
|
||||||
parse_inclusive_range_no_end = inclusive range with no end
|
parse_inclusive_range_no_end = inclusive range with no end
|
||||||
.suggestion_open_range = use `..` instead
|
.suggestion_open_range = use `..` instead
|
||||||
|
|
|
@ -668,13 +668,10 @@ pub(crate) struct InclusiveRangeExtraEquals {
|
||||||
#[diag(parse_inclusive_range_match_arrow)]
|
#[diag(parse_inclusive_range_match_arrow)]
|
||||||
pub(crate) struct InclusiveRangeMatchArrow {
|
pub(crate) struct InclusiveRangeMatchArrow {
|
||||||
#[primary_span]
|
#[primary_span]
|
||||||
|
pub arrow: Span,
|
||||||
|
#[label]
|
||||||
pub span: Span,
|
pub span: Span,
|
||||||
#[suggestion(
|
#[suggestion(style = "verbose", code = " ", applicability = "machine-applicable")]
|
||||||
suggestion_add_space,
|
|
||||||
style = "verbose",
|
|
||||||
code = " ",
|
|
||||||
applicability = "machine-applicable"
|
|
||||||
)]
|
|
||||||
pub after_pat: Span,
|
pub after_pat: Span,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2717,6 +2717,14 @@ impl<'a> Parser<'a> {
|
||||||
);
|
);
|
||||||
err.emit();
|
err.emit();
|
||||||
this.bump();
|
this.bump();
|
||||||
|
} else if matches!(
|
||||||
|
(&this.prev_token.kind, &this.token.kind),
|
||||||
|
(token::DotDotEq, token::Gt)
|
||||||
|
) {
|
||||||
|
// `error_inclusive_range_match_arrow` handles cases like `0..=> {}`,
|
||||||
|
// so we supress the error here
|
||||||
|
err.delay_as_bug();
|
||||||
|
this.bump();
|
||||||
} else {
|
} else {
|
||||||
return Err(err);
|
return Err(err);
|
||||||
}
|
}
|
||||||
|
|
|
@ -744,7 +744,7 @@ impl<'a> Parser<'a> {
|
||||||
}
|
}
|
||||||
token::Gt if no_space => {
|
token::Gt if no_space => {
|
||||||
let after_pat = span.with_hi(span.hi() - rustc_span::BytePos(1)).shrink_to_hi();
|
let after_pat = span.with_hi(span.hi() - rustc_span::BytePos(1)).shrink_to_hi();
|
||||||
self.sess.emit_err(InclusiveRangeMatchArrow { span, after_pat });
|
self.sess.emit_err(InclusiveRangeMatchArrow { span, arrow: tok.span, after_pat });
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
self.sess.emit_err(InclusiveRangeNoEnd { span });
|
self.sess.emit_err(InclusiveRangeNoEnd { span });
|
||||||
|
|
|
@ -2,7 +2,8 @@ fn main() {
|
||||||
let x = 42;
|
let x = 42;
|
||||||
match x {
|
match x {
|
||||||
0..=73 => {},
|
0..=73 => {},
|
||||||
74..=> {}, //~ ERROR unexpected `=>` after open range
|
74..=> {},
|
||||||
//~^ ERROR expected one of `=>`, `if`, or `|`, found `>`
|
//~^ ERROR unexpected `>` after inclusive range
|
||||||
|
//~| NOTE this is parsed as an inclusive range `..=`
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,19 +1,15 @@
|
||||||
error: unexpected `=>` after open range
|
error: unexpected `>` after inclusive range
|
||||||
--> $DIR/half-open-range-pats-inclusive-match-arrow.rs:5:11
|
--> $DIR/half-open-range-pats-inclusive-match-arrow.rs:5:14
|
||||||
|
|
|
|
||||||
LL | 74..=> {},
|
LL | 74..=> {},
|
||||||
| ^^^
|
| ---^
|
||||||
|
| |
|
||||||
|
| this is parsed as an inclusive range `..=`
|
||||||
|
|
|
|
||||||
help: add a space between the pattern and `=>`
|
help: add a space between the pattern and `=>`
|
||||||
|
|
|
|
||||||
LL | 74.. => {},
|
LL | 74.. => {},
|
||||||
| +
|
| +
|
||||||
|
|
||||||
error: expected one of `=>`, `if`, or `|`, found `>`
|
error: aborting due to previous error
|
||||||
--> $DIR/half-open-range-pats-inclusive-match-arrow.rs:5:14
|
|
||||||
|
|
|
||||||
LL | 74..=> {},
|
|
||||||
| ^ expected one of `=>`, `if`, or `|`
|
|
||||||
|
|
||||||
error: aborting due to 2 previous errors
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue