Skip to content

Commit d736992

Browse files
committed
Parse rustc version at compile time
1 parent 3e05710 commit d736992

File tree

1 file changed

+8
-15
lines changed

1 file changed

+8
-15
lines changed

clippy_utils/src/qualify_min_const_fn.rs

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
use crate::msrvs::Msrv;
77
use hir::LangItem;
8-
use rustc_attr::{Since, CURRENT_RUSTC_VERSION};
8+
use rustc_attr::Since;
99
use rustc_const_eval::transform::check_consts::ConstCx;
1010
use rustc_hir as hir;
1111
use rustc_hir::def_id::DefId;
@@ -372,23 +372,16 @@ fn is_const_fn(tcx: TyCtxt<'_>, def_id: DefId, msrv: &Msrv) -> bool {
372372
// as a part of an unimplemented MSRV check https://github.com/rust-lang/rust/issues/65262.
373373

374374
let const_stab_rust_version = match since {
375-
Since::Version(version) => RustcVersion::new(
376-
u32::from(version.major),
377-
u32::from(version.minor),
378-
u32::from(version.patch),
379-
),
380-
Since::Current => {
381-
// HACK(nilstrieb): CURRENT_RUSTC_VERSION can return versions like 1.66.0-dev.
382-
// `rustc-semver` doesn't accept the `-dev` version number so we have to strip it off.
383-
let short_version = CURRENT_RUSTC_VERSION.split('-').next().unwrap();
384-
RustcVersion::parse(short_version).unwrap_or_else(|err| {
385-
panic!("`rustc_attr::StabilityLevel::Stable::since` is ill-formatted: `{CURRENT_RUSTC_VERSION}`, {err:?}")
386-
})
387-
},
375+
Since::Version(version) => version,
376+
Since::Current => rustc_session::RustcVersion::CURRENT,
388377
Since::Err => return false,
389378
};
390379

391-
msrv.meets(const_stab_rust_version)
380+
msrv.meets(RustcVersion::new(
381+
u32::from(const_stab_rust_version.major),
382+
u32::from(const_stab_rust_version.minor),
383+
u32::from(const_stab_rust_version.patch),
384+
))
392385
} else {
393386
// Unstable const fn with the feature enabled.
394387
msrv.current().is_none()

0 commit comments

Comments
 (0)