Skip to content

Commit bedf004

Browse files
committed
Expose a non-Symbol way to access current rustc version string
1 parent 51f7fba commit bedf004

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

compiler/rustc_attr/src/builtin.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@ use crate::session_diagnostics::{self, IncorrectReprFormatGenericCause};
2424
/// For more, see [this pull request](https://github.com/rust-lang/rust/pull/100591).
2525
pub const VERSION_PLACEHOLDER: &str = "CURRENT_RUSTC_VERSION";
2626

27+
pub const CURRENT_RUSTC_VERSION: &str = env!("CFG_RELEASE");
28+
2729
pub fn rust_version_symbol() -> Symbol {
28-
Symbol::intern(env!("CFG_RELEASE"))
30+
Symbol::intern(CURRENT_RUSTC_VERSION)
2931
}
3032

3133
pub fn is_builtin_attr(attr: &Attribute) -> bool {
@@ -629,7 +631,7 @@ pub fn eval_condition(
629631
sess.emit_warning(session_diagnostics::UnknownVersionLiteral { span: *span });
630632
return false;
631633
};
632-
let rustc_version = parse_version(env!("CFG_RELEASE"), true).unwrap();
634+
let rustc_version = parse_version(CURRENT_RUSTC_VERSION, true).unwrap();
633635

634636
// See https://github.com/rust-lang/rust/issues/64796#issuecomment-640851454 for details
635637
if sess.assume_incomplete_release {

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

+3-4
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::{rust_version_symbol, Since};
8+
use rustc_attr::{Since, CURRENT_RUSTC_VERSION};
99
use rustc_const_eval::transform::check_consts::ConstCx;
1010
use rustc_hir as hir;
1111
use rustc_hir::def_id::DefId;
@@ -380,10 +380,9 @@ fn is_const_fn(tcx: TyCtxt<'_>, def_id: DefId, msrv: &Msrv) -> bool {
380380
Since::Current => {
381381
// HACK(nilstrieb): CURRENT_RUSTC_VERSION can return versions like 1.66.0-dev.
382382
// `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();
383+
let short_version = CURRENT_RUSTC_VERSION.split('-').next().unwrap();
385384
RustcVersion::parse(short_version).unwrap_or_else(|err| {
386-
panic!("`rustc_attr::StabilityLevel::Stable::since` is ill-formatted: `{current_rustc_version}`, {err:?}")
385+
panic!("`rustc_attr::StabilityLevel::Stable::since` is ill-formatted: `{CURRENT_RUSTC_VERSION}`, {err:?}")
387386
})
388387
},
389388
Since::Err => return false,

0 commit comments

Comments
 (0)