1
Fork 0

Parse rustc version at compile time

This commit is contained in:
David Tolnay 2023-10-26 17:18:21 -07:00
parent dab715641e
commit b7debe34e6
No known key found for this signature in database
GPG key ID: F9BA143B95FF6D82
9 changed files with 124 additions and 61 deletions

View file

@ -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.

View 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)
}
}