Skip to content

Conversation

@secona
Copy link
Contributor

@secona secona commented Dec 17, 2025

What does this PR try to resolve?

This PR supports creating an in-memory only Manifest.

Part of #16290

How to test and review this PR?

No tests should change as this is for cargo-as-a-library.

@rustbot rustbot added A-build-execution Area: anything dealing with executing the compiler A-manifest Area: Cargo.toml issues A-workspaces Area: workspaces Command-fix Command-vendor labels Dec 17, 2025
}

let document = manifest.document();
let document = manifest.document().unwrap();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should lints assume that this is a Some? I'm not familiar on how lints are used in cargo-as-a-library. Other options would probably be bail!ing out or silently stopping.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We will need a way to run lint passes with plumbing commands, so we'll need to have a way to resolve this

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We will need a way to run lint passes with plumbing commands

By this, do you mean lints being run as part of an existing plumbing command, like read-manifest, or having a separate plumbing command to run lints?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unsure where we will run it atm

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right. I think we can safely assume that the fields are Some. Within cargo itself, the calls to constructors use Some.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, we should be handling the Nones

contents: Rc<String>,
document: Rc<toml::Spanned<toml::de::DeTable<'static>>>,
original_toml: Rc<TomlManifest>,
document: Option<Rc<toml::Spanned<toml::de::DeTable<'static>>>>,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like removing the .unwrap()s would need to happen before this

@secona secona force-pushed the in-memory-manifest branch from f857ec0 to 8d25903 Compare December 17, 2025 16:21
@secona secona marked this pull request as ready for review December 17, 2025 17:06
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Dec 17, 2025
@rustbot
Copy link
Collaborator

rustbot commented Dec 17, 2025

r? @epage

rustbot has assigned @epage.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@secona secona force-pushed the in-memory-manifest branch from 8d25903 to c9fa22d Compare December 17, 2025 17:08
) -> CargoResult<Package> {
let contents = me.manifest().contents();
let document = me.manifest().document();
let contents = me.manifest().contents().unwrap();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My default assumption is that this PR is not ready to merge until all .unwrap()s are resolved. Any remaining .unwrap() should have a justification, likely including switching it to an .expect() explaining what invariants are keeping it from panicking.

@epage epage marked this pull request as draft December 17, 2025 19:13
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Dec 17, 2025
@epage
Copy link
Contributor

epage commented Dec 17, 2025

Because of #16409 (comment), I'm moving this back to a Draft

@secona secona force-pushed the in-memory-manifest branch from c9fa22d to fae3b40 Compare December 18, 2025 23:21
Comment on lines 2369 to 2370
spans: unit.pkg.manifest().document().unwrap().clone(),
contents: unit.pkg.manifest().contents().unwrap().to_owned(),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like these are for public dependency diagnostics. Its either requiring compilation to have a complete Workspace or disabling diagnostics for public dependency.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is no different than any other diagnostics: we should work to allow contents to be optional.

pub fn document(&self) -> &toml::Spanned<toml::de::DeTable<'static>> {
self.document.as_ref().unwrap()
pub fn document(&self) -> Option<&toml::Spanned<toml::de::DeTable<'static>>> {
self.document.as_ref().map(|d| d.as_ref())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are these maps needed?

let contents = manifest.contents();
let contents = manifest
.contents()
.with_context(|| "incomplete Workspace information")?;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that these with_context in this commit are not sufficient either. The error message is not meaningful to the end user and most or all of the functionality that they guard should be runnable

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right. So functionality should still be present but without the snippets?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wherever possible, yes

@secona secona force-pushed the in-memory-manifest branch from fae3b40 to 1dfa6b3 Compare December 19, 2025 20:52
Make `document`, `original_toml` and `contents` optional to allow
creating Manifests from in-memory data.
Make `contents` and `spans` optional in ManifestErrorContext to allow
disabling diagnostics.
@secona secona force-pushed the in-memory-manifest branch from 1dfa6b3 to 4573605 Compare December 19, 2025 21:25
@secona secona force-pushed the in-memory-manifest branch from 4573605 to 9c99c39 Compare December 20, 2025 03:18
Remove calls to `.unwrap` to make lints work with in-memory `Manifest`.
Change the signature for `to_real_manifest`, `to_virtual_manifest` and
`missing_dep_diagnostic` to support in-memory `Manifest`.
@secona secona force-pushed the in-memory-manifest branch from 9c99c39 to 3f8a05f Compare December 20, 2025 12:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-build-execution Area: anything dealing with executing the compiler A-manifest Area: Cargo.toml issues A-workspaces Area: workspaces Command-fix Command-vendor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants