rustc_ast/attr/
version.rs1use std::fmt::{self, Display};
2use std::sync::OnceLock;
3
4use rustc_macros::{BlobDecodable, Encodable, HashStable_Generic, current_rustc_version};
5
6#[derive(const _: () =
{
impl<__E: ::rustc_span::SpanEncoder> ::rustc_serialize::Encodable<__E>
for RustcVersion {
fn encode(&self, __encoder: &mut __E) {
match *self {
RustcVersion {
major: ref __binding_0,
minor: ref __binding_1,
patch: ref __binding_2 } => {
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
::rustc_serialize::Encodable::<__E>::encode(__binding_1,
__encoder);
::rustc_serialize::Encodable::<__E>::encode(__binding_2,
__encoder);
}
}
}
}
};Encodable, const _: () =
{
impl<__D: ::rustc_span::BlobDecoder> ::rustc_serialize::Decodable<__D>
for RustcVersion {
fn decode(__decoder: &mut __D) -> Self {
RustcVersion {
major: ::rustc_serialize::Decodable::decode(__decoder),
minor: ::rustc_serialize::Decodable::decode(__decoder),
patch: ::rustc_serialize::Decodable::decode(__decoder),
}
}
}
};BlobDecodable, #[automatically_derived]
impl ::core::marker::Copy for RustcVersion { }Copy, #[automatically_derived]
impl ::core::clone::Clone for RustcVersion {
#[inline]
fn clone(&self) -> RustcVersion {
let _: ::core::clone::AssertParamIsClone<u16>;
*self
}
}Clone, #[automatically_derived]
impl ::core::fmt::Debug for RustcVersion {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field3_finish(f, "RustcVersion",
"major", &self.major, "minor", &self.minor, "patch", &&self.patch)
}
}Debug, #[automatically_derived]
impl ::core::cmp::PartialEq for RustcVersion {
#[inline]
fn eq(&self, other: &RustcVersion) -> bool {
self.major == other.major && self.minor == other.minor &&
self.patch == other.patch
}
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for RustcVersion {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_receiver_is_total_eq(&self) -> () {
let _: ::core::cmp::AssertParamIsEq<u16>;
}
}Eq, #[automatically_derived]
impl ::core::cmp::PartialOrd for RustcVersion {
#[inline]
fn partial_cmp(&self, other: &RustcVersion)
-> ::core::option::Option<::core::cmp::Ordering> {
match ::core::cmp::PartialOrd::partial_cmp(&self.major, &other.major)
{
::core::option::Option::Some(::core::cmp::Ordering::Equal) =>
match ::core::cmp::PartialOrd::partial_cmp(&self.minor,
&other.minor) {
::core::option::Option::Some(::core::cmp::Ordering::Equal)
=>
::core::cmp::PartialOrd::partial_cmp(&self.patch,
&other.patch),
cmp => cmp,
},
cmp => cmp,
}
}
}PartialOrd, #[automatically_derived]
impl ::core::cmp::Ord for RustcVersion {
#[inline]
fn cmp(&self, other: &RustcVersion) -> ::core::cmp::Ordering {
match ::core::cmp::Ord::cmp(&self.major, &other.major) {
::core::cmp::Ordering::Equal =>
match ::core::cmp::Ord::cmp(&self.minor, &other.minor) {
::core::cmp::Ordering::Equal =>
::core::cmp::Ord::cmp(&self.patch, &other.patch),
cmp => cmp,
},
cmp => cmp,
}
}
}Ord, #[automatically_derived]
impl ::core::hash::Hash for RustcVersion {
#[inline]
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) -> () {
::core::hash::Hash::hash(&self.major, state);
::core::hash::Hash::hash(&self.minor, state);
::core::hash::Hash::hash(&self.patch, state)
}
}Hash)]
7#[derive(const _: () =
{
impl<__CTX> ::rustc_data_structures::stable_hasher::HashStable<__CTX>
for RustcVersion where __CTX: crate::HashStableContext {
#[inline]
fn hash_stable(&self, __hcx: &mut __CTX,
__hasher:
&mut ::rustc_data_structures::stable_hasher::StableHasher) {
match *self {
RustcVersion {
major: ref __binding_0,
minor: ref __binding_1,
patch: ref __binding_2 } => {
{ __binding_0.hash_stable(__hcx, __hasher); }
{ __binding_1.hash_stable(__hcx, __hasher); }
{ __binding_2.hash_stable(__hcx, __hasher); }
}
}
}
}
};HashStable_Generic)]
8pub struct RustcVersion {
9 pub major: u16,
10 pub minor: u16,
11 pub patch: u16,
12}
13
14impl RustcVersion {
15 pub const CURRENT: Self = Self { major: 1u16, minor: 94u16, patch: 0u16 }current_rustc_version!();
16 pub fn current_overridable() -> Self {
17 *CURRENT_OVERRIDABLE.get_or_init(|| {
18 if let Ok(override_var) = std::env::var("RUSTC_OVERRIDE_VERSION_STRING")
19 && let Some(override_) = Self::parse_str(&override_var)
20 {
21 override_
22 } else {
23 Self::CURRENT
24 }
25 })
26 }
27 fn parse_str(value: &str) -> Option<Self> {
28 let mut components = value.split('-').next().unwrap().splitn(3, '.');
30 let major = components.next()?.parse().ok()?;
31 let minor = components.next()?.parse().ok()?;
32 let patch = components.next().unwrap_or("0").parse().ok()?;
33 Some(RustcVersion { major, minor, patch })
34 }
35}
36
37static CURRENT_OVERRIDABLE: OnceLock<RustcVersion> = OnceLock::new();
38
39impl Display for RustcVersion {
40 fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
41 formatter.write_fmt(format_args!("{0}.{1}.{2}", self.major, self.minor,
self.patch))write!(formatter, "{}.{}.{}", self.major, self.minor, self.patch)
42 }
43}