Skip to content

Commit

Permalink
Fix invalid silencing of parsing error
Browse files Browse the repository at this point in the history
Given

```rust
macro_rules! a {
    ( ) => {
        impl<'b> c for d {
            e::<f'g>
        }
    };
}
```

ensure an error is emitted.

Fix rust-lang#123079.
  • Loading branch information
estebank committed Mar 30, 2024
1 parent 399fa2f commit 3d499ce
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 1 deletion.
3 changes: 3 additions & 0 deletions compiler/rustc_parse/src/lexer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@ impl<'psess, 'src> StringReader<'psess, 'src> {
if let rustc_lexer::TokenKind::Semi
| rustc_lexer::TokenKind::LineComment { .. }
| rustc_lexer::TokenKind::BlockComment { .. }
| rustc_lexer::TokenKind::OpenParen
| rustc_lexer::TokenKind::OpenBrace
| rustc_lexer::TokenKind::OpenBracket
| rustc_lexer::TokenKind::CloseParen
| rustc_lexer::TokenKind::CloseBrace
| rustc_lexer::TokenKind::CloseBracket = token.kind
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//@ edition:2021
macro_rules! a {
( ) => {
impl<'b> c for d {
e::<f'g> //~ ERROR prefix `f` is unknown
}
};
}
fn main() {}
Original file line number Diff line number Diff line change
@@ -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

2 changes: 1 addition & 1 deletion tests/ui/lexer/lex-bad-str-literal-as-char-3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
//@[rust2021] edition:2021
fn main() {
println!('hello world');
//[rust2015,rust2018,rust2021]~^ ERROR unterminated character literal
//~^ ERROR unterminated character literal
}
8 changes: 8 additions & 0 deletions tests/ui/lexer/lex-bad-str-literal-as-char-4.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//@edition:2021
macro_rules! foo {
() => {
println!('hello world');
//~^ ERROR unterminated character literal
}
}
fn main() {}
14 changes: 14 additions & 0 deletions tests/ui/lexer/lex-bad-str-literal-as-char-4.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
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 1 previous error

For more information about this error, try `rustc --explain E0762`.

0 comments on commit 3d499ce

Please sign in to comment.