Skip to content

Automatically set MSRV for code under #[cfg(version)] #14940

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Alexendoo
Copy link
Member

Fixes #14827

Semantics:

  • If there is both #[clippy::msrv] and #[cfg(version)] applying to the same node #[clippy::msrv] wins
  • When negated with not() version bounds are ignored (if double/quad/etc negated it will be applied once more)
  • Inside all/any the lowest found version is used

When the feature is stable we can go back and improve the docs a bit more with a better example

changelog: code using #[cfg(version)] will have the MSRV automatically detected

@rustbot
Copy link
Collaborator

rustbot commented May 31, 2025

r? @samueltardieu

rustbot has assigned @samueltardieu.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label May 31, 2025
Copy link
Contributor

@samueltardieu samueltardieu left a comment

Choose a reason for hiding this comment

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

This LGTM with the nit and the extra test. I'll let @flip1995 do the final check since he wants to be involved the the book is modified.

return Some(version);
let mut first_clippy_attr = None;
let mut clippy_msrv = None;
let mut cfg_version: Option<RustcVersion> = None;
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit, this looks strange to have only one ascribed variable.

Suggested change
let mut cfg_version: Option<RustcVersion> = None;
let mut cfg_version = None;

Comment on lines 27 to 40
#[clippy::msrv = "1.40"]
#[cfg(version("1.80"))]
fn both_attributes(i: i32) {
// if both are specified on the same node then `clippy::msrv` takes precedence
let _ = i.isqrt();
//~^ ERROR: is `1.40.0`
}
Copy link
Contributor

Choose a reason for hiding this comment

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

As a non-regression test, could you duplicate this test and reverse both versions (because here clippy::msrv is also the smaller one)?

@samueltardieu
Copy link
Contributor

r? @flip1995

@samueltardieu
Copy link
Contributor

Thanks.

@samueltardieu samueltardieu added this pull request to the merge queue Jun 1, 2025
@samueltardieu samueltardieu removed this pull request from the merge queue due to a manual request Jun 1, 2025
@samueltardieu
Copy link
Contributor

Sorry, I forgot I wanted to let @flip1995 weight in.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties
Projects
None yet
Development

Successfully merging this pull request may close these issues.

incompatible_msrv doesn't respect #[cfg(version(...))]
4 participants