Skip to content
This repository has been archived by the owner on Oct 6, 2024. It is now read-only.

Commit

Permalink
Merge pull request #76 from dtolnay/quotes
Browse files Browse the repository at this point in the history
Strip only surrounding quotes of a literal
  • Loading branch information
dtolnay authored Mar 27, 2022
2 parents 657991e + d82aaea commit d563004
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,11 +371,15 @@ fn parse_bracket_as_segments(input: TokenStream, scope: Span) -> Result<Vec<Segm
{
return Err(Error::new(string.span, "unsupported literal"));
}
string.value = string
.value
.replace('"', "")
.replace('\'', "")
.replace('-', "_");
let mut range = 0..string.value.len();
if string.value.starts_with("r\"") {
range.start += 2;
range.end -= 1;
} else if string.value.starts_with(&['"', '\''][..]) {
range.start += 1;
range.end -= 1;
}
string.value = string.value[range].replace('-', "_");
}
}

Expand Down
8 changes: 8 additions & 0 deletions tests/ui/invalid-ident.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,12 @@ paste! {
fn [<0 f>]() {}
}

paste! {
fn [<f '"'>]() {}
}

paste! {
fn [<f "'">]() {}
}

fn main() {}
12 changes: 12 additions & 0 deletions tests/ui/invalid-ident.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,15 @@ error: `"0f"` is not a valid identifier
|
4 | fn [<0 f>]() {}
| ^^^^^^^

error: `"f\""` is not a valid identifier
--> tests/ui/invalid-ident.rs:8:8
|
8 | fn [<f '"'>]() {}
| ^^^^^^^^^

error: `"f'"` is not a valid identifier
--> tests/ui/invalid-ident.rs:12:8
|
12 | fn [<f "'">]() {}
| ^^^^^^^^^

0 comments on commit d563004

Please sign in to comment.