Rollup merge of #117256 - dtolnay:currentversion, r=compiler-errors
Parse rustc version at compile time This PR eliminates a couple awkward codepaths where it was not clear how the compiler should proceed if its own version number is incomprehensible.dab715641e/src/tools/clippy/clippy_utils/src/qualify_min_const_fn.rs (L385)
dab715641e/compiler/rustc_attr/src/builtin.rs (L630)
We can guarantee that every compiled rustc comes with a working version number, so the ICE codepaths above shouldn't need to be written.
This commit is contained in:
commit
1db8c9d6e2
9 changed files with 124 additions and 61 deletions
|
@ -43,6 +43,9 @@ pub mod output;
|
|||
|
||||
pub use getopts;
|
||||
|
||||
mod version;
|
||||
pub use version::RustcVersion;
|
||||
|
||||
fluent_messages! { "../messages.ftl" }
|
||||
|
||||
/// Requirements for a `StableHashingContext` to be used in this crate.
|
||||
|
|
19
compiler/rustc_session/src/version.rs
Normal file
19
compiler/rustc_session/src/version.rs
Normal file
|
@ -0,0 +1,19 @@
|
|||
use std::fmt::{self, Display};
|
||||
|
||||
#[derive(Encodable, Decodable, Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||
#[derive(HashStable_Generic)]
|
||||
pub struct RustcVersion {
|
||||
pub major: u16,
|
||||
pub minor: u16,
|
||||
pub patch: u16,
|
||||
}
|
||||
|
||||
impl RustcVersion {
|
||||
pub const CURRENT: Self = current_rustc_version!(env!("CFG_RELEASE"));
|
||||
}
|
||||
|
||||
impl Display for RustcVersion {
|
||||
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(formatter, "{}.{}.{}", self.major, self.minor, self.patch)
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue