//! Rustc adapter lowering.

use aqc_cargo_toml_engine::cargo_lint_table_requirements;
use shackles_core::{EngineRequirementOutput, Provenance, boxed_engine_requirement};

use crate::types::RustcAdapterRequirement;

#[must_use]
pub fn lower_rustc_requirement(
    provenance: Provenance,
    requirement: RustcAdapterRequirement,
) -> EngineRequirementOutput {
    let RustcAdapterRequirement {
        cargo_workspace_rust_lints,
        cargo_package_rust_lints,
    } = requirement;

    let Some(cargo) =
        cargo_lint_table_requirements("rust", cargo_workspace_rust_lints, cargo_package_rust_lints)
    else {
        return Vec::new();
    };
    vec![boxed_engine_requirement(provenance, cargo)]
}
