mirror of
https://github.com/pezkuwichain/serde.git
synced 2026-06-15 21:21:01 +00:00
Merge pull request #2499 from dtolnay/strsuffix
Reject suffixed string literals inside serde attrs
This commit is contained in:
@@ -24,7 +24,7 @@ proc-macro = true
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
proc-macro2 = "1.0"
|
proc-macro2 = "1.0"
|
||||||
quote = "1.0"
|
quote = "1.0"
|
||||||
syn = "2.0.24"
|
syn = "2.0.25"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
serde = { version = "1.0", path = "../serde" }
|
serde = { version = "1.0", path = "../serde" }
|
||||||
|
|||||||
@@ -1418,6 +1418,13 @@ fn get_lit_str2(
|
|||||||
..
|
..
|
||||||
}) = value
|
}) = value
|
||||||
{
|
{
|
||||||
|
let suffix = lit.suffix();
|
||||||
|
if !suffix.is_empty() {
|
||||||
|
cx.error_spanned_by(
|
||||||
|
lit,
|
||||||
|
format!("unexpected suffix `{}` on string literal", suffix),
|
||||||
|
);
|
||||||
|
}
|
||||||
Ok(Some(lit.clone()))
|
Ok(Some(lit.clone()))
|
||||||
} else {
|
} else {
|
||||||
cx.error_spanned_by(
|
cx.error_spanned_by(
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ path = "lib.rs"
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
proc-macro2 = "1.0"
|
proc-macro2 = "1.0"
|
||||||
quote = "1.0"
|
quote = "1.0"
|
||||||
syn = { version = "2.0.24", default-features = false, features = ["clone-impls", "derive", "parsing", "printing"] }
|
syn = { version = "2.0.25", default-features = false, features = ["clone-impls", "derive", "parsing", "printing"] }
|
||||||
|
|
||||||
[package.metadata.docs.rs]
|
[package.metadata.docs.rs]
|
||||||
targets = ["x86_64-unknown-linux-gnu"]
|
targets = ["x86_64-unknown-linux-gnu"]
|
||||||
|
|||||||
@@ -0,0 +1,10 @@
|
|||||||
|
use serde::Serialize;
|
||||||
|
|
||||||
|
#[derive(Serialize)]
|
||||||
|
#[serde(bound = ""huh)]
|
||||||
|
pub struct Struct {
|
||||||
|
#[serde(rename = ""what)]
|
||||||
|
pub field: i32,
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
error: unexpected suffix `huh` on string literal
|
||||||
|
--> tests/ui/malformed/str_suffix.rs:4:17
|
||||||
|
|
|
||||||
|
4 | #[serde(bound = ""huh)]
|
||||||
|
| ^^^^^
|
||||||
|
|
||||||
|
error: unexpected suffix `what` on string literal
|
||||||
|
--> tests/ui/malformed/str_suffix.rs:6:22
|
||||||
|
|
|
||||||
|
6 | #[serde(rename = ""what)]
|
||||||
|
| ^^^^^^
|
||||||
Reference in New Issue
Block a user