Skip to content

feature request: #[feature] awareness in MSRV-gated lints #14477

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
tamird opened this issue Mar 26, 2025 · 3 comments
Open

feature request: #[feature] awareness in MSRV-gated lints #14477

tamird opened this issue Mar 26, 2025 · 3 comments

Comments

@tamird
Copy link
Contributor

tamird commented Mar 26, 2025

Some lints, such as borrow_as_ptr have conditional behavior based on MSRV:

let (suggestion, span) = if msrv.meets(cx, msrvs::RAW_REF_OP) {

In Rust-for-Linux, this is not sufficient because we enable a number of unstable features when we are reasonably confident their behavior won't change before stabilization, or because we know they have been stabilized without API change in a version that exceeds our configured MSRV.

It would be extremely helpful if these MSRV checks could be taught to also respect #[feature] attributes that enable unstable features ahead of the MSRV having been met. This is especially tricky when API has actually changed between the configured MSRV and the feature's actual stabilization.

@ojeda
Copy link
Contributor

ojeda commented Mar 26, 2025

Cc Rust-for-Linux/linux#1152.

I assume this could work with a list of unstable features (or perhaps a list of lints that would ignore the msrv behavior).

In any case, if it is tricky to do this, then I guess we could for the time being avoid using the msrv field -- some notes at Rust-for-Linux/linux#1152 (comment). Eventually we will not use unstable features like today, so it is not a critical feature, but it would be nice to be able to use unstable features without having to lose the msrv feature.

because we enable a number of unstable features

To clarify, we also use a few others in https://github.com/Rust-for-Linux/linux/blob/edc5e6e019c99b529b3d1f2801d5cce9924ae79b/rust/kernel/lib.rs#L16-L42 (and for derive_coerce_pointee we have to do it conditionally).

@samueltardieu
Copy link
Contributor

We can check for enabled features for features that are probably stable indeed. We already do that, for example in the manual_div_ceil lint: we lint on unsigned integers manual div_ceil() provided the MSRV is ok, and on signed integers as well if the int_roundings feature is enabled, because div_ceil() on signed integers is still unstable.

Is that what you need? If this is, don't hesitate to request such additions on a lint+feature basis, as a feature request (ah ah).

@ojeda
Copy link
Contributor

ojeda commented May 18, 2025

Yeah, so e.g. for us borrow_as_ptr would ideally suggest &raw instead of addr_of*! because we use #![feature(raw_ref_op)], but it doesn't because we say msrv = "1.78.0".

For Linux we don't have many cases -- we are now fairly close to stable (I updated the link above since there was a cleanup that makes it more readable). Doing it for at least (borrow_as_ptr, raw_ref_op) would help.

Thanks!

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants