-
Notifications
You must be signed in to change notification settings - Fork 1.6k
update readme for specifying msrv #6379
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -194,6 +194,32 @@ cargo clippy -- -A clippy::all -W clippy::useless_format -W clippy::... | |
``` | ||
Note that if you've run clippy before, this may only take effect after you've modified a file or ran `cargo clean`. | ||
|
||
### Specifying the minimum supported Rust version | ||
|
||
Projects that intend to support old versions of Rust can disable lints pertaining to newer features by | ||
specifying the minimum supported Rust version (MSRV) in the clippy configuration file. | ||
|
||
```toml | ||
msrv = "1.30.0" | ||
``` | ||
|
||
The MSRV can also be specified as an inner attribute, like below. | ||
|
||
```rust | ||
#![feature(custom_inner_attributes)] | ||
#![clippy::msrv = "1.30.0"] | ||
|
||
fn main() { | ||
... | ||
} | ||
``` | ||
|
||
Tilde/Caret version requirements (like `^1.0` or `~1.2`) can be specified as well. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IIRC There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I looked at how rustc's I've commented about an alternative parser implementation, but I think that is probably sufficient for Clippy's use cases as well. If so, it may be preferable to use that instead of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't see why the additional options to specify a version should be problematic. If you want to misuse those, that's on you. But I agree, that we should not mention that this is possible, otherwise it invites people to misuse it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @taiki-e yeah, the MSRV should definitely not be a range so tilde requirements don't make sense but, I don't think e.g. In the snippet below, switching between use semver::{Version, VersionReq};
fn main() {
const MANUAL_STRIP_MSRV: Version = Version {
major: 1,
minor: 45,
patch: 0,
pre: Vec::new(),
build: Vec::new(),
};
match VersionReq::parse("1.30") {
Ok(vReq) => {
if !vReq.matches(&MANUAL_STRIP_MSRV) {
println!("Will lint!")
} else {
println!("Won't lint!")
}
},
Err(_) => println!("Error")
}
} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @suyash458: Good catch! I didn't know that behavior. Given that cargo treats them as the same requirements, I think it's preferable to treat the same as cargo. @flip1995: I agree with it is a user issue, but the more things that can be accepted, the more complicated the test will be. I think it is preferable to accept only the minimum necessary things if possible. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Well we use the semver crate, so this crate should have the tests, that the version matching works, so we can just assume, that it works. (And semver has indeed many unit tests) Contrary to that: The semver documentation for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
||
Note: `custom_inner_attributes` is an unstable feature so it has to be enabled explicitly. | ||
|
||
Lints that recognize this configuration option can be found [here](https://rust-lang.github.io/rust-clippy/master/index.html#msrv) | ||
|
||
## Contributing | ||
|
||
If you want to contribute to Clippy, you can find more information in [CONTRIBUTING.md](https://github.com/rust-lang/rust-clippy/blob/master/CONTRIBUTING.md). | ||
|
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.
IIUC the #6201 implementation does not consider the exact patch version, so I think it is preferable to always omit the patch version in the documentation.
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.
It does, if you specify it. So if you specify
msrv = 1.30.0
and a lint is marked as1.30.1
this lint will not trigger. The thing is, that features don't usually get stabilized in a patch version, so no lint will probably ever have a patch version>0
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.
Oh, I didn't realize it was possible with the current implementation. Thanks for pointing it out.
Yeah, this is what I actually wanted to say. (There was a case where stabilization was reverted in a patch version due to a security vulnerability, but I don't think there were any cases where new APIs were stabilized.)