Expose a non-Symbol way to access current rustc version string

This commit is contained in:
David Tolnay 2023-10-24 18:06:57 -07:00
parent 51f7fbab92
commit 1a9ea1f1a5
No known key found for this signature in database
GPG Key ID: F9BA143B95FF6D82
3 changed files with 9 additions and 8 deletions

View File

@ -24,8 +24,10 @@ use crate::session_diagnostics::{self, IncorrectReprFormatGenericCause};
/// For more, see [this pull request](https://github.com/rust-lang/rust/pull/100591).
pub const VERSION_PLACEHOLDER: &str = "CURRENT_RUSTC_VERSION";
pub const CURRENT_RUSTC_VERSION: &str = env!("CFG_RELEASE");
pub fn rust_version_symbol() -> Symbol {
Symbol::intern(env!("CFG_RELEASE"))
Symbol::intern(CURRENT_RUSTC_VERSION)
}
pub fn is_builtin_attr(attr: &Attribute) -> bool {
@ -629,7 +631,7 @@ pub fn eval_condition(
sess.emit_warning(session_diagnostics::UnknownVersionLiteral { span: *span });
return false;
};
let rustc_version = parse_version(env!("CFG_RELEASE"), true).unwrap();
let rustc_version = parse_version(CURRENT_RUSTC_VERSION, true).unwrap();
// See https://github.com/rust-lang/rust/issues/64796#issuecomment-640851454 for details
if sess.assume_incomplete_release {

View File

@ -48,7 +48,7 @@ use std::str;
use std::string::ToString;
use askama::Template;
use rustc_attr::{rust_version_symbol, ConstStability, Deprecation, Since, StabilityLevel};
use rustc_attr::{ConstStability, Deprecation, Since, StabilityLevel, CURRENT_RUSTC_VERSION};
use rustc_data_structures::captures::Captures;
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_hir::def_id::{DefId, DefIdSet};
@ -979,7 +979,7 @@ fn render_stability_since_raw_with_extra(
fn since_to_string(since: &Since) -> Option<String> {
match since {
Since::Version(since) => Some(since.to_string()),
Since::Current => Some(rust_version_symbol().to_string()),
Since::Current => Some(CURRENT_RUSTC_VERSION.to_owned()),
Since::Err => None,
}
}

View File

@ -5,7 +5,7 @@
use crate::msrvs::Msrv;
use hir::LangItem;
use rustc_attr::{rust_version_symbol, Since};
use rustc_attr::{Since, CURRENT_RUSTC_VERSION};
use rustc_const_eval::transform::check_consts::ConstCx;
use rustc_hir as hir;
use rustc_hir::def_id::DefId;
@ -380,10 +380,9 @@ fn is_const_fn(tcx: TyCtxt<'_>, def_id: DefId, msrv: &Msrv) -> bool {
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();
let short_version = CURRENT_RUSTC_VERSION.split('-').next().unwrap();
RustcVersion::parse(short_version).unwrap_or_else(|err| {
panic!("`rustc_attr::StabilityLevel::Stable::since` is ill-formatted: `{current_rustc_version}`, {err:?}")
panic!("`rustc_attr::StabilityLevel::Stable::since` is ill-formatted: `{CURRENT_RUSTC_VERSION}`, {err:?}")
})
},
Since::Err => return false,