diff options
| author | Jubilee <46493976+workingjubilee@users.noreply.github.com> | 2023-10-28 01:07:38 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-10-28 01:07:38 -0700 |
| commit | 1db8c9d6e20dfefda97fd994e09e7c3121fd2e45 (patch) | |
| tree | 582976dc0da17d85b409f00ae6b7edb696114166 /compiler/rustc_session | |
| parent | 87a564d271999dafcc9bcfdcca33fd5fa60b0e58 (diff) | |
| parent | b7debe34e6fb2d329e21739c97ce3d7161303af5 (diff) | |
| download | rust-1db8c9d6e20dfefda97fd994e09e7c3121fd2e45.tar.gz rust-1db8c9d6e20dfefda97fd994e09e7c3121fd2e45.zip | |
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. https://github.com/rust-lang/rust/blob/dab715641e96a61a534587fda9de1128b75b34dc/src/tools/clippy/clippy_utils/src/qualify_min_const_fn.rs#L385 https://github.com/rust-lang/rust/blob/dab715641e96a61a534587fda9de1128b75b34dc/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.
Diffstat (limited to 'compiler/rustc_session')
| -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) + } +} |
