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

feat: lints feature #12148

Merged
merged 19 commits into from
May 22, 2023
Merged

feat: lints feature #12148

merged 19 commits into from
May 22, 2023

Conversation

epage
Copy link
Contributor

@epage epage commented May 17, 2023

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.

@rustbot
Copy link
Collaborator

rustbot commented May 17, 2023

r? @weihanglo

(rustbot has picked a reviewer for you, use r? to override)

@rustbot rustbot added A-build-execution Area: anything dealing with executing the compiler A-documenting-cargo-itself Area: Cargo's documentation A-manifest Area: Cargo.toml issues A-rebuild-detection Area: rebuild detection and fingerprinting A-unstable Area: nightly unstable support S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 17, 2023
Copy link
Member

@weihanglo weihanglo left a 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.

src/doc/src/reference/unstable.md Outdated Show resolved Hide resolved
src/doc/src/reference/unstable.md Outdated Show resolved Hide resolved
src/doc/src/reference/unstable.md Outdated Show resolved Hide resolved
src/doc/src/reference/unstable.md Outdated Show resolved Hide resolved
Example:

```toml
# [PROJECT_DIR]/Cargo.toml
Copy link
Member

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 😆

Suggested change
# [PROJECT_DIR]/Cargo.toml
# [WORKSPACE_DIR]/Cargo.toml

Copy link
Contributor Author

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/core/compiler/mod.rs Outdated Show resolved Hide resolved
src/doc/src/reference/unstable.md Show resolved Hide resolved
src/doc/src/reference/unstable.md Show resolved Hide resolved
lints.try_into().map(Some).map_err(|err| err.into())
}

fn warn_for_feature(name: &str, config: &Config) {
Copy link
Member

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?
  • Will the user get a warning from each dependency having lints table?

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 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

@epage epage force-pushed the lints branch 4 times, most recently from 9759d86 to 02f96ea Compare May 19, 2023 21:24
Copy link
Member

@weihanglo weihanglo left a 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.

src/cargo/core/compiler/mod.rs Outdated Show resolved Hide resolved
src/cargo/core/compiler/fingerprint/mod.rs Outdated Show resolved Hide resolved
src/cargo/util/toml/mod.rs Outdated Show resolved Hide resolved
@@ -0,0 +1,603 @@
//! Tests for `[lints]`
Copy link
Member

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.

Copy link
Contributor Author

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 Show resolved Hide resolved
tests/testsuite/lints.rs Outdated Show resolved Hide resolved
.build();

foo.cargo("check")
.arg("-v")
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
.arg("-v")

Not needed and elsewhere ditto.

Copy link
Contributor Author

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.

tests/testsuite/lints.rs Outdated Show resolved Hide resolved
}

#[cargo_test]
fn rustdoc_lint() {
Copy link
Member

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?

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 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!)

tests/testsuite/lints.rs Show resolved Hide resolved
@epage epage force-pushed the lints branch 3 times, most recently from c52d691 to 9ffa303 Compare May 22, 2023 14:32
@epage epage force-pushed the lints branch 2 times, most recently from 8d4f929 to ccf5c64 Compare May 22, 2023 15:18
…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 | ✓ | ✓
Copy link
Member

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:

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?

Copy link
Member

@weihanglo weihanglo left a 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.

@weihanglo
Copy link
Member

@bors r+

@bors
Copy link
Contributor

bors commented May 22, 2023

📌 Commit b435eda has been approved by weihanglo

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 22, 2023
@bors
Copy link
Contributor

bors commented May 22, 2023

⌛ Testing commit b435eda with merge e5e68c4...

@bors
Copy link
Contributor

bors commented May 22, 2023

☀️ Test successful - checks-actions
Approved by: weihanglo
Pushing e5e68c4 to master...

1 similar comment
@bors
Copy link
Contributor

bors commented May 22, 2023

☀️ Test successful - checks-actions
Approved by: weihanglo
Pushing e5e68c4 to master...

@bors
Copy link
Contributor

bors commented May 22, 2023

👀 Test was successful, but fast-forwarding failed: 422 Changes must be made through a pull request.

@bors bors merged commit e5e68c4 into rust-lang:master May 22, 2023
@epage epage deleted the lints branch May 22, 2023 21:11
bors added a commit to rust-lang-ci/rust that referenced this pull request May 23, 2023
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`
saethlin pushed a commit to saethlin/miri that referenced this pull request May 26, 2023
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`
@ehuss ehuss added this to the 1.71.0 milestone May 30, 2023
@weihanglo weihanglo added the A-lints-table Area: [lints] table label Jun 13, 2023
epage added a commit to epage/cargo that referenced this pull request Jan 16, 2024
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).
epage added a commit to epage/cargo that referenced this pull request Jan 16, 2024
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).
bors added a commit that referenced this pull request Jan 16, 2024
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).
stupendoussuperpowers pushed a commit to stupendoussuperpowers/cargo that referenced this pull request Feb 28, 2024
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).
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-documenting-cargo-itself Area: Cargo's documentation A-lints-table Area: [lints] table A-manifest Area: Cargo.toml issues A-rebuild-detection Area: rebuild detection and fingerprinting A-unstable Area: nightly unstable support S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants