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

Commit

Permalink
Reject byte literal and byte string literal inside paste
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Mar 27, 2022
1 parent 2f42c5b commit 28d2b03
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 5 deletions.
6 changes: 5 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,11 @@ fn parse_bracket_as_segments(input: TokenStream, scope: Span) -> Result<Vec<Segm

for segment in &mut segments {
if let Segment::String(string) = segment {
if string.value.contains(&['#', '\\', '.', '+'][..]) {
if string.value.contains(&['#', '\\', '.', '+'][..])
|| string.value.starts_with("b'")
|| string.value.starts_with("b\"")
|| string.value.starts_with("br\"")
{
return Err(Error::new(string.span, "unsupported literal"));
}
string.value = string
Expand Down
16 changes: 15 additions & 1 deletion tests/ui/unsupported-literal.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,21 @@
use paste::paste;

paste! {
fn [<1e+100>]() {}
fn [<x 1e+100 z>]() {}
}

paste! {
// `xyz` is not correct. `xbyz` is certainly not correct. Maybe `x121z`
// would be justifiable but for now don't accept this.
fn [<x b'y' z>]() {}
}

paste! {
fn [<x b"y" z>]() {}
}

paste! {
fn [<x br"y" z>]() {}
}

fn main() {}
24 changes: 21 additions & 3 deletions tests/ui/unsupported-literal.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
error: unsupported literal
--> tests/ui/unsupported-literal.rs:4:10
--> tests/ui/unsupported-literal.rs:4:12
|
4 | fn [<1e+100>]() {}
| ^^^^^^
4 | fn [<x 1e+100 z>]() {}
| ^^^^^^

error: unsupported literal
--> tests/ui/unsupported-literal.rs:10:12
|
10 | fn [<x b'y' z>]() {}
| ^^^^

error: unsupported literal
--> tests/ui/unsupported-literal.rs:14:12
|
14 | fn [<x b"y" z>]() {}
| ^^^^

error: unsupported literal
--> tests/ui/unsupported-literal.rs:18:12
|
18 | fn [<x br"y" z>]() {}
| ^^^^^

0 comments on commit 28d2b03

Please sign in to comment.