Fix invalid silencing of parsing error
Given ```rust macro_rules! a { ( ) => { impl<'b> c for d { e::<f'g> } }; } ``` ensure an error is emitted. Fix #123079.
This commit is contained in:
parent
e78913baef
commit
e572a194bf
7 changed files with 80 additions and 15 deletions
|
@ -698,7 +698,6 @@ impl<'psess, 'src> StringReader<'psess, 'src> {
|
||||||
let expn_data = prefix_span.ctxt().outer_expn_data();
|
let expn_data = prefix_span.ctxt().outer_expn_data();
|
||||||
|
|
||||||
if expn_data.edition >= Edition::Edition2021 {
|
if expn_data.edition >= Edition::Edition2021 {
|
||||||
let mut silence = false;
|
|
||||||
// In Rust 2021, this is a hard error.
|
// In Rust 2021, this is a hard error.
|
||||||
let sugg = if prefix == "rb" {
|
let sugg = if prefix == "rb" {
|
||||||
Some(errors::UnknownPrefixSugg::UseBr(prefix_span))
|
Some(errors::UnknownPrefixSugg::UseBr(prefix_span))
|
||||||
|
@ -706,25 +705,20 @@ impl<'psess, 'src> StringReader<'psess, 'src> {
|
||||||
if self.cursor.first() == '\''
|
if self.cursor.first() == '\''
|
||||||
&& let Some(start) = self.last_lifetime
|
&& let Some(start) = self.last_lifetime
|
||||||
&& self.cursor.third() != '\''
|
&& self.cursor.third() != '\''
|
||||||
|
&& let end = self.mk_sp(self.pos, self.pos + BytePos(1))
|
||||||
|
&& !self.psess.source_map().is_multiline(start.until(end))
|
||||||
{
|
{
|
||||||
// An "unclosed `char`" error will be emitted already, silence redundant error.
|
// FIXME: An "unclosed `char`" error will be emitted already in some cases,
|
||||||
silence = true;
|
// but it's hard to silence this error while not also silencing important cases
|
||||||
Some(errors::UnknownPrefixSugg::MeantStr {
|
// too. We should use the error stashing machinery instead.
|
||||||
start,
|
Some(errors::UnknownPrefixSugg::MeantStr { start, end })
|
||||||
end: self.mk_sp(self.pos, self.pos + BytePos(1)),
|
|
||||||
})
|
|
||||||
} else {
|
} else {
|
||||||
Some(errors::UnknownPrefixSugg::Whitespace(prefix_span.shrink_to_hi()))
|
Some(errors::UnknownPrefixSugg::Whitespace(prefix_span.shrink_to_hi()))
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
};
|
};
|
||||||
let err = errors::UnknownPrefix { span: prefix_span, prefix, sugg };
|
self.dcx().emit_err(errors::UnknownPrefix { span: prefix_span, prefix, sugg });
|
||||||
if silence {
|
|
||||||
self.dcx().create_err(err).delay_as_bug();
|
|
||||||
} else {
|
|
||||||
self.dcx().emit_err(err);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
// Before Rust 2021, only emit a lint for migration.
|
// Before Rust 2021, only emit a lint for migration.
|
||||||
self.psess.buffer_lint_with_diagnostic(
|
self.psess.buffer_lint_with_diagnostic(
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
//@ edition:2021
|
||||||
|
macro_rules! a {
|
||||||
|
( ) => {
|
||||||
|
impl<'b> c for d {
|
||||||
|
e::<f'g> //~ ERROR prefix `f` is unknown
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
fn main() {}
|
|
@ -0,0 +1,14 @@
|
||||||
|
error: prefix `f` is unknown
|
||||||
|
--> $DIR/dont-ice-on-invalid-lifetime-in-macro-definition.rs:5:17
|
||||||
|
|
|
||||||
|
LL | e::<f'g>
|
||||||
|
| ^ unknown prefix
|
||||||
|
|
|
||||||
|
= note: prefixed identifiers and literals are reserved since Rust 2021
|
||||||
|
help: consider inserting whitespace here
|
||||||
|
|
|
||||||
|
LL | e::<f 'g>
|
||||||
|
| +
|
||||||
|
|
||||||
|
error: aborting due to 1 previous error
|
||||||
|
|
|
@ -3,5 +3,6 @@
|
||||||
//@[rust2021] edition:2021
|
//@[rust2021] edition:2021
|
||||||
fn main() {
|
fn main() {
|
||||||
println!('hello world');
|
println!('hello world');
|
||||||
//[rust2015,rust2018,rust2021]~^ ERROR unterminated character literal
|
//~^ ERROR unterminated character literal
|
||||||
|
//[rust2021]~| ERROR prefix `world` is unknown
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,15 @@
|
||||||
|
error: prefix `world` is unknown
|
||||||
|
--> $DIR/lex-bad-str-literal-as-char-3.rs:5:21
|
||||||
|
|
|
||||||
|
LL | println!('hello world');
|
||||||
|
| ^^^^^ unknown prefix
|
||||||
|
|
|
||||||
|
= note: prefixed identifiers and literals are reserved since Rust 2021
|
||||||
|
help: if you meant to write a string literal, use double quotes
|
||||||
|
|
|
||||||
|
LL | println!("hello world");
|
||||||
|
| ~ ~
|
||||||
|
|
||||||
error[E0762]: unterminated character literal
|
error[E0762]: unterminated character literal
|
||||||
--> $DIR/lex-bad-str-literal-as-char-3.rs:5:26
|
--> $DIR/lex-bad-str-literal-as-char-3.rs:5:26
|
||||||
|
|
|
|
||||||
|
@ -9,6 +21,6 @@ help: if you meant to write a string literal, use double quotes
|
||||||
LL | println!("hello world");
|
LL | println!("hello world");
|
||||||
| ~ ~
|
| ~ ~
|
||||||
|
|
||||||
error: aborting due to 1 previous error
|
error: aborting due to 2 previous errors
|
||||||
|
|
||||||
For more information about this error, try `rustc --explain E0762`.
|
For more information about this error, try `rustc --explain E0762`.
|
||||||
|
|
9
tests/ui/lexer/lex-bad-str-literal-as-char-4.rs
Normal file
9
tests/ui/lexer/lex-bad-str-literal-as-char-4.rs
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
//@edition:2021
|
||||||
|
macro_rules! foo {
|
||||||
|
() => {
|
||||||
|
println!('hello world');
|
||||||
|
//~^ ERROR unterminated character literal
|
||||||
|
//~| ERROR prefix `world` is unknown
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fn main() {}
|
26
tests/ui/lexer/lex-bad-str-literal-as-char-4.stderr
Normal file
26
tests/ui/lexer/lex-bad-str-literal-as-char-4.stderr
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
error: prefix `world` is unknown
|
||||||
|
--> $DIR/lex-bad-str-literal-as-char-4.rs:4:25
|
||||||
|
|
|
||||||
|
LL | println!('hello world');
|
||||||
|
| ^^^^^ unknown prefix
|
||||||
|
|
|
||||||
|
= note: prefixed identifiers and literals are reserved since Rust 2021
|
||||||
|
help: if you meant to write a string literal, use double quotes
|
||||||
|
|
|
||||||
|
LL | println!("hello world");
|
||||||
|
| ~ ~
|
||||||
|
|
||||||
|
error[E0762]: unterminated character literal
|
||||||
|
--> $DIR/lex-bad-str-literal-as-char-4.rs:4:30
|
||||||
|
|
|
||||||
|
LL | println!('hello world');
|
||||||
|
| ^^^
|
||||||
|
|
|
||||||
|
help: if you meant to write a string literal, use double quotes
|
||||||
|
|
|
||||||
|
LL | println!("hello world");
|
||||||
|
| ~ ~
|
||||||
|
|
||||||
|
error: aborting due to 2 previous errors
|
||||||
|
|
||||||
|
For more information about this error, try `rustc --explain E0762`.
|
Loading…
Add table
Add a link
Reference in a new issue