Skip to content

Commit a682564

Browse files
committed
refactor(toml): Rename 'resolved' to 'normalized'
In a discussion on an issue, it became confusing to talk about "resolved" manifests and dependency resolution, so I'm switching manifests to use the other term I considered, "normalized".
1 parent 354f9b2 commit a682564

File tree

16 files changed

+277
-258
lines changed

16 files changed

+277
-258
lines changed

Cargo.lock

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ cargo-platform = { path = "crates/cargo-platform", version = "0.1.5" }
3333
cargo-test-macro = { version = "0.3.0", path = "crates/cargo-test-macro" }
3434
cargo-test-support = { version = "0.4.0", path = "crates/cargo-test-support" }
3535
cargo-util = { version = "0.2.14", path = "crates/cargo-util" }
36-
cargo-util-schemas = { version = "0.5.0", path = "crates/cargo-util-schemas" }
36+
cargo-util-schemas = { version = "0.6.0", path = "crates/cargo-util-schemas" }
3737
cargo_metadata = "0.18.1"
3838
clap = "4.5.11"
3939
color-print = "0.3.6"

crates/cargo-util-schemas/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "cargo-util-schemas"
3-
version = "0.5.1"
3+
version = "0.6.0"
44
rust-version = "1.80" # MSRV:1
55
edition.workspace = true
66
license.workspace = true

crates/cargo-util-schemas/src/manifest/mod.rs

+47-38
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,8 @@ impl TomlManifest {
106106
self.features.as_ref()
107107
}
108108

109-
pub fn resolved_lints(&self) -> Result<Option<&TomlLints>, UnresolvedError> {
110-
self.lints.as_ref().map(|l| l.resolved()).transpose()
109+
pub fn normalized_lints(&self) -> Result<Option<&TomlLints>, UnresolvedError> {
110+
self.lints.as_ref().map(|l| l.normalized()).transpose()
111111
}
112112
}
113113

@@ -237,23 +237,26 @@ impl TomlPackage {
237237
}
238238
}
239239

