mirror of
https://github.com/rust-lang/rust.git
synced 2025-05-14 02:49:40 +00:00
fix an ICE in macro's diagnostic message
This commit is contained in:
parent
1062b698c1
commit
292ba98cb7
@ -1742,14 +1742,25 @@ impl<'a> Parser<'a> {
|
||||
}
|
||||
|
||||
fn report_invalid_macro_expansion_item(&self) {
|
||||
let has_close_delim = self.sess.source_map()
|
||||
.span_to_snippet(self.prev_span)
|
||||
.map(|s| s.ends_with(")") || s.ends_with("]"))
|
||||
.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.sess.source_map().next_point(self.prev_span)
|
||||
};
|
||||
|
||||
self.struct_span_err(
|
||||
self.prev_span,
|
||||
"macros that expand to items must be delimited with braces or followed by a semicolon",
|
||||
).multipart_suggestion(
|
||||
"change the delimiters to curly braces",
|
||||
vec![
|
||||
(self.prev_span.with_hi(self.prev_span.lo() + BytePos(1)), String::from(" {")),
|
||||
(self.prev_span.with_lo(self.prev_span.hi() - BytePos(1)), '}'.to_string()),
|
||||
(self.prev_span.with_hi(self.prev_span.lo() + BytePos(1)), "{".to_string()),
|
||||
(right_brace_span, '}'.to_string()),
|
||||
],
|
||||
Applicability::MaybeIncorrect,
|
||||
).span_suggestion(
|
||||
|
@ -6,8 +6,8 @@ LL | macro_rules! foo()
|
||||
|
|
||||
help: change the delimiters to curly braces
|
||||
|
|
||||
LL | macro_rules! foo {}
|
||||
| ^^
|
||||
LL | macro_rules! foo{}
|
||||
| ^^
|
||||
help: add a semicolon
|
||||
|
|
||||
LL | macro_rules! foo();
|
||||
@ -26,7 +26,7 @@ LL | | )
|
||||
|
|
||||
help: change the delimiters to curly braces
|
||||
|
|
||||
LL | bar! {
|
||||
LL | bar!{
|
||||
LL | blah
|
||||
LL | blah
|
||||
LL | blah
|
||||
|
3
src/test/ui/parser/mbe_missing_right_paren.rs
Normal file
3
src/test/ui/parser/mbe_missing_right_paren.rs
Normal file
@ -0,0 +1,3 @@
|
||||
// ignore-tidy-trailing-newlines
|
||||
// error-pattern: aborting due to 3 previous errors
|
||||
macro_rules! abc(ؼ
|
31
src/test/ui/parser/mbe_missing_right_paren.stderr
Normal file
31
src/test/ui/parser/mbe_missing_right_paren.stderr
Normal file
@ -0,0 +1,31 @@
|
||||
error: this file contains an un-closed delimiter
|
||||
--> $DIR/mbe_missing_right_paren.rs:3:19
|
||||
|
|
||||
LL | macro_rules! abc(ؼ
|
||||
| - ^
|
||||
| |
|
||||
| un-closed delimiter
|
||||
|
||||
error: macros that expand to items must be delimited with braces or followed by a semicolon
|
||||
--> $DIR/mbe_missing_right_paren.rs:3:17
|
||||
|
|
||||
LL | macro_rules! abc(ؼ
|
||||
| ^^
|
||||
|
|
||||
help: change the delimiters to curly braces
|
||||
|
|
||||
LL | macro_rules! abc{ؼ}
|
||||
| ^ ^
|
||||
help: add a semicolon
|
||||
|
|
||||
LL | macro_rules! abc(ؼ;
|
||||
| ^
|
||||
|
||||
error: unexpected end of macro invocation
|
||||
--> $DIR/mbe_missing_right_paren.rs:3:1
|
||||
|
|
||||
LL | macro_rules! abc(ؼ
|
||||
| ^^^^^^^^^^^^^^^^^^ missing tokens in macro arguments
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
Loading…
Reference in New Issue
Block a user