Skip to content

Use serde for target spec json deserialize #144218

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4499,7 +4499,10 @@ dependencies = [
"rustc_macros",
"rustc_serialize",
"rustc_span",
"serde",
"serde_derive",
"serde_json",
"serde_path_to_error",
"tracing",
]

Expand Down Expand Up @@ -4870,6 +4873,16 @@ dependencies = [
"serde",
]

[[package]]
name = "serde_path_to_error"
version = "0.1.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "59fab13f937fa393d08645bf3a84bdfe86e296747b506ada67bb15f10f218b2a"
dependencies = [
"itoa",
"serde",
]

[[package]]
name = "serde_spanned"
version = "0.6.9"
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_session/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -336,12 +336,12 @@ impl LinkSelfContained {
if let Some(component_to_enable) = component.strip_prefix('+') {
self.explicitly_set = None;
self.enabled_components
.insert(LinkSelfContainedComponents::from_str(component_to_enable)?);
.insert(LinkSelfContainedComponents::from_str(component_to_enable).ok()?);
Some(())
} else if let Some(component_to_disable) = component.strip_prefix('-') {
self.explicitly_set = None;
self.disabled_components
.insert(LinkSelfContainedComponents::from_str(component_to_disable)?);
.insert(LinkSelfContainedComponents::from_str(component_to_disable).ok()?);
Some(())
} else {
None
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_session/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1295,7 +1295,7 @@ pub mod parse {
}

pub(crate) fn parse_linker_flavor(slot: &mut Option<LinkerFlavorCli>, v: Option<&str>) -> bool {
match v.and_then(LinkerFlavorCli::from_str) {
match v.and_then(|v| LinkerFlavorCli::from_str(v).ok()) {
Some(lf) => *slot = Some(lf),
_ => return false,
}
Expand Down
3 changes: 3 additions & 0 deletions compiler/rustc_target/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ rustc_fs_util = { path = "../rustc_fs_util" }
rustc_macros = { path = "../rustc_macros" }
rustc_serialize = { path = "../rustc_serialize" }
rustc_span = { path = "../rustc_span" }
serde = "1.0.219"
serde_derive = "1.0.219"
serde_json = "1.0.59"
serde_path_to_error = "0.1.17"
tracing = "0.1"
# tidy-alphabetical-end

Expand Down
15 changes: 15 additions & 0 deletions compiler/rustc_target/src/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,18 @@ impl ToJson for rustc_abi::CanonAbi {
self.to_string().to_json()
}
}

macro_rules! serde_deserialize_from_str {
($ty:ty) => {
impl<'de> serde::Deserialize<'de> for $ty {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
let s = String::deserialize(deserializer)?;
FromStr::from_str(&s).map_err(serde::de::Error::custom)
}
}
};
}
pub(crate) use serde_deserialize_from_str;
1,025 changes: 373 additions & 652 deletions compiler/rustc_target/src/spec/json.rs

Large diffs are not rendered by default.

Loading
Loading