mirror of
https://github.com/rust-lang/cargo
synced 2024-08-28 03:39:31 +00:00
refactor(toml): Group resolving of lints with package
We can't have validation depend on `TomlManifest::resolved_lints` yet because we need to pull out the resolving of deps first.
This commit is contained in:
parent
a2033965a8
commit
772539a03a
|
@ -105,6 +105,10 @@ impl TomlManifest {
|
||||||
pub fn features(&self) -> Option<&BTreeMap<FeatureName, Vec<String>>> {
|
pub fn features(&self) -> Option<&BTreeMap<FeatureName, Vec<String>>> {
|
||||||
self.features.as_ref()
|
self.features.as_ref()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn resolved_lints(&self) -> Result<Option<&TomlLints>, UnresolvedError> {
|
||||||
|
self.lints.as_ref().map(|l| l.resolved()).transpose()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Deserialize, Serialize, Clone)]
|
#[derive(Debug, Deserialize, Serialize, Clone)]
|
||||||
|
@ -1378,6 +1382,16 @@ pub struct InheritableLints {
|
||||||
pub lints: TomlLints,
|
pub lints: TomlLints,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl InheritableLints {
|
||||||
|
pub fn resolved(&self) -> Result<&TomlLints, UnresolvedError> {
|
||||||
|
if self.workspace {
|
||||||
|
Err(UnresolvedError)
|
||||||
|
} else {
|
||||||
|
Ok(&self.lints)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn is_false(b: &bool) -> bool {
|
fn is_false(b: &bool) -> bool {
|
||||||
!b
|
!b
|
||||||
}
|
}
|
||||||
|
|
|
@ -668,6 +668,11 @@ pub fn to_real_manifest(
|
||||||
metadata: original_package.metadata.clone(),
|
metadata: original_package.metadata.clone(),
|
||||||
_invalid_cargo_features: Default::default(),
|
_invalid_cargo_features: Default::default(),
|
||||||
};
|
};
|
||||||
|
let resolved_lints = original_toml
|
||||||
|
.lints
|
||||||
|
.clone()
|
||||||
|
.map(|value| lints_inherit_with(value, || inherit()?.lints()))
|
||||||
|
.transpose()?;
|
||||||
|
|
||||||
let rust_version = resolved_package
|
let rust_version = resolved_package
|
||||||
.resolved_rust_version()
|
.resolved_rust_version()
|
||||||
|
@ -865,14 +870,9 @@ pub fn to_real_manifest(
|
||||||
&inherit_cell,
|
&inherit_cell,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
let lints = original_toml
|
verify_lints(resolved_lints.as_ref(), gctx, manifest_ctx.warnings)?;
|
||||||
.lints
|
|
||||||
.clone()
|
|
||||||
.map(|mw| lints_inherit_with(mw, || inherit()?.lints()))
|
|
||||||
.transpose()?;
|
|
||||||
verify_lints(lints.as_ref(), gctx, manifest_ctx.warnings)?;
|
|
||||||
let default = manifest::TomlLints::default();
|
let default = manifest::TomlLints::default();
|
||||||
let rustflags = lints_to_rustflags(lints.as_ref().unwrap_or(&default));
|
let rustflags = lints_to_rustflags(resolved_lints.as_ref().unwrap_or(&default));
|
||||||
|
|
||||||
let mut target: BTreeMap<String, manifest::TomlPlatform> = BTreeMap::new();
|
let mut target: BTreeMap<String, manifest::TomlPlatform> = BTreeMap::new();
|
||||||
for (name, platform) in original_toml.target.iter().flatten() {
|
for (name, platform) in original_toml.target.iter().flatten() {
|
||||||
|
@ -1128,7 +1128,7 @@ pub fn to_real_manifest(
|
||||||
.badges
|
.badges
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.map(|_| manifest::InheritableField::Value(metadata.badges.clone())),
|
.map(|_| manifest::InheritableField::Value(metadata.badges.clone())),
|
||||||
lints: lints.map(|lints| manifest::InheritableLints {
|
lints: resolved_lints.map(|lints| manifest::InheritableLints {
|
||||||
workspace: false,
|
workspace: false,
|
||||||
lints,
|
lints,
|
||||||
}),
|
}),
|
||||||
|
|
Loading…
Reference in a new issue