Skip to content

Commit fd8907f

Browse files
committed
Handle structured stable attribute 'since' version in clippy
1 parent 6933a67 commit fd8907f

File tree

1 file changed

+19
-12
lines changed

1 file changed

+19
-12
lines changed

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

+19-12
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
use crate::msrvs::Msrv;
77
use hir::LangItem;
8+
use rustc_attr::{rust_version_symbol, Since};
89
use rustc_const_eval::transform::check_consts::ConstCx;
910
use rustc_hir as hir;
1011
use rustc_hir::def_id::DefId;
@@ -370,19 +371,25 @@ fn is_const_fn(tcx: TyCtxt<'_>, def_id: DefId, msrv: &Msrv) -> bool {
370371
// function could be removed if `rustc` provided a MSRV-aware version of `is_const_fn`.
371372
// as a part of an unimplemented MSRV check https://github.com/rust-lang/rust/issues/65262.
372373

373-
// HACK(nilstrieb): CURRENT_RUSTC_VERSION can return versions like 1.66.0-dev. `rustc-semver`
374-
// doesn't accept the `-dev` version number so we have to strip it off.
375-
let short_version = since
376-
.as_str()
377-
.split('-')
378-
.next()
379-
.expect("rustc_attr::StabilityLevel::Stable::since` is empty");
374+
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 current_rustc_version = rust_version_symbol();
384+
let short_version = current_rustc_version.as_str().split('-').next().unwrap();
385+
RustcVersion::parse(short_version).unwrap_or_else(|err| {
386+
panic!("`rustc_attr::StabilityLevel::Stable::since` is ill-formatted: `{current_rustc_version}`, {err:?}")
387+
})
388+
},
389+
Since::Err => return false,
390+
};
380391

381-
let since = rustc_span::Symbol::intern(short_version);
382-
383-
msrv.meets(RustcVersion::parse(since.as_str()).unwrap_or_else(|err| {
384-
panic!("`rustc_attr::StabilityLevel::Stable::since` is ill-formatted: `{since}`, {err:?}")
385-
}))
392+
msrv.meets(const_stab_rust_version)
386393
} else {
387394
// Unstable const fn with the feature enabled.
388395
msrv.current().is_none()

0 commit comments

Comments
 (0)