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

Add a [lints] table to Cargo.toml #3389

Merged
merged 64 commits into from
May 9, 2023
Merged

Add a [lints] table to Cargo.toml #3389

merged 64 commits into from
May 9, 2023

Conversation

epage
Copy link
Contributor

@epage epage commented Feb 15, 2023

This proposal is trying to make it easier managing project-specific lint overrides.

Rendered (book)

@epage epage added the T-cargo Relevant to the Cargo team, which will review and decide on the RFC. label Feb 15, 2023
@xFrednet
Copy link
Member

xFrednet commented Feb 15, 2023

Thank you for creating the RFC. I think this would be interesting for everyone in Clippy as well. Adding an option to configure lints has been requested several times :)

cc: @rust-lang/clippy :)

Copy link
Member

@Manishearth Manishearth left a comment

Choose a reason for hiding this comment

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

I'm excited for this! I was getting pretty close to just proposing this for clippy.toml after there wasn't movement on the cargo.toml front, so this is nice to see!

lint and `threshold` is used by the tool. We'd need to define how to
distinguish between reserved and unreserved field names.

## Extending the syntax to `.cargo/config.toml`
Copy link
Member

Choose a reason for hiding this comment

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

I actually think this is probably necessary for this RFC to make sense. I feel this makes more sense in the local (potentially-but-not-necessarily checked-in) config as opposed to the crate config.

Copy link
Member

Choose a reason for hiding this comment

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

Though with workspace inheritance perhaps it's not that necessary.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Could you clarify why you feel it makes more sense to put this in .cargo/config.toml over Cargo.toml?

In starting this with Cargo.toml, I'm looking to address the existing problems with doing this via rustflags in .cargo/config.toml (project configuration being directory dependent). EmbarkStudios/rust-ecosystem#59 is a good example of people using both source code and .cargo/config.toml for lints that are project-specific and would benefit from this. This was also spurred by the cargo team itself wanting to use this feature.

Copy link
Member

Choose a reason for hiding this comment

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

I think it makes sense to allow it in both.

The reason being that there are multiple lint workflows: sometimes you lint in CI and want everyone to follow the same lint set. However, some people may wish to opt in to additional lints locally for their own code, and being able to set that is useful.

But I'm fine with starting out in Cargo.toml at least. I would prefer to try and solve it for both.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The reason being that there are multiple lint workflows: sometimes you lint in CI and want everyone to follow the same lint set. However, some people may wish to opt in to additional lints locally for their own code, and being able to set that is useful.

The part I'm missing is why users can't just use rustflags for this in the short term? In the long term, if we add configurable lints, there isn't an alternative and I can see it becoming a higher priority then. This is the main reason I put it as a future possibility, rather than including it.

Copy link
Contributor

Choose a reason for hiding this comment

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

When you are cross-compiling, there is no way to set rustflags via .config/cargo.toml that applies to everything (built for host or built for target), so even just for having something that works across proc-macros and normal crates within a workspace, this would be great.

Choose a reason for hiding this comment

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

We will still be fingerprinting [lints] and causing rebuilds

Why? Lints don't affect the compiled binaries. It seems like pure overhead to me.


While I'd want to be able to set lints globally (for every project on my computer), there is a design issue of config priority which is unclear to me. Currently afaik the only option duplicated in both config.toml and Cargo.toml is [profile], and in its case the config.toml has priority. In particular, a [profile] section in $HOME/.cargo/config.toml would override the [profile] in any other Cargo project.

That may be reasonable for [profile], but would likely be incorrect for lints. Most of the time I'd want to use the lints from the specific project I work on, with the config.toml defaults (particularly defined in non-project directories) used only occasionally. So the correct priority looks like $WORKSPACE/.cargo/config.toml > $WORKSPACE/subcrate/Cargo.toml > $WORKSPACE/Cargo.toml > $UPPER_DIR/.cargo/config.toml. This looks a bit convoluted and inconsistent with the behaviour of other config.toml keys.

Maybe there should be a cargo command-line flag which would control whether Cargo.toml or config.toml lint settings should be used?

