-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Tracking Issue for [lints]
table RFC 3389
#12115
Comments
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
Currently there's no mechanism for controlling Cargo's warnings. Could the |
Yes, one of the future possibilities listed in the RFC is for cargo to have configurable lints. |
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
feat: `lints` feature ### What does this PR try to resolve? Implement rust-lang/rfcs#3389 which shifts a subset of `.cargo/config.toml` functionality to `Cargo.toml` by adding a `[lints]` table. This **should** cover all of the user-facing aspects of the RFC - This doesn't reduce what flags we fingerprint - This will fail if any lint name as `::` in it. What to do in this case was in the RFC discussion but I couldn't find the thread to see what all was involved in that discussion - This does not fail if a `[lints]` table is present or malformed unless nightly with the `lints` feature enabled - The idea is this will act like a `[lints]` table is present in an existing version of rust, ignore it - The intent is to not force an MSRV bump to use it. - When disabled, it will be a warning - When disabled, it will be stripped so we don't publish it Tracking issue for this is #12115. ### How should we test and review this PR? 1. Look at this commit by commit to see it gradually build up 2. Look through the final set of test cases to make sure everything in the RFC is covered I tried to write this in a way that will make it easy to strip out the special handling of this unstable feature, both in code and commit history ### Additional information I'd love to bypass the need for `cargo-features = ["lints"]` so users today can test it on their existing projects but hesitated for now. We can re-evaluate that later. I broke out the `warn_for_feature` as an experiment towards us systemitizing this stabilization approach which we also used with #9732. This works well when we can ignore the new information which isn't too often but sometimes happens. This does involve a subtle change to `profile.rustflags` precedence but its nightly and most likely people won't notice it? The benefit is its in a location more like the rest of the rustflags.
In rust-lang#12115, we explored how we can let stable projects experiment with `[lints]` to provide feedback. What we settled on is switching from the `cargo-features` manifest key to the `-Z` flag as `cargo-features` always requires nightly while `-Z` only requires it when being passed in. This means a project can have a `[lints]` table and have CI / contributors run `cargo +nightly check -Zlints` when they care about warnings.
fix(lints): Switch to -Zlints so stable projects can experiment ### What does this PR try to resolve? In #12115, we explored how we can let stable projects experiment with `[lints]` to provide feedback. What we settled on is switching from the `cargo-features` manifest key to the `-Z` flag as `cargo-features` always requires nightly while `-Z` only requires it when being passed in. This means a project can have a `[lints]` table and have CI / contributors run `cargo +nightly check -Zlints` when they care about warnings. ### How should we test and review this PR? Demonstrate how you test this change and guide reviewers through your PR. With a smooth review process, a pull request usually gets reviewed quicker. If you don't know how to write and run your tests, please read the guide: https://doc.crates.io/contrib/tests ### Additional information I considered reworking the code to show the user the errors they would encounter once the feature is stable but held off. I wasn't quite sure what language to use and most likely a user would have something doing error reporting, like CI, so it should be fine.
This is now stabilized on |
@weihanglo what is the expected timeline to stabilize it? |
It is stable on nightly. It will reach the stable compiler in 1.75. |
Dumb question, is the lints section in a Rust crate inherited by downstream projects? I love linting, but I am wary of accidentally forcing a particular lint configuration onto my users. |
If my memory hasn't rusty, then yes. Dependencies will compile with their lint configurations. However, users are not expected to see any compilation failure since Cargo uses cargo/src/cargo/core/compiler/mod.rs Lines 883 to 894 in d2f6a04
|
Depends on a newly stabilized feature which will be in 1.75 and available on nightly today rust-lang/cargo#12115 (comment)
Depends on a newly stabilized feature which will be in 1.75 and available on nightly today rust-lang/cargo#12115 (comment)
(I'm not sure if this issue is the best place to ask this; if there's a better location, please let me know.) Does the syntax for the |
However, I would recommend against it. In general,
I would instead recommend looking at #8424. |
Small correction: |
Just to be clear on this point: Does the |
Is there (going to be) a way to force workspace lints on all member crates? Having to add |
#12976 was just merged which added the following to the documentation
|
#12208 is our general issue for considering implicit inheritance. If we should consider piece-meal implicit inheritance, I think that should also be discussed there. |
Summary
RFC: #3389Area: [lints] table
Implementation: #12148, #12168, #12174, #12174
Documentation: https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#lints
Issues: A-lints-table
This feature adds a
[lints]
table toCargo.toml
to configure reporting levels for rustc and other tool lints.See also #3591, #5034
Testing instructions
Requires
betastableSteps:
[lints]
table per the unstable reference-Dwarnings
should likely still be passed in explicitly so local experimentation doesn't get blocked on perfection-Adeprecations
likely should still do so since users should see deprecation warnings locally to decide whether to address them-Zlints
flagDebugging
--verbose
to see what order[lints]
and otherRUSTFLAGS
are being passed to the underlying toolExample: #12178
Updates Since RFC
cargo new
will automatically inherit the lints table (Automatically inherit workspace lints when running cargo new/init #12174)profile.rustflags
precedence with[lints]
was unspecified. We have put made it a higher precedence.[lints]
table are not included inrustc -C metadata
hash.[lints]
should only apply to doctests as much as a diagnostic attributes (#[warn(...)]
) in an.rs
file applies to doctests[lints]
tables is deferred (not in original RFC)#[warn]
in the target)[lib]
,[bin]
s in a workspace) want to be held to a higher standard than development code (especially tests)allow-unwrap-in-tests
setting[lints]
table RFC 3389 #12115 (comment) for ideas[lints]
table toCargo.toml
rfcs#3389 (comment)Unresolved Issues
[lints]
table toCargo.toml
rfcs#3389 (comment)[lints]
table toCargo.toml
rfcs#3389 (comment)Feedback
Cases that don't work well:
missing_docs
andmissing_debug_implementations
for[lib]
s (comment)disallowed_methods
in chore: dogfood Cargo-Zlints
table feature #12178Future Extensions
No response
About tracking issues
Tracking issues are used to record the overall progress of implementation.
They are also used as hubs connecting to other relevant issues, e.g., bugs or open design questions.
A tracking issue is however not meant for large scale discussion, questions, or bug reports about a feature.
Instead, open a dedicated issue for the specific matter and add the relevant feature gate label.
The text was updated successfully, but these errors were encountered: