-
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
feat: lints
feature
#12148
feat: lints
feature
#12148
Conversation
r? @weihanglo (rustbot has picked a reviewer for you, use r? to override) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for getting this done! Just finished the first round of my review. Haven't started for the test part.
Example: | ||
|
||
```toml | ||
# [PROJECT_DIR]/Cargo.toml |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be better?
I know it was from reference/workspaces.md
😆
# [PROJECT_DIR]/Cargo.toml | |
# [WORKSPACE_DIR]/Cargo.toml |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Eh, keeping it consistent for now.
src/cargo/util/toml/mod.rs
Outdated
lints.try_into().map(Some).map_err(|err| err.into()) | ||
} | ||
|
||
fn warn_for_feature(name: &str, config: &Config) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Should this be a method of
Features
struct, likeFeatures::require
? - Will the user get a warning from each dependency having
lints
table?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be a method of Features struct, like Features::require?
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.
Figured it'd be better to understand this usage of the warning before stabilizing
Will the user get a warning from each dependency having lints table?
Yes, and I've switched it to use the existing warning system for manifests. This will hide it for non-workspace members and show the path for workspace members.
Note that we strip the [lints]
table on stable so it won't get published
9759d86
to
02f96ea
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Finished a second pass. This pull request should cover almost all things if I've done the review correctly. Just some minor issues left.
@@ -0,0 +1,603 @@ | |||
//! Tests for `[lints]` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we should use snapbox for new tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are a couple of missing features (unordered lists) which is why I haven't pushed it since we can't drive towards a new consistency. That doesn't mean I'm against it just unsure how others would take it.
tests/testsuite/lints.rs
Outdated
.build(); | ||
|
||
foo.cargo("check") | ||
.arg("-v") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.arg("-v") |
Not needed and elsewhere ditto.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added a comment to clarify why this is here: on failure, it will show the order of the flags which would help with debugging.
} | ||
|
||
#[cargo_test] | ||
fn rustdoc_lint() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we can use #[cargo_test(requires_cargo-clippy)]
and write a simple test for clippy lint as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can't atm. clippy fails with an error about cargo-features = ["lints"]
(lints
not existing).
I am looking at a follow up PR that switches us from cargo-features
to -Z
which will allow us to test with clippy (besides allowing people to experiment!)
c52d691
to
9ffa303
Compare
The implementation doesn't match this yet but this reflects what we'll be working towards.
This will make it easier for users to test this feature
This improves the messaging experience (sometimes showing manifest path) and hiding the warning when not relevant).
8d4f929
to
ccf5c64
Compare
…lags This will avoid people reusing it in the future and expanding its use without updating fingerprinting/metadata.
@@ -75,6 +75,7 @@ | |||
//! [`Lto`] flags | ✓ | ✓ | |||
//! config settings[^5] | ✓ | | |||
//! is_std | | ✓ | |||
//! `[lints]` table | ✓ | ✓ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No. It is not included in metadata. Metadata is computed here:
fn compute_metadata( |
The larger question is: Should it be included? RUSTFLAGS
is not in metadata whereas cargo rustc
extra flags is. I think lints table shouldn't, since it more like an extra layer for checking your code but not for final artifacts. However, at this moment we generalize [lints]
table to manifest.rustflags()
, which may be reasonable to be in metadata in the future.
My take is: keep it in fingerprint and give it a footnote stating that it is computed as rustflags from mainfest as a whole. What do people think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks again for the implementation.
Highlight some implementation choices that are unspecified in the RFC:
profile.rustflags
takes precedence over[lints]
table- rustflags derived from
[lints]
table are not included in rustc-C metadata
hash.
Going to merge it soon.
@bors r+ |
☀️ Test successful - checks-actions |
1 similar comment
☀️ Test successful - checks-actions |
👀 Test was successful, but fast-forwarding failed: 422 Changes must be made through a pull request. |
Update cargo 10 commits in 09276c703a473ab33daaeb94917232e80eefd628..64fb38c97ac4d3a327fc9032c862dd28c8833b17 2023-05-16 21:43:35 +0000 to 2023-05-23 18:53:23 +0000 - Consider rust-version when selecting packages for cargo add (rust-lang/cargo#12078) - fix(lints): Switch to -Zlints so stable projects can experiment (rust-lang/cargo#12168) - Automatically inherit workspace fields when running cargo new/init (rust-lang/cargo#12069) - ci: check if any version bump needed for member crates (rust-lang/cargo#12126) - feat: `lints` feature (rust-lang/cargo#12148) - fix: pass `-C debuginfo` after weakening if explicitly set (rust-lang/cargo#12165) - Tweak build help to clarify role of --bin (rust-lang/cargo#12157) - fix: Pass CI on nightly (rust-lang/cargo#12160) - docs(source): doc comments for Source and its impls (rust-lang/cargo#12159) - docs(source): doc comments for `Source` and friends (rust-lang/cargo#12153) r? `@ghost`
Update cargo 10 commits in 09276c703a473ab33daaeb94917232e80eefd628..64fb38c97ac4d3a327fc9032c862dd28c8833b17 2023-05-16 21:43:35 +0000 to 2023-05-23 18:53:23 +0000 - Consider rust-version when selecting packages for cargo add (rust-lang/cargo#12078) - fix(lints): Switch to -Zlints so stable projects can experiment (rust-lang/cargo#12168) - Automatically inherit workspace fields when running cargo new/init (rust-lang/cargo#12069) - ci: check if any version bump needed for member crates (rust-lang/cargo#12126) - feat: `lints` feature (rust-lang/cargo#12148) - fix: pass `-C debuginfo` after weakening if explicitly set (rust-lang/cargo#12165) - Tweak build help to clarify role of --bin (rust-lang/cargo#12157) - fix: Pass CI on nightly (rust-lang/cargo#12160) - docs(source): doc comments for Source and its impls (rust-lang/cargo#12159) - docs(source): doc comments for `Source` and friends (rust-lang/cargo#12153) r? `@ghost`
We already discussed non-blocking gates but the language makes it sound like it was limited to `config.toml`. Since I haven't been touching that, I had always overlooked that section. This change brings the blocking / non-blocking decision front and center. To support this, the later sections focus more on mechanisms (the gate) rather than on what is being done (new syntax for `cargo-features`). I also feel this makes the content more scannable. This is adapted from what I did for `[lints]` (see rust-lang#12148).
We already discussed non-blocking gates but the language makes it sound like it was limited to `config.toml`. Since I haven't been touching that, I had always overlooked that section. This change brings the blocking / non-blocking decision front and center. To support this, the later sections focus more on mechanisms (the gate) rather than on what is being done (new syntax for `cargo-features`). I also feel this makes the content more scannable. This is adapted from what I did for `[lints]` (see rust-lang#12148).
doc(features): Highlight the non-blocking feature gating technique We already discussed non-blocking gates but the language makes it sound like it was limited to `config.toml`. Since I haven't been touching that, I had always overlooked that section. This change brings the blocking / non-blocking decision front and center. To support this, the later sections focus more on mechanisms (the gate) rather than on what is being done (new syntax for `cargo-features`). I also feel this makes the content more scannable. This is adapted from what I did for `[lints]` (see #12148).
We already discussed non-blocking gates but the language makes it sound like it was limited to `config.toml`. Since I haven't been touching that, I had always overlooked that section. This change brings the blocking / non-blocking decision front and center. To support this, the later sections focus more on mechanisms (the gate) rather than on what is being done (new syntax for `cargo-features`). I also feel this makes the content more scannable. This is adapted from what I did for `[lints]` (see rust-lang#12148).
What does this PR try to resolve?
Implement rust-lang/rfcs#3389 which shifts a subset of
.cargo/config.toml
functionality toCargo.toml
by adding a[lints]
table.This should cover all of the user-facing aspects of the RFC
::
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[lints]
table is present or malformed unless nightly with thelints
feature enabled[lints]
table is present in an existing version of rust, ignore itTracking issue for this is #12115.
How should we test and review this PR?
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 butits nightly and most likely people won't notice it? The benefit is its
in a location more like the rest of the rustflags.