Skip to content

Deduplicate fingerprint logic and check-cfg lint config #13975

Closed
@Urgau

Description

@Urgau

#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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-cleanupCategory: cleanup within the codebase

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions