-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Add new lint missing_rust_version
#14071
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 new lint missing_rust_version
#14071
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @Manishearth (or someone else) some time within the next two weeks. Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (
|
e8f79f3
to
9ca3ad9
Compare
Opened an FCP: https://rust-lang.zulipchat.com/#narrow/channel/257328-clippy/topic/FCP.3A.20missing_rust_version I wonder if this should be on by default: not all crates wish to specify an MSRV. Maybe they should anyway? I guess there's always a de facto MSRV. Slight worry is that asking people to set this might mean they set it but don't CI it and it stops working, defeating the purpose of this field. |
cc @rust-lang/cargo in case y'all have opinions on how strongly we should be nudging people here |
I do not think this lint should be added. Setting |
for package in &metadata.packages { | ||
if package.rust_version.is_none() { | ||
let message = format!("package `{}` is missing the `rust-version` field", package.name); | ||
span_lint(cx, MISSING_RUST_VERSION, DUMMY_SP, message); | ||
} | ||
} |
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.
Not an endorsement of adding this lint. Just wonder do we really mean to check every package in the dependency graph, including all deeper transitive dependencies?
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 shouldn't, yeah.
Thanks, Ed! I'm inclined to close this if the Cargo team is not super sanguine about a lint like this. It is probably worth nudging people to document MSRV, but perhaps that should be done socially rather than through Clippy. |
Note that my comment of being against this was personal and not speaking on behalf of the team but a core part of the MSRV-aware resolver RFC that the team did agree to is the importance of
The RFC also included a mechanism to allow a low-effort way of adding an MSRV, by allowing an opt-in to use the current toolchain for the MSRV (pinning it in the That should help move the ecosystem to having MSRV set more often. Due to its nature of aggressively raising the MSRV, it will cause a lot of disruption for people without the MSRV-aware resolver and I'm waiting on the MSRV-aware resolver being out a bit longer before moving forward with it. |
I think it might make sense to have this as an allow-by-default lint, to help people who want to enforce this in a workspace. But I agree that, at least for now, it shouldn't be warning by default. |
I wonder if there will be much value with allowy-by-default to outweigh the misuse. You have to enable in each workspace. You likely are also setting So it will help only if have an MSRV and are verifying your MSRV and one of
|
One problem with merging this is clippy's handling of groups. Clippy lints must only belong to one group and groups have semantic meaning except for Cargo lints. If we want something like this eventually, I would prefer waiting on rust-lang/cargo#12235 and conversations like https://rust-lang.zulipchat.com/#narrow/channel/246057-t-cargo/topic/Sharing.20of.20lints/near/475872847 |
I'm not going to advocate for it here; I primarily mean that it probably wouldn't do any harm if allow-by-default. |
Yeah, I think this lint doesn't make too much sense as allow-by-default (for the reasons given by Ed), and it appears that some Cargo team members have a decent plan for nudging the community over to always-working MSRV. I'd rather have this topic be revisited if the Cargo team wants us to do more work on this. Thanks all, for the discussion, and thanks for initiating this topic @sorairolake!
I wonder if there's value to having a |
The RFC talks about similar ideas at https://rust-lang.github.io/rfcs/3537-msrv-resolver.html#ensuring-the-registry-index-has-rust-version-without-affecting-quality |
This lint checks to see if the
rust-version
field is defined inCargo.toml
.Starting with version 3, the resolver takes this field into account when picking dependencies. The MSRV-aware resolver has been stabilized since Rust 1.84.0. I think it would be better if this field is defined in order to make more effective use of the MSRV-aware resolver. Also, I think defining this field is useful even for older versions, as it would provide clearer diagnostics about the insufficient toolchain version.
I set the MSRV of this lint to 1.58.0. This is because this field is respected as of Rust 1.56.0, but the
cargo_metadata
crate always returnsNone
if running with a version of Cargo older than 1.58.0.1Closes #14064
changelog: [
missing_rust_version
]: new lintFootnotes
https://docs.rs/cargo_metadata/0.18.1/cargo_metadata/struct.Package.html#structfield.rust_version ↩