mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 06:44:35 +00:00
Specialize PartialEq for Option<newtype>
This commit is contained in:
parent
8e8fd02b27
commit
20f2d8b841
@ -15,6 +15,7 @@
|
||||
#![feature(if_let_guard)]
|
||||
#![feature(let_chains)]
|
||||
#![feature(min_specialization)]
|
||||
#![feature(spec_option_partial_eq)]
|
||||
#![feature(negative_impls)]
|
||||
#![feature(slice_internals)]
|
||||
#![feature(stmt_expr_attributes)]
|
||||
|
@ -6,6 +6,7 @@
|
||||
#![feature(min_specialization)]
|
||||
#![feature(never_type)]
|
||||
#![feature(rustc_attrs)]
|
||||
#![feature(spec_option_partial_eq)]
|
||||
#![feature(stmt_expr_attributes)]
|
||||
#![feature(trusted_step)]
|
||||
#![feature(try_blocks)]
|
||||
|
@ -13,6 +13,7 @@
|
||||
#![feature(cell_leak)]
|
||||
#![feature(control_flow_enum)]
|
||||
#![feature(extend_one)]
|
||||
#![feature(spec_option_partial_eq)]
|
||||
#![feature(hash_raw_entry)]
|
||||
#![feature(hasher_prefixfree_extras)]
|
||||
#![feature(maybe_uninit_uninit_array)]
|
||||
|
@ -9,6 +9,7 @@
|
||||
#![feature(never_type)]
|
||||
#![feature(rustc_attrs)]
|
||||
#![feature(variant_count)]
|
||||
#![feature(spec_option_partial_eq)]
|
||||
#![recursion_limit = "256"]
|
||||
#![deny(rustc::untranslatable_diagnostic)]
|
||||
#![deny(rustc::diagnostic_outside_of_impl)]
|
||||
|
@ -65,6 +65,7 @@ This API is completely unstable and subject to change.
|
||||
#![feature(is_sorted)]
|
||||
#![feature(iter_intersperse)]
|
||||
#![feature(let_chains)]
|
||||
#![feature(spec_option_partial_eq)]
|
||||
#![feature(min_specialization)]
|
||||
#![feature(never_type)]
|
||||
#![feature(once_cell)]
|
||||
|
@ -3,6 +3,7 @@
|
||||
#![feature(try_blocks)]
|
||||
#![feature(never_type)]
|
||||
#![feature(min_specialization)]
|
||||
#![feature(spec_option_partial_eq)]
|
||||
#![feature(control_flow_enum)]
|
||||
#![feature(drain_filter)]
|
||||
#![allow(rustc::potential_query_instability)]
|
||||
|
@ -6,6 +6,7 @@
|
||||
#![feature(new_uninit)]
|
||||
#![feature(step_trait)]
|
||||
#![feature(stmt_expr_attributes)]
|
||||
#![feature(spec_option_partial_eq)]
|
||||
#![feature(test)]
|
||||
|
||||
pub mod bit_set;
|
||||
|
@ -19,6 +19,7 @@
|
||||
#![feature(extend_one)]
|
||||
#![feature(let_chains)]
|
||||
#![feature(if_let_guard)]
|
||||
#![feature(spec_option_partial_eq)]
|
||||
#![feature(min_specialization)]
|
||||
#![feature(never_type)]
|
||||
#![feature(try_blocks)]
|
||||
|
@ -34,6 +34,7 @@
|
||||
#![feature(iter_intersperse)]
|
||||
#![feature(iter_order_by)]
|
||||
#![feature(let_chains)]
|
||||
#![feature(spec_option_partial_eq)]
|
||||
#![feature(min_specialization)]
|
||||
#![feature(never_type)]
|
||||
#![recursion_limit = "256"]
|
||||
|
@ -192,6 +192,30 @@ impl Parse for Newtype {
|
||||
}
|
||||
}
|
||||
};
|
||||
let spec_partial_eq_impl = if let Lit::Int(max) = &max {
|
||||
if let Ok(max_val) = max.base10_parse::<u32>() {
|
||||
quote! {
|
||||
impl core::option::SpecOptionPartialEq for #name {
|
||||
#[inline]
|
||||
fn eq(l: &Option<Self>, r: &Option<Self>) -> bool {
|
||||
if #max_val < u32::MAX {
|
||||
l.map(|i| i.private).unwrap_or(#max_val+1) == r.map(|i| i.private).unwrap_or(#max_val+1)
|
||||
} else {
|
||||
match (l, r) {
|
||||
(Some(l), Some(r)) => r == l,
|
||||
(None, None) => true,
|
||||
_ => false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
quote! {}
|
||||
}
|
||||
} else {
|
||||
quote! {}
|
||||
};
|
||||
|
||||
Ok(Self(quote! {
|
||||
#(#attrs)*
|
||||
@ -293,6 +317,8 @@ impl Parse for Newtype {
|
||||
|
||||
#step
|
||||
|
||||
#spec_partial_eq_impl
|
||||
|
||||
impl From<#name> for u32 {
|
||||
#[inline]
|
||||
fn from(v: #name) -> u32 {
|
||||
|
@ -31,6 +31,7 @@
|
||||
#![feature(discriminant_kind)]
|
||||
#![feature(exhaustive_patterns)]
|
||||
#![feature(get_mut_unchecked)]
|
||||
#![feature(spec_option_partial_eq)]
|
||||
#![feature(if_let_guard)]
|
||||
#![feature(negative_impls)]
|
||||
#![feature(never_type)]
|
||||
|
@ -7,6 +7,7 @@
|
||||
#![feature(control_flow_enum)]
|
||||
#![feature(if_let_guard)]
|
||||
#![feature(let_chains)]
|
||||
#![feature(spec_option_partial_eq)]
|
||||
#![feature(min_specialization)]
|
||||
#![feature(once_cell)]
|
||||
#![recursion_limit = "256"]
|
||||
|
@ -4,6 +4,7 @@
|
||||
#![feature(min_specialization)]
|
||||
#![feature(once_cell)]
|
||||
#![feature(stmt_expr_attributes)]
|
||||
#![feature(spec_option_partial_eq)]
|
||||
#![feature(trusted_step)]
|
||||
#![recursion_limit = "256"]
|
||||
#![deny(rustc::untranslatable_diagnostic)]
|
||||
|
@ -7,6 +7,7 @@
|
||||
#![feature(once_cell)]
|
||||
#![feature(option_get_or_insert_default)]
|
||||
#![feature(trusted_step)]
|
||||
#![feature(spec_option_partial_eq)]
|
||||
#![feature(try_blocks)]
|
||||
#![feature(yeet_expr)]
|
||||
#![feature(if_let_guard)]
|
||||
|
@ -11,6 +11,7 @@
|
||||
#![feature(iter_intersperse)]
|
||||
#![feature(let_chains)]
|
||||
#![feature(map_try_insert)]
|
||||
#![feature(spec_option_partial_eq)]
|
||||
#![feature(min_specialization)]
|
||||
#![feature(try_blocks)]
|
||||
#![recursion_limit = "256"]
|
||||
|
@ -3,6 +3,7 @@
|
||||
#![feature(hash_raw_entry)]
|
||||
#![feature(min_specialization)]
|
||||
#![feature(extern_types)]
|
||||
#![feature(spec_option_partial_eq)]
|
||||
#![allow(rustc::potential_query_instability)]
|
||||
#![deny(rustc::untranslatable_diagnostic)]
|
||||
#![deny(rustc::diagnostic_outside_of_impl)]
|
||||
|
@ -18,6 +18,7 @@
|
||||
#![feature(if_let_guard)]
|
||||
#![feature(negative_impls)]
|
||||
#![feature(min_specialization)]
|
||||
#![feature(spec_option_partial_eq)]
|
||||
#![feature(rustc_attrs)]
|
||||
#![deny(rustc::untranslatable_diagnostic)]
|
||||
#![deny(rustc::diagnostic_outside_of_impl)]
|
||||
|
@ -14,6 +14,7 @@
|
||||
#![feature(min_specialization)]
|
||||
#![feature(never_type)]
|
||||
#![feature(rustc_attrs)]
|
||||
#![feature(spec_option_partial_eq)]
|
||||
#![feature(step_trait)]
|
||||
#![deny(rustc::untranslatable_diagnostic)]
|
||||
#![deny(rustc::diagnostic_outside_of_impl)]
|
||||
|
@ -1,6 +1,7 @@
|
||||
#![feature(fmt_helpers_for_derive)]
|
||||
#![feature(min_specialization)]
|
||||
#![feature(rustc_attrs)]
|
||||
#![feature(spec_option_partial_eq)]
|
||||
#![deny(rustc::untranslatable_diagnostic)]
|
||||
#![deny(rustc::diagnostic_outside_of_impl)]
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user