Skip to content

Commit 66484c0

Browse files
committed
Fix clippy's const fn stability check for CURRENT_RUSTC_VERSION
Since clippy can use a projects MSRV for its lints, it might not want to consider functions as const stable if they have been added lately. Functions that have been stabilized this version use CURRENT_RUSTC_VERSION as their version, which gets then turned into the current version, which might be something like `1.66.0-dev`. The version parser cannot deal with this version, so it has to be stripped off.
1 parent aa35ab8 commit 66484c0

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/tools/clippy/clippy_utils/src/qualify_min_const_fn.rs

+12-1
Original file line numberDiff line numberDiff line change
@@ -367,10 +367,21 @@ fn is_const_fn(tcx: TyCtxt<'_>, def_id: DefId, msrv: Option<RustcVersion>) -> bo
367367
// Checking MSRV is manually necessary because `rustc` has no such concept. This entire
368368
// function could be removed if `rustc` provided a MSRV-aware version of `is_const_fn`.
369369
// as a part of an unimplemented MSRV check https://github.com/rust-lang/rust/issues/65262.
370+
371+
// HACK(nilstrieb): CURRENT_RUSTC_VERSION can return versions like 1.66.0-dev. `rustc-semver` doesn't accept
372+
// the `-dev` version number so we have to strip it off.
373+
let short_version = since
374+
.as_str()
375+
.split('-')
376+
.next()
377+
.expect("rustc_attr::StabilityLevel::Stable::since` is empty");
378+
379+
let since = rustc_span::Symbol::intern(short_version);
380+
370381
crate::meets_msrv(
371382
msrv,
372383
RustcVersion::parse(since.as_str())
373-
.expect("`rustc_attr::StabilityLevel::Stable::since` is ill-formatted"),
384+
.unwrap_or_else(|err| panic!("`rustc_attr::StabilityLevel::Stable::since` is ill-formatted: `{since}`, {err:?}")),
374385
)
375386
} else {
376387
// Unstable const fn with the feature enabled.

0 commit comments

Comments
 (0)