about summary refs log tree commit diff
diff options
context:
space:
mode:
authorNilstrieb <48135649+Nilstrieb@users.noreply.github.com>2022-09-23 21:04:54 +0200
committerNilstrieb <48135649+Nilstrieb@users.noreply.github.com>2022-09-23 21:04:54 +0200
commit66484c0a21b840b30f865e92fdd5b3bad877816f (patch)
treee2d5eba90157aa2b2d43eb10d960bd3212be1310
parentaa35ab81ea4bd427a86e0c781c342835a020e6fe (diff)
downloadrust-66484c0a21b840b30f865e92fdd5b3bad877816f.tar.gz
rust-66484c0a21b840b30f865e92fdd5b3bad877816f.zip
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.
-rw-r--r--src/tools/clippy/clippy_utils/src/qualify_min_const_fn.rs13
1 files changed, 12 insertions, 1 deletions
diff --git a/src/tools/clippy/clippy_utils/src/qualify_min_const_fn.rs b/src/tools/clippy/clippy_utils/src/qualify_min_const_fn.rs
index 405f0228683..f7ce7191772 100644
--- a/src/tools/clippy/clippy_utils/src/qualify_min_const_fn.rs
+++ b/src/tools/clippy/clippy_utils/src/qualify_min_const_fn.rs
@@ -367,10 +367,21 @@ fn is_const_fn(tcx: TyCtxt<'_>, def_id: DefId, msrv: Option<RustcVersion>) -> bo
                 // Checking MSRV is manually necessary because `rustc` has no such concept. This entire
                 // 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 since = rustc_span::Symbol::intern(short_version);
+
                 crate::meets_msrv(
                     msrv,
                     RustcVersion::parse(since.as_str())
-                        .expect("`rustc_attr::StabilityLevel::Stable::since` is ill-formatted"),
+                        .unwrap_or_else(|err| panic!("`rustc_attr::StabilityLevel::Stable::since` is ill-formatted: `{since}`, {err:?}")),
                 )
             } else {
                 // Unstable const fn with the feature enabled.