Skip to content

Commit 3d499ce

Browse files
committed
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 rust-lang#123079.
1 parent 399fa2f commit 3d499ce

6 files changed

+49
-1
lines changed

compiler/rustc_parse/src/lexer/mod.rs

+3
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,9 @@ impl<'psess, 'src> StringReader<'psess, 'src> {
138138
if let rustc_lexer::TokenKind::Semi
139139
| rustc_lexer::TokenKind::LineComment { .. }
140140
| rustc_lexer::TokenKind::BlockComment { .. }
141+
| rustc_lexer::TokenKind::OpenParen
142+
| rustc_lexer::TokenKind::OpenBrace
143+
| rustc_lexer::TokenKind::OpenBracket
141144
| rustc_lexer::TokenKind::CloseParen
142145
| rustc_lexer::TokenKind::CloseBrace
143146
| rustc_lexer::TokenKind::CloseBracket = token.kind
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
//@ edition:2021
2+
macro_rules! a {
3+
( ) => {
4+
impl<'b> c for d {
5+
e::<f'g> //~ ERROR prefix `f` is unknown
6+
}
7+
};
8+
}
9+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error: prefix `f` is unknown
2+
--> $DIR/dont-ice-on-invalid-lifetime-in-macro-definition.rs:5:17
3+
|
4+
LL | e::<f'g>
5+
| ^ unknown prefix
6+
|
7+
= note: prefixed identifiers and literals are reserved since Rust 2021
8+
help: consider inserting whitespace here
9+
|
10+
LL | e::<f 'g>
11+
| +
12+
13+
error: aborting due to 1 previous error
14+

tests/ui/lexer/lex-bad-str-literal-as-char-3.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
//@[rust2021] edition:2021
44
fn main() {
55
println!('hello world');
6-
//[rust2015,rust2018,rust2021]~^ ERROR unterminated character literal
6+
//~^ ERROR unterminated character literal
77
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
//@edition:2021
2+
macro_rules! foo {
3+
() => {
4+
println!('hello world');
5+
//~^ ERROR unterminated character literal
6+
}
7+
}
8+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error[E0762]: unterminated character literal
2+
--> $DIR/lex-bad-str-literal-as-char-4.rs:4:30
3+
|
4+
LL | println!('hello world');
5+
| ^^^
6+
|
7+
help: if you meant to write a string literal, use double quotes
8+
|
9+
LL | println!("hello world");
10+
| ~ ~
11+
12+
error: aborting due to 1 previous error
13+
14+
For more information about this error, try `rustc --explain E0762`.

0 commit comments

Comments
 (0)