mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-23 13:13:34 +00:00
Handle structured stable attribute 'since' version in clippy
This commit is contained in:
parent
cd6ec97f0d
commit
f4f5b05cbb
1 changed files with 19 additions and 12 deletions
|
@ -5,6 +5,7 @@
|
|||
|
||||
use crate::msrvs::Msrv;
|
||||
use hir::LangItem;
|
||||
use rustc_attr::{rust_version_symbol, Since};
|
||||
use rustc_const_eval::transform::check_consts::ConstCx;
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::def_id::DefId;
|
||||
|
@ -370,19 +371,25 @@ fn is_const_fn(tcx: TyCtxt<'_>, def_id: DefId, msrv: &Msrv) -> bool {
|
|||
// function could be removed if `rustc` provided a MSRV-aware version of `is_const_fn`.
|
||||
// as a part of an unimplemented MSRV check https://github.com/rust-lang/rust/issues/65262.
|
||||
|
||||
// HACK(nilstrieb): CURRENT_RUSTC_VERSION can return versions like 1.66.0-dev. `rustc-semver`
|
||||
// doesn't accept the `-dev` version number so we have to strip it off.
|
||||
let short_version = since
|
||||
.as_str()
|
||||
.split('-')
|
||||
.next()
|
||||
.expect("rustc_attr::StabilityLevel::Stable::since` is empty");
|
||||
let const_stab_rust_version = match since {
|
||||
Since::Version(version) => RustcVersion::new(
|
||||
u32::from(version.major),
|
||||
u32::from(version.minor),
|
||||
u32::from(version.patch),
|
||||
),
|
||||
Since::Current => {
|
||||
// HACK(nilstrieb): CURRENT_RUSTC_VERSION can return versions like 1.66.0-dev.
|
||||
// `rustc-semver` doesn't accept the `-dev` version number so we have to strip it off.
|
||||
let current_rustc_version = rust_version_symbol();
|
||||
let short_version = current_rustc_version.as_str().split('-').next().unwrap();
|
||||
RustcVersion::parse(short_version).unwrap_or_else(|err| {
|
||||
panic!("`rustc_attr::StabilityLevel::Stable::since` is ill-formatted: `{current_rustc_version}`, {err:?}")
|
||||
})
|
||||
},
|
||||
Since::Err => return false,
|
||||
};
|
||||
|
||||
let since = rustc_span::Symbol::intern(short_version);
|
||||
|
||||
msrv.meets(RustcVersion::parse(since.as_str()).unwrap_or_else(|err| {
|
||||
panic!("`rustc_attr::StabilityLevel::Stable::since` is ill-formatted: `{since}`, {err:?}")
|
||||
}))
|
||||
msrv.meets(const_stab_rust_version)
|
||||
} else {
|
||||
// Unstable const fn with the feature enabled.
|
||||
msrv.current().is_none()
|
||||
|
|
Loading…
Reference in a new issue