|
5 | 5 |
|
6 | 6 | use crate::msrvs::Msrv;
|
7 | 7 | use hir::LangItem;
|
| 8 | +use rustc_attr::{rust_version_symbol, Since}; |
8 | 9 | use rustc_const_eval::transform::check_consts::ConstCx;
|
9 | 10 | use rustc_hir as hir;
|
10 | 11 | use rustc_hir::def_id::DefId;
|
@@ -370,19 +371,25 @@ fn is_const_fn(tcx: TyCtxt<'_>, def_id: DefId, msrv: &Msrv) -> bool {
|
370 | 371 | // function could be removed if `rustc` provided a MSRV-aware version of `is_const_fn`.
|
371 | 372 | // as a part of an unimplemented MSRV check https://github.com/rust-lang/rust/issues/65262.
|
372 | 373 |
|
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 | + }; |
380 | 391 |
|
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) |
386 | 393 | } else {
|
387 | 394 | // Unstable const fn with the feature enabled.
|
388 | 395 | msrv.current().is_none()
|
|
0 commit comments