diff options
| author | David Tolnay <dtolnay@gmail.com> | 2023-10-26 17:18:21 -0700 |
|---|---|---|
| committer | David Tolnay <dtolnay@gmail.com> | 2023-10-26 18:55:05 -0700 |
| commit | b7debe34e6fb2d329e21739c97ce3d7161303af5 (patch) | |
| tree | ca044e5dd26d1a01a4231f6db780e4e6645d0ad3 /compiler/rustc_session/src | |
| parent | dab715641e96a61a534587fda9de1128b75b34dc (diff) | |
| download | rust-b7debe34e6fb2d329e21739c97ce3d7161303af5.tar.gz rust-b7debe34e6fb2d329e21739c97ce3d7161303af5.zip | |
Parse rustc version at compile time
Diffstat (limited to 'compiler/rustc_session/src')
| -rw-r--r-- | compiler/rustc_session/src/lib.rs | 3 | ||||
| -rw-r--r-- | compiler/rustc_session/src/version.rs | 19 |
2 files changed, 22 insertions, 0 deletions
diff --git a/compiler/rustc_session/src/lib.rs b/compiler/rustc_session/src/lib.rs index 7da0bcf01bf..17ac3e991c5 100644 --- a/compiler/rustc_session/src/lib.rs +++ b/compiler/rustc_session/src/lib.rs @@ -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. diff --git a/compiler/rustc_session/src/version.rs b/compiler/rustc_session/src/version.rs new file mode 100644 index 00000000000..1ad8620bfba --- /dev/null +++ b/compiler/rustc_session/src/version.rs @@ -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) + } +} |
