Skip to content

Commit

Permalink
Do not allow beginning of string token as ident
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Sep 26, 2020
1 parent 5d5fdb3 commit 7c3b8ed
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,17 @@ fn leaf_token(input: Cursor) -> PResult<TokenTree> {
}

fn ident(input: Cursor) -> PResult<crate::Ident> {
if ["r\"", "r#\"", "r##", "b\"", "b\'", "br\"", "br#"]
.iter()
.any(|prefix| input.starts_with(prefix))
{
Err(LexError)
} else {
ident_any(input)
}
}

fn ident_any(input: Cursor) -> PResult<crate::Ident> {
let raw = input.starts_with("r#");
let rest = input.advance((raw as usize) << 1);

Expand Down Expand Up @@ -716,7 +727,7 @@ fn digits(mut input: Cursor) -> Result<Cursor, LexError> {
fn op(input: Cursor) -> PResult<Punct> {
match op_char(input) {
Ok((rest, '\'')) => {
if ident(rest)?.0.starts_with("'") {
if ident_any(rest)?.0.starts_with("'") {
Err(LexError)
} else {
Ok((rest, Punct::new('\'', Spacing::Joint)))
Expand Down
1 change: 1 addition & 0 deletions tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ fn fail() {
fail("r\"\r\""); // bare carriage return in raw string
fail("\"\\\r \""); // backslash carriage return
fail("'aa'aa");
fail("br##\"\"#");
}

#[cfg(span_locations)]
Expand Down

0 comments on commit 7c3b8ed

Please sign in to comment.