240-
pub fn resolved_edition(&self) -> Result<Option<&String>, UnresolvedError> {
241-
self.edition.as_ref().map(|v| v.resolved()).transpose()
240+
pub fn normalized_edition(&self) -> Result<Option<&String>, UnresolvedError> {
241+
self.edition.as_ref().map(|v| v.normalized()).transpose()
242242
}
243243

244-
pub fn resolved_rust_version(&self) -> Result<Option<&RustVersion>, UnresolvedError> {
245-
self.rust_version.as_ref().map(|v| v.resolved()).transpose()
244+
pub fn normalized_rust_version(&self) -> Result<Option<&RustVersion>, UnresolvedError> {
245+
self.rust_version
246+
.as_ref()
247+
.map(|v| v.normalized())
248+
.transpose()
246249
}
247250

248-
pub fn resolved_version(&self) -> Result<Option<&semver::Version>, UnresolvedError> {
249-
self.version.as_ref().map(|v| v.resolved()).transpose()
251+
pub fn normalized_version(&self) -> Result<Option<&semver::Version>, UnresolvedError> {
252+
self.version.as_ref().map(|v| v.normalized()).transpose()
250253
}
251254

252-
pub fn resolved_authors(&self) -> Result<Option<&Vec<String>>, UnresolvedError> {
253-
self.authors.as_ref().map(|v| v.resolved()).transpose()
255+
pub fn normalized_authors(&self) -> Result<Option<&Vec<String>>, UnresolvedError> {
256+
self.authors.as_ref().map(|v| v.normalized()).transpose()
254257
}
255258

256-
pub fn resolved_build(&self) -> Result<Option<&String>, UnresolvedError> {
259+
pub fn normalized_build(&self) -> Result<Option<&String>, UnresolvedError> {
257260
let readme = self.build.as_ref().ok_or(UnresolvedError)?;
258261
match readme {
259262
StringOrBool::Bool(false) => Ok(None),
@@ -262,60 +265,66 @@ impl TomlPackage {
262265
}
263266
}
264267

265-
pub fn resolved_exclude(&self) -> Result<Option<&Vec<String>>, UnresolvedError> {
266-
self.exclude.as_ref().map(|v| v.resolved()).transpose()
268+
pub fn normalized_exclude(&self) -> Result<Option<&Vec<String>>, UnresolvedError> {
269+
self.exclude.as_ref().map(|v| v.normalized()).transpose()
267270
}
268271

269-
pub fn resolved_include(&self) -> Result<Option<&Vec<String>>, UnresolvedError> {
270-
self.include.as_ref().map(|v| v.resolved()).transpose()
272+
pub fn normalized_include(&self) -> Result<Option<&Vec<String>>, UnresolvedError> {
273+
self.include.as_ref().map(|v| v.normalized()).transpose()
271274
}
272275

273-
pub fn resolved_publish(&self) -> Result<Option<&VecStringOrBool>, UnresolvedError> {
274-
self.publish.as_ref().map(|v| v.resolved()).transpose()
276+
pub fn normalized_publish(&self) -> Result<Option<&VecStringOrBool>, UnresolvedError> {
277+
self.publish.as_ref().map(|v| v.normalized()).transpose()
275278
}
276279

277-
pub fn resolved_description(&self) -> Result<Option<&String>, UnresolvedError> {
278-
self.description.as_ref().map(|v| v.resolved()).transpose()
280+
pub fn normalized_description(&self) -> Result<Option<&String>, UnresolvedError> {
281+
self.description
282+
.as_ref()
283+
.map(|v| v.normalized())
284+
.transpose()
279285
}
280286

281-
pub fn resolved_homepage(&self) -> Result<Option<&String>, UnresolvedError> {
282-
self.homepage.as_ref().map(|v| v.resolved()).transpose()
287+
pub fn normalized_homepage(&self) -> Result<Option<&String>, UnresolvedError> {
288+
self.homepage.as_ref().map(|v| v.normalized()).transpose()
283289
}
284290

285-
pub fn resolved_documentation(&self) -> Result<Option<&String>, UnresolvedError> {
291+
pub fn normalized_documentation(&self) -> Result<Option<&String>, UnresolvedError> {
286292
self.documentation
287293
.as_ref()
288-
.map(|v| v.resolved())
294+
.map(|v| v.normalized())
289295
.transpose()
290296
}
291297

292-
pub fn resolved_readme(&self) -> Result<Option<&String>, UnresolvedError> {
298+
pub fn normalized_readme(&self) -> Result<Option<&String>, UnresolvedError> {
293299
let readme = self.readme.as_ref().ok_or(UnresolvedError)?;
294-
readme.resolved().and_then(|sb| match sb {
300+
readme.normalized().and_then(|sb| match sb {
295301
StringOrBool::Bool(false) => Ok(None),
296302
StringOrBool::Bool(true) => Err(UnresolvedError),
297303
StringOrBool::String(value) => Ok(Some(value)),
298304
})
299305
}
300306

301-
pub fn resolved_keywords(&self) -> Result<Option<&Vec<String>>, UnresolvedError> {
302-
self.keywords.as_ref().map(|v| v.resolved()).transpose()
307+
pub fn normalized_keywords(&self) -> Result<Option<&Vec<String>>, UnresolvedError> {
308+
self.keywords.as_ref().map(|v| v.normalized()).transpose()
303309
}
304310

305-
pub fn resolved_categories(&self) -> Result<Option<&Vec<String>>, UnresolvedError> {
306-
self.categories.as_ref().map(|v| v.resolved()).transpose()
311+
pub fn normalized_categories(&self) -> Result<Option<&Vec<String>>, UnresolvedError> {
312+
self.categories.as_ref().map(|v| v.normalized()).transpose()
307313
}
308314

309-
pub fn resolved_license(&self) -> Result<Option<&String>, UnresolvedError> {
310-
self.license.as_ref().map(|v| v.resolved()).transpose()
315+
pub fn normalized_license(&self) -> Result<Option<&String>, UnresolvedError> {
316+
self.license.as_ref().map(|v| v.normalized()).transpose()
311317
}
312318

313-
pub fn resolved_license_file(&self) -> Result<Option<&String>, UnresolvedError> {
314-
self.license_file.as_ref().map(|v| v.resolved()).transpose()
319+
pub fn normalized_license_file(&self) -> Result<Option<&String>, UnresolvedError> {
320+
self.license_file
321+
.as_ref()
322+
.map(|v| v.normalized())
323+
.transpose()
315324
}
316325

317-
pub fn resolved_repository(&self) -> Result<Option<&String>, UnresolvedError> {
318-
self.repository.as_ref().map(|v| v.resolved()).transpose()
326+
pub fn normalized_repository(&self) -> Result<Option<&String>, UnresolvedError> {
327+
self.repository.as_ref().map(|v| v.normalized()).transpose()
319328
}
320329
}
321330

@@ -330,7 +339,7 @@ pub enum InheritableField<T> {
330339
}
331340

332341
impl<T> InheritableField<T> {
333-
pub fn resolved(&self) -> Result<&T, UnresolvedError> {
342+
pub fn normalized(&self) -> Result<&T, UnresolvedError> {
334343
self.as_value().ok_or(UnresolvedError)
335344
}
336345

@@ -634,7 +643,7 @@ impl InheritableDependency {
634643
}
635644
}
636645

637-
pub fn resolved(&self) -> Result<&TomlDependency, UnresolvedError> {
646+
pub fn normalized(&self) -> Result<&TomlDependency, UnresolvedError> {
638647
match self {
639648
InheritableDependency::Value(d) => Ok(d),
640649
InheritableDependency::Inherit(_) => Err(UnresolvedError),
@@ -1440,7 +1449,7 @@ pub struct InheritableLints {
14401449
}
14411450

14421451
impl InheritableLints {
1443-
pub fn resolved(&self) -> Result<&TomlLints, UnresolvedError> {
1452+
pub fn normalized(&self) -> Result<&TomlLints, UnresolvedError> {
14441453
if self.workspace {
14451454
Err(UnresolvedError)
14461455
} else {

src/cargo/core/compiler/fingerprint/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1426,7 +1426,7 @@ fn calculate_normal(
14261426
// HACK(#13975): duplicating the lookup logic here until `--check-cfg` is supported
14271427
// on Cargo's MSRV and we can centralize the logic in `lints_to_rustflags`
14281428
let mut lint_check_cfg = Vec::new();
1429-
if let Ok(Some(lints)) = unit.pkg.manifest().resolved_toml().resolved_lints() {
1429+
if let Ok(Some(lints)) = unit.pkg.manifest().normalized_toml().normalized_lints() {
14301430
if let Some(rust_lints) = lints.get("rust") {
14311431
if let Some(unexpected_cfgs) = rust_lints.get("unexpected_cfgs") {
14321432
if let Some(config) = unexpected_cfgs.config() {

src/cargo/core/compiler/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1355,7 +1355,7 @@ fn check_cfg_args(unit: &Unit) -> CargoResult<Vec<OsString>> {
13551355
];
13561356

13571357
// Also include the custom arguments specified in `[lints.rust.unexpected_cfgs.check_cfg]`
1358-
if let Ok(Some(lints)) = unit.pkg.manifest().resolved_toml().resolved_lints() {
1358+
if let Ok(Some(lints)) = unit.pkg.manifest().normalized_toml().normalized_lints() {
13591359
if let Some(rust_lints) = lints.get("rust") {
13601360
if let Some(unexpected_cfgs) = rust_lints.get("unexpected_cfgs") {
13611361
if let Some(config) = unexpected_cfgs.config() {

src/cargo/core/manifest.rs

+15-15
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ pub struct Manifest {
6464
contents: Rc<String>,
6565
document: Rc<toml_edit::ImDocument<String>>,
6666
original_toml: Rc<TomlManifest>,
67-
resolved_toml: Rc<TomlManifest>,
67+
normalized_toml: Rc<TomlManifest>,
6868
summary: Summary,
6969

7070
// this form of manifest:
@@ -110,7 +110,7 @@ pub struct VirtualManifest {
110110
contents: Rc<String>,
111111
document: Rc<toml_edit::ImDocument<String>>,
112112
original_toml: Rc<TomlManifest>,
113-
resolved_toml: Rc<TomlManifest>,
113+
normalized_toml: Rc<TomlManifest>,
114114

115115
// this form of manifest:
116116
replace: Vec<(PackageIdSpec, Dependency)>,
@@ -422,7 +422,7 @@ impl Manifest {
422422
contents: Rc<String>,
423423
document: Rc<toml_edit::ImDocument<String>>,
424424
original_toml: Rc<TomlManifest>,
425-
resolved_toml: Rc<TomlManifest>,
425+
normalized_toml: Rc<TomlManifest>,
426426
summary: Summary,
427427

428428
default_kind: Option<CompileKind>,
@@ -451,7 +451,7 @@ impl Manifest {
451451
contents,
452452
document,
453453
original_toml,
454-
resolved_toml,
454+
normalized_toml,
455455
summary,
456456

457457
default_kind,
@@ -483,9 +483,9 @@ impl Manifest {
483483
pub fn contents(&self) -> &str {
484484
self.contents.as_str()
485485
}
486-
/// See [`Manifest::resolved_toml`] for what "resolved" means
487-
pub fn to_resolved_contents(&self) -> CargoResult<String> {
488-
let toml = toml::to_string_pretty(self.resolved_toml())?;
486+
/// See [`Manifest::normalized_toml`] for what "normalized" means
487+
pub fn to_normalized_contents(&self) -> CargoResult<String> {
488+
let toml = toml::to_string_pretty(self.normalized_toml())?;
489489
Ok(format!("{}\n{}", MANIFEST_PREAMBLE, toml))
490490
}
491491
/// Collection of spans for the original TOML
@@ -502,8 +502,8 @@ impl Manifest {
502502
/// useful for the operation of cargo, including
503503
/// - workspace inheritance
504504
/// - target discovery
505-
pub fn resolved_toml(&self) -> &TomlManifest {
506-
&self.resolved_toml
505+
pub fn normalized_toml(&self) -> &TomlManifest {
506+
&self.normalized_toml
507507
}
508508
pub fn summary(&self) -> &Summary {
509509
&self.summary
@@ -553,7 +553,7 @@ impl Manifest {
553553
&self.warnings
554554
}
555555
pub fn profiles(&self) -> Option<&TomlProfiles> {
556-
self.resolved_toml.profile.as_ref()
556+
self.normalized_toml.profile.as_ref()
557557
}
558558
pub fn publish(&self) -> &Option<Vec<String>> {
559559
&self.publish
@@ -664,7 +664,7 @@ impl VirtualManifest {
664664
contents: Rc<String>,
665665
document: Rc<toml_edit::ImDocument<String>>,
666666
original_toml: Rc<TomlManifest>,
667-
resolved_toml: Rc<TomlManifest>,
667+
normalized_toml: Rc<TomlManifest>,
668668
replace: Vec<(PackageIdSpec, Dependency)>,
669669
patch: HashMap<Url, Vec<Dependency>>,
670670
workspace: WorkspaceConfig,
@@ -675,7 +675,7 @@ impl VirtualManifest {
675675
contents,
676676
document,
677677
original_toml,
678-
resolved_toml,
678+
normalized_toml,
679679
replace,
680680
patch,
681681
workspace,
@@ -698,8 +698,8 @@ impl VirtualManifest {
698698
&self.original_toml
699699
}
700700
/// The [`TomlManifest`] with all fields expanded
701-
pub fn resolved_toml(&self) -> &TomlManifest {
702-
&self.resolved_toml
701+
pub fn normalized_toml(&self) -> &TomlManifest {
702+
&self.normalized_toml
703703
}
704704

705705
pub fn replace(&self) -> &[(PackageIdSpec, Dependency)] {
@@ -715,7 +715,7 @@ impl VirtualManifest {
715715
}
716716

717717
pub fn profiles(&self) -> Option<&TomlProfiles> {
718-
self.resolved_toml.profile.as_ref()
718+
self.normalized_toml.profile.as_ref()
719719
}
720720

721721
pub fn warnings_mut(&mut self) -> &mut Warnings {

src/cargo/core/workspace.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1066,7 +1066,7 @@ impl<'gctx> Workspace<'gctx> {
10661066
);
10671067
self.gctx.shell().warn(&msg)
10681068
};
1069-
if manifest.resolved_toml().has_profiles() {
1069+
if manifest.normalized_toml().has_profiles() {
10701070
emit_warning("profiles")?;
10711071
}
10721072
if !manifest.replace().is_empty() {
@@ -1191,7 +1191,7 @@ impl<'gctx> Workspace<'gctx> {
11911191
let mut error_count = 0;
11921192
let toml_lints = pkg
11931193
.manifest()
1194-
.resolved_toml()
1194+
.normalized_toml()
11951195
.lints
11961196
.clone()
11971197
.map(|lints| lints.lints)

src/cargo/ops/cargo_package.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -924,7 +924,7 @@ fn tar(
924924
}
925925
FileContents::Generated(generated_kind) => {
926926
let contents = match generated_kind {
927-
GeneratedFile::Manifest => publish_pkg.manifest().to_resolved_contents()?,
927+
GeneratedFile::Manifest => publish_pkg.manifest().to_normalized_contents()?,
928928
GeneratedFile::Lockfile => build_lock(ws, &publish_pkg, local_reg)?,
929929
GeneratedFile::VcsInfo(ref s) => serde_json::to_string_pretty(s)?,
930930
};

src/cargo/ops/fix.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ fn add_feature_for_unused_deps(
443443
let manifest = pkg.manifest();
444444

445445
let activated_opt_deps = manifest
446-
.resolved_toml()
446+
.normalized_toml()
447447
.features()
448448
.map(|map| {
449449
map.values()
@@ -479,7 +479,7 @@ fn add_feature_for_unused_deps(
479479
// only way to guarantee an optional dependency is available for use.
480480
//
481481
// The way we avoid implicitly creating features in Edition2024 is we remove the
482-
// dependency from `resolved_toml` if there is no `dep:` syntax as that is the only
482+
// dependency from `normalized_toml` if there is no `dep:` syntax as that is the only
483483
// syntax that suppresses the creation of the implicit feature.
484484
for (feature_name, activations) in features.iter_mut() {
485485
let Some(activations) = activations.as_array_mut() else {

src/cargo/ops/registry/publish.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ pub(crate) fn prepare_transmit(
411411
}
412412
}
413413

414-
let string_features = match manifest.resolved_toml().features() {
414+
let string_features = match manifest.normalized_toml().features() {
415415
Some(features) => features
416416
.iter()
417417
.map(|(feat, values)| {

src/cargo/ops/vendor.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ fn cp_sources(
360360
let cksum = if dst.file_name() == Some(OsStr::new("Cargo.toml"))
361361
&& pkg.package_id().source_id().is_git()
362362
{
363-
let contents = pkg.manifest().to_resolved_contents()?;
363+
let contents = pkg.manifest().to_normalized_contents()?;
364364
copy_and_checksum(
365365
&dst,
366366
&mut dst_opts,

src/cargo/sources/path.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -880,14 +880,14 @@ fn read_packages(
880880

881881
fn nested_paths(manifest: &Manifest) -> Vec<PathBuf> {
882882
let mut nested_paths = Vec::new();
883-
let resolved = manifest.resolved_toml();
884-
let dependencies = resolved
883+
let normalized = manifest.normalized_toml();
884+
let dependencies = normalized
885885
.dependencies
886886
.iter()
887-
.chain(resolved.build_dependencies())
888-
.chain(resolved.dev_dependencies())
887+
.chain(normalized.build_dependencies())
888+
.chain(normalized.dev_dependencies())
889889
.chain(
890-
resolved
890+
normalized
891891
.target
892892
.as_ref()
893893
.into_iter()

0 commit comments

Comments
 (0)