Skip to content

Commit d438c80

Browse files
committed
Auto merge of #13603 - epage:toml3, r=weihanglo
refactor(toml): Expose surce/spans for VirtualManifests ### What does this PR try to resolve? This is a follow up to #13593, expanding support from `Manifest` to `VirtualManifest` as well. This also does other clean up along the way in preparation for making a more explicit `resolve_toml` phase. ### How should we test and review this PR? ### Additional information
2 parents ecb89a1 + 627217a commit d438c80

File tree

7 files changed

+192
-160
lines changed

7 files changed

+192
-160
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/cargo-util-schemas/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "cargo-util-schemas"
3-
version = "0.3.0"
3+
version = "0.3.1"
44
rust-version = "1.76.0" # MSRV:1
55
edition.workspace = true
66
license.workspace = true

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ pub use rust_version::RustVersion;
2626
pub use rust_version::RustVersionError;
2727

2828
/// This type is used to deserialize `Cargo.toml` files.
29-
#[derive(Debug, Deserialize, Serialize)]
29+
#[derive(Default, Clone, Debug, Deserialize, Serialize)]
3030
#[serde(rename_all = "kebab-case")]
3131
pub struct TomlManifest {
3232
// when adding new fields, be sure to check whether `requires_package` should disallow them

src/cargo/core/compiler/standard_lib.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use crate::util::errors::CargoResult;
1212
use crate::GlobalContext;
1313
use std::collections::{HashMap, HashSet};
1414
use std::path::PathBuf;
15+
use std::rc::Rc;
1516

1617
use super::BuildConfig;
1718

@@ -103,10 +104,13 @@ pub fn resolve_std<'gctx>(
103104
/*custom_metadata*/ &None,
104105
));
105106
let virtual_manifest = crate::core::VirtualManifest::new(
107+
Rc::default(),
108+
Rc::new(toml_edit::ImDocument::parse("".to_owned()).expect("empty is valid TOML")),
109+
Rc::default(),
110+
Rc::default(),
106111
/*replace*/ Vec::new(),
107112
patch,
108113
ws_config,
109-
/*profiles*/ None,
110114
crate::core::Features::default(),
111115
None,
112116
);

src/cargo/core/features.rs

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,6 @@ impl Features {
546546
warnings: &mut Vec<String>,
547547
) -> CargoResult<()> {
548548
let nightly_features_allowed = self.nightly_features_allowed;
549-
let is_local = self.is_local;
550549
let Some((slot, feature)) = self.status(feature_name) else {
551550
bail!("unknown cargo feature `{}`", feature_name)
552551
};
@@ -567,19 +566,15 @@ impl Features {
567566

568567
match feature.stability {
569568
Status::Stable => {
570-
// The user can't do anything about non-local packages.
571-
// Warnings are usually suppressed, but just being cautious here.
572-
if is_local {
573-
let warning = format!(
574-
"the cargo feature `{}` has been stabilized in the {} \
569+
let warning = format!(
570+
"the cargo feature `{}` has been stabilized in the {} \
575571
release and is no longer necessary to be listed in the \
576572
manifest\n {}",
577-
feature_name,
578-
feature.version,
579-
see_docs()
580-
);
581-
warnings.push(warning);
582-
}
573+
feature_name,
574+
feature.version,
575+
see_docs()
576+
);
577+
warnings.push(warning);
583578
}
584579
Status::Unstable if !nightly_features_allowed => bail!(
585580
"the cargo feature `{}` requires a nightly version of \

src/cargo/core/manifest.rs

Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ pub struct Manifest {
4444
// alternate forms of manifests:
4545
contents: Rc<String>,
4646
document: Rc<toml_edit::ImDocument<String>>,
47+
original_toml: Rc<TomlManifest>,
4748
resolved_toml: Rc<TomlManifest>,
4849
summary: Summary,
4950

@@ -57,7 +58,6 @@ pub struct Manifest {
5758
include: Vec<String>,
5859
metadata: ManifestMetadata,
5960
custom_metadata: Option<toml::Value>,
60-
profiles: Option<TomlProfiles>,
6161
publish: Option<Vec<String>>,
6262
replace: Vec<(PackageIdSpec, Dependency)>,
6363
patch: HashMap<Url, Vec<Dependency>>,
@@ -87,10 +87,16 @@ pub struct Warnings(Vec<DelayedWarning>);
8787

8888
#[derive(Clone, Debug)]
8989
pub struct VirtualManifest {
90+
// alternate forms of manifests:
91+
contents: Rc<String>,
92+
document: Rc<toml_edit::ImDocument<String>>,
93+
original_toml: Rc<TomlManifest>,
94+
resolved_toml: Rc<TomlManifest>,
95+
96+
// this form of manifest:
9097
replace: Vec<(PackageIdSpec, Dependency)>,
9198
patch: HashMap<Url, Vec<Dependency>>,
9299
workspace: WorkspaceConfig,
93-
profiles: Option<TomlProfiles>,
94100
warnings: Warnings,
95101
features: Features,
96102
resolve_behavior: Option<ResolveBehavior>,
@@ -396,6 +402,7 @@ impl Manifest {
396402
pub fn new(
397403
contents: Rc<String>,
398404
document: Rc<toml_edit::ImDocument<String>>,
405+
original_toml: Rc<TomlManifest>,
399406
resolved_toml: Rc<TomlManifest>,
400407
summary: Summary,
401408

@@ -407,7 +414,6 @@ impl Manifest {
407414
links: Option<String>,
408415
metadata: ManifestMetadata,
409416
custom_metadata: Option<toml::Value>,
410-
profiles: Option<TomlProfiles>,
411417
publish: Option<Vec<String>>,
412418
replace: Vec<(PackageIdSpec, Dependency)>,
413419
patch: HashMap<Url, Vec<Dependency>>,
@@ -425,6 +431,7 @@ impl Manifest {
425431
Manifest {
426432
contents,
427433
document,
434+
original_toml,
428435
resolved_toml,
429436
summary,
430437

@@ -437,7 +444,6 @@ impl Manifest {
437444
links,
438445
metadata,
439446
custom_metadata,
440-
profiles,
441447
publish,
442448
replace,
443449
patch,
@@ -462,6 +468,10 @@ impl Manifest {
462468
pub fn document(&self) -> &toml_edit::ImDocument<String> {
463469
&self.document
464470
}
471+
/// The [`TomlManifest`] as parsed from [`Manifest::document`]
472+
pub fn original_toml(&self) -> &TomlManifest {
473+
&self.original_toml
474+
}
465475
/// The [`TomlManifest`] with all fields expanded
466476
pub fn resolved_toml(&self) -> &TomlManifest {
467477
&self.resolved_toml
@@ -514,7 +524,7 @@ impl Manifest {
514524
&self.warnings
515525
}
516526
pub fn profiles(&self) -> Option<&TomlProfiles> {
517-
self.profiles.as_ref()
527+
self.resolved_toml.profile.as_ref()
518528
}
519529
pub fn publish(&self) -> &Option<Vec<String>> {
520530
&self.publish
@@ -622,24 +632,47 @@ impl Manifest {
622632

623633
impl VirtualManifest {
624634
pub fn new(
635+
contents: Rc<String>,
636+
document: Rc<toml_edit::ImDocument<String>>,
637+
original_toml: Rc<TomlManifest>,
638+
resolved_toml: Rc<TomlManifest>,
625639
replace: Vec<(PackageIdSpec, Dependency)>,
626640
patch: HashMap<Url, Vec<Dependency>>,
627641
workspace: WorkspaceConfig,
628-
profiles: Option<TomlProfiles>,
629642
features: Features,
630643
resolve_behavior: Option<ResolveBehavior>,
631644
) -> VirtualManifest {
632645
VirtualManifest {
646+
contents,
647+
document,
648+
original_toml,
649+
resolved_toml,
633650
replace,
634651
patch,
635652
workspace,
636-
profiles,
637653
warnings: Warnings::new(),
638654
features,
639655
resolve_behavior,
640656
}
641657
}
642658

659+
/// The raw contents of the original TOML
660+
pub fn contents(&self) -> &str {
661+
self.contents.as_str()
662+
}
663+
/// Collection of spans for the original TOML
664+
pub fn document(&self) -> &toml_edit::ImDocument<String> {
665+
&self.document
666+
}
667+
/// The [`TomlManifest`] as parsed from [`VirtualManifest::document`]
668+
pub fn original_toml(&self) -> &TomlManifest {
669+
&self.original_toml
670+
}
671+
/// The [`TomlManifest`] with all fields expanded
672+
pub fn resolved_toml(&self) -> &TomlManifest {
673+
&self.resolved_toml
674+
}
675+
643676
pub fn replace(&self) -> &[(PackageIdSpec, Dependency)] {
644677
&self.replace
645678
}
@@ -653,7 +686,7 @@ impl VirtualManifest {
653686
}
654687

655688
pub fn profiles(&self) -> Option<&TomlProfiles> {
656-
self.profiles.as_ref()
689+
self.resolved_toml.profile.as_ref()
657690
}
658691

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

0 commit comments

Comments
 (0)