Actually, if cargo build/run/test would have flags to set lint levels per invocation, that would be sufficient. That would also avoid the question of config priorities.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Why? Lints don't affect the compiled binaries. It seems like pure overhead to me.

If a user adds additional lints and run cargo check, they would expect to see the result of those lints. This would only be possible by rebuilding which will require finger printing.

While I'd want to be able to set lints globally (for every project on my computer), there is a design issue of config priority which is unclear to me.

For now, I am leaving [lints] for .cargo/config.toml as a future possibility rather than removing it or making it required to move this proposal along. Keeping it as a future possibility has no cost. Adding it into the proposal has a larger cost, in design, decision making, and implementation. It would require a very strong motivation to block incremental improvement ([lints] in Cargo.toml) on getting a full solution (e.g. including [lints] in .cargo/config.toml).

With that context, maybe we can temper how much design work we put into the feature or how much we debate whether we should or shouldn't do it in the future.

Choose a reason for hiding this comment

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

Sure, I wouldn't want future extensions to block this long-waited feature either.

When you say "rebuilding", do you mean rebuilding the workspace crates or all dependencies? I am most concerned about the latter, even though for large projects there could be no difference. I am not familiar with the inner details of cargo check.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When you say "rebuilding", do you mean rebuilding the workspace crates or all dependencies?

Rebuilding the package when its [lints] table changes and not its dependencies.
When writing up my previous message, I realized this was ambiguous in the RFC and I have since clarified it.

text/3389-manifest-lint.md Outdated Show resolved Hide resolved
text/3389-manifest-lint.md Show resolved Hide resolved
text/3389-manifest-lint.md Outdated Show resolved Hide resolved
text/3389-manifest-lint.md Show resolved Hide resolved
text/3389-manifest-lint.md Outdated Show resolved Hide resolved
text/3389-manifest-lint.md Outdated Show resolved Hide resolved
text/3389-manifest-lint.md Outdated Show resolved Hide resolved
Comment on lines 174 to 244
Instead of traditional workspace inheritance where there is a single value to
inherit with `workspace = true`, we could have `[workspace.lints.<preset>]`
which defines presets and the user could do `lints.<preset> = true`. The user
could then name them as they wish to avoid collision with rustc lints.
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 wanted to call attention to this item. Would presets or custom lint groups of interest enough for us to design around?

Comment on lines 214 to 218
How should we hand rustdoc lint levels or, in the future, cargo lint levels?
The current proposal takes all lints and passes them to rustc like `RUSTFLAGS`
but rustdoc uses `RUSTDOCFLAGS` and cargo would use neither. This also starts
to get into
[user-defined tool attributes](https://rust-lang.github.io/rfcs/2103-tool-attributes.html).
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Would it work for cargo to just hard code what lint tool goes to what CLI?

The problem is then dealing with the potential future state of third-party lint tools. If those were opted into via cargo instead of a source-level attribute, we might be able to get the information we need to direct the lints to the appropriate CLI (or ignore as needed)

Copy link
Member

Choose a reason for hiding this comment

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

Couldn't cargo always pass all lints defined in the [lint] section to all tools? If a tool is not used and therefore not registered with rustc, rustc will just ignore that lint and that it was passed to it. Or am I misunderstanding the problem? 🤔

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 not touched that side of things so I am unsure if that would be a problem or not.

ehuss also brought up the possibility of using this to minimize which lints are included in fingerprinting for reducing recompiles for lint changes (e.g. adding clippy lints doesn't cause cargo build to rebuild). Its mentioned in the RFC just after this paragraph.

@rfcbot rfcbot removed the proposed-final-comment-period Currently awaiting signoff of all team members in order to enter the final comment period. label Apr 29, 2023
@rfcbot
Copy link
Collaborator

rfcbot commented Apr 29, 2023

🔔 This is now entering its final comment period, as per the review above. 🔔

@rfcbot rfcbot added finished-final-comment-period The final comment period is finished for this RFC. to-announce and removed final-comment-period Will be merged/postponed/closed in ~10 calendar days unless new substational objections are raised. labels May 9, 2023
@rfcbot
Copy link
Collaborator

rfcbot commented May 9, 2023

The final comment period, with a disposition to merge, as per the review above, is now complete.

As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed.

This will be merged soon.

@ehuss ehuss merged commit 51fd0be into rust-lang:master May 9, 2023
@ehuss
Copy link
Contributor

ehuss commented May 9, 2023

Huzzah! The @rust-lang/cargo team has decided to accept this RFC.

To track further discussion, subscribe to the tracking issue here:
rust-lang/cargo#12115

@epage epage deleted the lints branch May 9, 2023 15:59
bors added a commit to rust-lang/cargo that referenced this pull request May 22, 2023
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.
@epage epage added the call-for-testing Add this label + test notes in comments to be included in TWiR `Call for Testing` section. label May 25, 2023
@epage
Copy link
Contributor Author

epage commented May 25, 2023

Testing instructions

Requires

  • nightly: nightly-2023-05-25 or newer
  • beta
  • stable

Steps:

  1. Switch from attributes to [lints] table per the unstable reference
  • -Dwarnings should likely still be passed in explicitly so local experimentation doesn't get blocked on perfection
  • CI jobs passing in -Adeprecations likely should still do so since users should see deprecation warnings locally to decide whether to address them
  1. Verify lints in CI with a supported compiler by adding the -Zlints flag

Example: rust-lang/cargo#12178

Please leave feedback on rust-lang/cargo#12115

@U007D
Copy link

U007D commented May 30, 2023

This Tracking Issue will appear in the Call for Testing section of the next issue (# 497) of This Week in Rust (TWiR).

I have removed the call-for-testing label. Please feel free to re-add the call-for-testing label if you would like this RFC to appear again in another issue of TWiR.

@U007D U007D removed the call-for-testing Add this label + test notes in comments to be included in TWiR `Call for Testing` section. label May 30, 2023
Erenoit added a commit to Erenoit/discord-bot that referenced this pull request Sep 11, 2023
new cargo feature has became stable at nightly:
<rust-lang/rfcs#3389 (comment)>
DCNick3 added a commit to DCNick3/iroha that referenced this pull request Sep 20, 2023
…intained cargo-lints

Since the implementation of rust-lang/rfcs#3389, it is now possible to specify workspace-level lints for rustc and clippy. This PR updates the cargo configuration and CI to use this new feature instead of cargo-lints.

Note that it was only stabilized in `nightly-2023-09-10`. Using it with out current toolchain requires either a -Zlints flag or a modification to `.cargo/config.toml`:

```
[unstable]
lints = true
```

Note that unlike the original suggestion in hyperledger-iroha#3622, this doesn't make the lints crate level, but merely replaces a clunky unmaintained tool with a standard solution for configuring lints.

In particular this PR:
- Removes old lints.toml configuration files for cargo-lints
- Adds [lint] tables to Cargo.toml of the root and wasm workspaces. The lints are duplicated between the two
- Replaces `cargo lints clippy` invocations with `cargo clippy -Zlints` in CI scripts
- Silences/fixes some new lints that popped up due to differences in how between `cargo lints` and workspaces
- Does a drive-by fix to iroha_genesis: it now too shares cargo metadata as do other crates

Signed-off-by: Nikita Strygin <[email protected]>
DCNick3 added a commit to hyperledger-iroha/iroha that referenced this pull request Sep 21, 2023
Since the implementation of rust-lang/rfcs#3389, it is now possible to specify workspace-level lints for rustc and clippy. This PR updates the cargo configuration and CI to use this new feature instead of cargo-lints.

Note that it was only stabilized in `nightly-2023-09-10`. Using it with out current toolchain requires either a -Zlints flag or a modification to `.cargo/config.toml`:

```
[unstable]
lints = true
```

Note that unlike the original suggestion in #3622, this doesn't make the lints crate level, but merely replaces a clunky unmaintained tool with a standard solution for configuring lints.

In particular this PR:
- Removes old lints.toml configuration files for cargo-lints
- Adds [lint] tables to Cargo.toml of the root and wasm workspaces. The lints are duplicated between the two
- Replaces `cargo lints clippy` invocations with `cargo clippy -Zlints` in CI scripts
- Silences/fixes some new lints that popped up due to differences in how between `cargo lints` and workspaces
- Does a drive-by fix to iroha_genesis: it now too shares cargo metadata as do other crates

Signed-off-by: Nikita Strygin <[email protected]>
6r1d pushed a commit to hyperledger-iroha/iroha that referenced this pull request Oct 17, 2023
Since the implementation of rust-lang/rfcs#3389, it is now possible to specify workspace-level lints for rustc and clippy. This PR updates the cargo configuration and CI to use this new feature instead of cargo-lints.

Note that it was only stabilized in `nightly-2023-09-10`. Using it with out current toolchain requires either a -Zlints flag or a modification to `.cargo/config.toml`:

```
[unstable]
lints = true
```

Note that unlike the original suggestion in #3622, this doesn't make the lints crate level, but merely replaces a clunky unmaintained tool with a standard solution for configuring lints.

In particular this PR:
- Removes old lints.toml configuration files for cargo-lints
- Adds [lint] tables to Cargo.toml of the root and wasm workspaces. The lints are duplicated between the two
- Replaces `cargo lints clippy` invocations with `cargo clippy -Zlints` in CI scripts
- Silences/fixes some new lints that popped up due to differences in how between `cargo lints` and workspaces
- Does a drive-by fix to iroha_genesis: it now too shares cargo metadata as do other crates

Signed-off-by: Nikita Strygin <[email protected]>
6r1d pushed a commit to hyperledger-iroha/iroha that referenced this pull request Oct 17, 2023
Since the implementation of rust-lang/rfcs#3389, it is now possible to specify workspace-level lints for rustc and clippy. This PR updates the cargo configuration and CI to use this new feature instead of cargo-lints.

Note that it was only stabilized in `nightly-2023-09-10`. Using it with out current toolchain requires either a -Zlints flag or a modification to `.cargo/config.toml`:

```
[unstable]
lints = true
```

Note that unlike the original suggestion in #3622, this doesn't make the lints crate level, but merely replaces a clunky unmaintained tool with a standard solution for configuring lints.

In particular this PR:
- Removes old lints.toml configuration files for cargo-lints
- Adds [lint] tables to Cargo.toml of the root and wasm workspaces. The lints are duplicated between the two
- Replaces `cargo lints clippy` invocations with `cargo clippy -Zlints` in CI scripts
- Silences/fixes some new lints that popped up due to differences in how between `cargo lints` and workspaces
- Does a drive-by fix to iroha_genesis: it now too shares cargo metadata as do other crates

Signed-off-by: Nikita Strygin <[email protected]>
mversic pushed a commit to hyperledger-iroha/iroha that referenced this pull request Oct 17, 2023
Since the implementation of rust-lang/rfcs#3389, it is now possible to specify workspace-level lints for rustc and clippy. This PR updates the cargo configuration and CI to use this new feature instead of cargo-lints.

Note that it was only stabilized in `nightly-2023-09-10`. Using it with out current toolchain requires either a -Zlints flag or a modification to `.cargo/config.toml`:

```
[unstable]
lints = true
```

Note that unlike the original suggestion in #3622, this doesn't make the lints crate level, but merely replaces a clunky unmaintained tool with a standard solution for configuring lints.

In particular this PR:
- Removes old lints.toml configuration files for cargo-lints
- Adds [lint] tables to Cargo.toml of the root and wasm workspaces. The lints are duplicated between the two
- Replaces `cargo lints clippy` invocations with `cargo clippy -Zlints` in CI scripts
- Silences/fixes some new lints that popped up due to differences in how between `cargo lints` and workspaces
- Does a drive-by fix to iroha_genesis: it now too shares cargo metadata as do other crates

Signed-off-by: Nikita Strygin <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
disposition-merge This RFC is in PFCP or FCP with a disposition to merge it. finished-final-comment-period The final comment period is finished for this RFC. T-cargo Relevant to the Cargo team, which will review and decide on the RFC. to-announce
Projects
No open projects
Status: Done (Stabilized)
Development

Successfully merging this pull request may close these issues.