Avoid ICE in macro's diagnostics
This commit is contained in:
parent
343432a74d
commit
cef7764a76
5 changed files with 27 additions and 22 deletions
|
@ -1638,26 +1638,32 @@ impl<'a> Parser<'a> {
|
||||||
.span_to_snippet(self.prev_span)
|
.span_to_snippet(self.prev_span)
|
||||||
.map(|s| s.ends_with(")") || s.ends_with("]"))
|
.map(|s| s.ends_with(")") || s.ends_with("]"))
|
||||||
.unwrap_or(false);
|
.unwrap_or(false);
|
||||||
let right_brace_span = if has_close_delim {
|
|
||||||
// it's safe to peel off one character only when it has the close delim
|
|
||||||
self.prev_span.with_lo(self.prev_span.hi() - BytePos(1))
|
|
||||||
} else {
|
|
||||||
self.prev_span.shrink_to_hi()
|
|
||||||
};
|
|
||||||
|
|
||||||
self.struct_span_err(
|
let mut err = self.struct_span_err(
|
||||||
self.prev_span,
|
self.prev_span,
|
||||||
"macros that expand to items must be delimited with braces or followed by a semicolon",
|
"macros that expand to items must be delimited with braces or followed by a semicolon",
|
||||||
)
|
);
|
||||||
.multipart_suggestion(
|
|
||||||
"change the delimiters to curly braces",
|
// To avoid ICE, we shouldn't emit actual suggestions when it hasn't closing delims
|
||||||
vec![
|
if has_close_delim {
|
||||||
(self.prev_span.with_hi(self.prev_span.lo() + BytePos(1)), "{".to_string()),
|
err.multipart_suggestion(
|
||||||
(right_brace_span, '}'.to_string()),
|
"change the delimiters to curly braces",
|
||||||
],
|
vec![
|
||||||
Applicability::MaybeIncorrect,
|
(self.prev_span.with_hi(self.prev_span.lo() + BytePos(1)), '{'.to_string()),
|
||||||
)
|
(self.prev_span.with_lo(self.prev_span.hi() - BytePos(1)), '}'.to_string()),
|
||||||
.span_suggestion(
|
],
|
||||||
|
Applicability::MaybeIncorrect,
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
err.span_suggestion(
|
||||||
|
self.prev_span,
|
||||||
|
"change the delimiters to curly braces",
|
||||||
|
" { /* items */ }".to_string(),
|
||||||
|
Applicability::MaybeIncorrect,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
err.span_suggestion(
|
||||||
self.prev_span.shrink_to_hi(),
|
self.prev_span.shrink_to_hi(),
|
||||||
"add a semicolon",
|
"add a semicolon",
|
||||||
';'.to_string(),
|
';'.to_string(),
|
||||||
|
|
|
@ -16,9 +16,8 @@ LL | | Ϥ,
|
||||||
|
|
|
|
||||||
help: change the delimiters to curly braces
|
help: change the delimiters to curly braces
|
||||||
|
|
|
|
||||||
LL | y!{
|
LL | y! { /* items */ }
|
||||||
LL | Ϥ}
|
| ^^^^^^^^^^^^^^^
|
||||||
|
|
|
||||||
help: add a semicolon
|
help: add a semicolon
|
||||||
|
|
|
|
||||||
LL | Ϥ,;
|
LL | Ϥ,;
|
||||||
|
|
BIN
src/test/ui/parser/issue-68629.rs
Normal file
BIN
src/test/ui/parser/issue-68629.rs
Normal file
Binary file not shown.
BIN
src/test/ui/parser/issue-68629.stderr
Normal file
BIN
src/test/ui/parser/issue-68629.stderr
Normal file
Binary file not shown.
|
@ -14,8 +14,8 @@ LL | macro_rules! abc(ؼ
|
||||||
|
|
|
|
||||||
help: change the delimiters to curly braces
|
help: change the delimiters to curly braces
|
||||||
|
|
|
|
||||||
LL | macro_rules! abc{ؼ}
|
LL | macro_rules! abc { /* items */ }
|
||||||
| ^ ^
|
| ^^^^^^^^^^^^^^^
|
||||||
help: add a semicolon
|
help: add a semicolon
|
||||||
|
|
|
|
||||||
LL | macro_rules! abc(ؼ;
|
LL | macro_rules! abc(ؼ;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue