Skip to content
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

Deduplicate fingerprint logic and check-cfg lint config #13975

Closed
Urgau opened this issue May 28, 2024 · 0 comments · Fixed by #14567
Closed

Deduplicate fingerprint logic and check-cfg lint config #13975

Urgau opened this issue May 28, 2024 · 0 comments · Fixed by #14567
Labels
C-cleanup Category: cleanup within the codebase

Comments

@Urgau
Copy link
Member

Urgau commented May 28, 2024

#13958 introduce a duplication in the code between the fingerprint logic and the check-cfg lint config, because of Cargo MSRV, the --check-cfg code generation is dependant on a minimum rustc version (1.79).

It would be good to consolidate

// Include all the args from `[lints.rust.unexpected_cfgs.check-cfg]`
//
// HACK(#13975): duplicating the lookup logic here until `--check-cfg` is supported
// on Cargo's MSRV and we can centralize the logic in `lints_to_rustflags`
let mut lint_check_cfg = Vec::new();
if let Ok(Some(lints)) = unit.pkg.manifest().resolved_toml().resolved_lints() {
if let Some(rust_lints) = lints.get("rust") {
if let Some(unexpected_cfgs) = rust_lints.get("unexpected_cfgs") {
if let Some(config) = unexpected_cfgs.config() {
if let Some(check_cfg) = config.get("check-cfg") {
if let Ok(check_cfgs) =
toml::Value::try_into::<Vec<String>>(check_cfg.clone())
{
lint_check_cfg = check_cfgs;
}
}
}
}
}
}
and
// Also include the custom arguments specified in `[lints.rust.unexpected_cfgs.check_cfg]`
if let Ok(Some(lints)) = unit.pkg.manifest().resolved_toml().resolved_lints() {
if let Some(rust_lints) = lints.get("rust") {
if let Some(unexpected_cfgs) = rust_lints.get("unexpected_cfgs") {
if let Some(config) = unexpected_cfgs.config() {
if let Some(check_cfg) = config.get("check-cfg") {
if let Ok(check_cfgs) =
toml::Value::try_into::<Vec<String>>(check_cfg.clone())
{
for check_cfg in check_cfgs {
args.push(OsString::from("--check-cfg"));
args.push(OsString::from(check_cfg));
}
// error about `check-cfg` not being a list-of-string
} else {
bail!("`lints.rust.unexpected_cfgs.check-cfg` must be a list of string");
}
}
}
}
}
}
in
fn lints_to_rustflags(lints: &manifest::TomlLints) -> Vec<String> {

Originate from #13958 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-cleanup Category: cleanup within the codebase
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants