Skip to content

Commit 7c3b8ed

Browse files
committed
Do not allow beginning of string token as ident
1 parent 5d5fdb3 commit 7c3b8ed

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/parse.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,17 @@ fn leaf_token(input: Cursor) -> PResult<TokenTree> {
238238
}
239239

240240
fn ident(input: Cursor) -> PResult<crate::Ident> {
241+
if ["r\"", "r#\"", "r##", "b\"", "b\'", "br\"", "br#"]
242+
.iter()
243+
.any(|prefix| input.starts_with(prefix))
244+
{
245+
Err(LexError)
246+
} else {
247+
ident_any(input)
248+
}
249+
}
250+
251+
fn ident_any(input: Cursor) -> PResult<crate::Ident> {
241252
let raw = input.starts_with("r#");
242253
let rest = input.advance((raw as usize) << 1);
243254

@@ -716,7 +727,7 @@ fn digits(mut input: Cursor) -> Result<Cursor, LexError> {
716727
fn op(input: Cursor) -> PResult<Punct> {
717728
match op_char(input) {
718729
Ok((rest, '\'')) => {
719-
if ident(rest)?.0.starts_with("'") {
730+
if ident_any(rest)?.0.starts_with("'") {
720731
Err(LexError)
721732
} else {
722733
Ok((rest, Punct::new('\'', Spacing::Joint)))

tests/test.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ fn fail() {
199199
fail("r\"\r\""); // bare carriage return in raw string
200200
fail("\"\\\r \""); // backslash carriage return
201201
fail("'aa'aa");
202+
fail("br##\"\"#");
202203
}
203204

204205
#[cfg(span_locations)]

0 commit comments

Comments
 (0)