Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Workspace root detection can print warnings without context #15167

Open
ehuss opened this issue Feb 10, 2025 · 2 comments
Open

Workspace root detection can print warnings without context #15167

ehuss opened this issue Feb 10, 2025 · 2 comments
Labels
A-diagnostics Area: Error and warning messages generated by Cargo itself. C-bug Category: bug S-triage Status: This issue is waiting on initial triage.

Comments

@ehuss
Copy link
Contributor

ehuss commented Feb 10, 2025

Problem

When there is a package in a subdirectory of another package, and the root package generates warnings, then cargo will print a warning, but not tell you where it is coming from. This can be confusing, since the package in the root doesn't actually have any bearing on the package in the subdirectory (it only needs to be parsed to know if it defines a workspace). In a normal workspace, cargo prints the path to the manifest generating the warning.

Steps

Root has:

# Root Cargo.toml
[package]
name = "foo"

and in a subdirectory:

# bar/Cargo.toml
[package]
name = "bar"
version = "0.1.0"
edition = "2024"

building in bar will result in:

warning: no edition set: defaulting to the 2015 edition while the latest is 2024

This warning does not indicate where it is coming from. I believe this happens somewhere in find_workspace_root_with_loader.

Possible Solution(s)

Two possible solutions I can think of:

  • Don't display any warnings loading a manifest during workspace discovery if it determines it isn't actually a workspace (i.e. the root manifest ends up being ignored).
  • Include the path to the manifest when printing warnings during workspace discovery.

Notes

No response

Version

cargo 1.86.0-nightly (2928e3273 2025-02-07)
release: 1.86.0-nightly
commit-hash: 2928e32734b04925ee51e1ae88bea9a83d2fd451
commit-date: 2025-02-07
host: aarch64-apple-darwin
libgit2: 1.9.0 (sys:0.20.0 vendored)
libcurl: 8.7.1 (sys:0.4.74+curl-8.9.0 system ssl:(SecureTransport) LibreSSL/3.3.6)
ssl: OpenSSL 1.1.1w  11 Sep 2023
os: Mac OS 14.6.1 [64-bit]
@ehuss ehuss added A-diagnostics Area: Error and warning messages generated by Cargo itself. C-bug Category: bug S-triage Status: This issue is waiting on initial triage. labels Feb 10, 2025
@epage
Copy link
Contributor

epage commented Feb 10, 2025

Interesting. We push that message into warnings which we then set on EitherManifest. When we emit these, we conditionally add the path

let msg = if self.root_manifest.is_none() {
warning.message.to_string()
} else {
// In a workspace, it can be confusing where a warning
// originated, so include the path.
format!("{}: {}", path.display(), warning.message)
};
self.gctx.shell().warn(msg)?

@epage
Copy link
Contributor

epage commented Feb 10, 2025

As we move to using our diagnostic outputs, these messages should look more like rustc, including showing of the path

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Error and warning messages generated by Cargo itself. C-bug Category: bug S-triage Status: This issue is waiting on initial triage.
Projects
None yet
Development

No branches or pull requests

2 participants