Skip to content

Commit a1fc7fe

Browse files
committed
refactor: Expose source/spans to Manifest for emitting lints
This does nothing on its own. This is meant to short-circuit some of my refactorings so Muscraft can start on their work on adding lints while I work to move out existing warnings into being able to be converted to lints.
1 parent 196e8b4 commit a1fc7fe

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed

src/cargo/core/manifest.rs

+14
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ impl EitherManifest {
4242
#[derive(Clone, Debug)]
4343
pub struct Manifest {
4444
// alternate forms of manifests:
45+
contents: Rc<String>,
46+
document: Rc<toml_edit::ImDocument<String>>,
4547
resolved_toml: Rc<TomlManifest>,
4648
summary: Summary,
4749

@@ -389,6 +391,8 @@ compact_debug! {
389391

390392
impl Manifest {
391393
pub fn new(
394+
contents: Rc<String>,
395+
document: Rc<toml_edit::ImDocument<String>>,
392396
resolved_toml: Rc<TomlManifest>,
393397
summary: Summary,
394398

@@ -416,6 +420,8 @@ impl Manifest {
416420
embedded: bool,
417421
) -> Manifest {
418422
Manifest {
423+
contents,
424+
document,
419425
resolved_toml,
420426
summary,
421427

@@ -445,6 +451,14 @@ impl Manifest {
445451
}
446452
}
447453

454+
/// The raw contents of the original TOML
455+
pub fn contents(&self) -> &str {
456+
self.contents.as_str()
457+
}
458+
/// Collection of spans for the original TOML
459+
pub fn document(&self) -> &toml_edit::ImDocument<String> {
460+
&self.document
461+
}
448462
/// The [`TomlManifest`] with all fields expanded
449463
pub fn resolved_toml(&self) -> &TomlManifest {
450464
&self.resolved_toml

src/cargo/ops/cargo_package.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -453,10 +453,19 @@ fn build_lock(ws: &Workspace<'_>, orig_pkg: &Package) -> CargoResult<String> {
453453
let orig_resolve = ops::load_pkg_lockfile(ws)?;
454454

455455
// Convert Package -> TomlManifest -> Manifest -> Package
456+
let contents = orig_pkg.manifest().contents();
457+
let document = orig_pkg.manifest().document();
456458
let toml_manifest =
457459
prepare_for_publish(orig_pkg.manifest().resolved_toml(), ws, orig_pkg.root())?;
458460
let source_id = orig_pkg.package_id().source_id();
459-
let manifest = to_real_manifest(toml_manifest, source_id, orig_pkg.manifest_path(), gctx)?;
461+
let manifest = to_real_manifest(
462+
contents.to_owned(),
463+
document.clone(),
464+
toml_manifest,
465+
source_id,
466+
orig_pkg.manifest_path(),
467+
gctx,
468+
)?;
460469
let new_pkg = Package::new(manifest, orig_pkg.manifest_path());
461470

462471
// Regenerate Cargo.lock using the old one as a guide.

src/cargo/util/toml/mod.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ pub fn read_manifest(
5757

5858
(|| {
5959
if toml.package().is_some() {
60-
to_real_manifest(toml, source_id, path, gctx).map(EitherManifest::Real)
60+
to_real_manifest(contents, document, toml, source_id, path, gctx)
61+
.map(EitherManifest::Real)
6162
} else {
6263
to_virtual_manifest(toml, source_id, path, gctx).map(EitherManifest::Virtual)
6364
}
@@ -443,6 +444,8 @@ pub fn prepare_for_publish(
443444

444445
#[tracing::instrument(skip_all)]
445446
pub fn to_real_manifest(
447+
contents: String,
448+
document: toml_edit::ImDocument<String>,
446449
me: manifest::TomlManifest,
447450
source_id: SourceId,
448451
manifest_file: &Path,
@@ -1208,6 +1211,8 @@ pub fn to_real_manifest(
12081211
_unused_keys: Default::default(),
12091212
};
12101213
let mut manifest = Manifest::new(
1214+
Rc::new(contents),
1215+
Rc::new(document),
12111216
Rc::new(resolved_toml),
12121217
summary,
12131218
default_kind,

0 commit comments

Comments
 (0)