1
Fork 0

Impl ConstParamTy for tuples, make PartialStructuralEq a supertrait too

This commit is contained in:
Michael Goulet 2023-05-17 03:00:19 +00:00
parent 8ab10bacdf
commit a9fcb524ff
7 changed files with 68 additions and 7 deletions

View file

@ -205,6 +205,20 @@ pub trait StructuralPartialEq {
// Empty.
}
marker_impls! {
#[unstable(feature = "structural_match", issue = "31434")]
StructuralPartialEq for
usize, u8, u16, u32, u64, u128,
isize, i8, i16, i32, i64, i128,
bool,
char,
str /* Technically requires `[u8]: StructuralEq` */,
(),
{T, const N: usize} [T; N],
{T} [T],
{T: ?Sized} &T,
}
/// Required trait for constants used in pattern matches.
///
/// Any type that derives `Eq` automatically implements this trait, *regardless*
@ -267,6 +281,7 @@ marker_impls! {
bool,
char,
str /* Technically requires `[u8]: StructuralEq` */,
(),
{T, const N: usize} [T; N],
{T} [T],
{T: ?Sized} &T,
@ -974,7 +989,8 @@ pub trait PointerLike {}
#[lang = "const_param_ty"]
#[unstable(feature = "adt_const_params", issue = "95174")]
#[rustc_on_unimplemented(message = "`{Self}` can't be used as a const parameter type")]
pub trait ConstParamTy: StructuralEq {}
#[allow(multiple_supertrait_upcastable)]
pub trait ConstParamTy: StructuralEq + StructuralPartialEq {}
/// Derive macro generating an impl of the trait `ConstParamTy`.
#[rustc_builtin_macro]
@ -983,8 +999,7 @@ pub macro ConstParamTy($item:item) {
/* compiler built-in */
}
// FIXME(generic_const_parameter_types): handle `ty::FnDef`/`ty::Closure`
// FIXME(generic_const_parameter_types): handle `ty::Tuple`
// FIXME(adt_const_params): handle `ty::FnDef`/`ty::Closure`
marker_impls! {
#[unstable(feature = "adt_const_params", issue = "95174")]
ConstParamTy for
@ -998,6 +1013,11 @@ marker_impls! {
{T: ?Sized + ConstParamTy} &T,
}
// FIXME(adt_const_params): Add to marker_impls call above once not in bootstrap
#[unstable(feature = "adt_const_params", issue = "95174")]
#[cfg(not(bootstrap))]
impl ConstParamTy for () {}
/// A common trait implemented by all function pointers.
#[unstable(
feature = "fn_ptr_trait",

View file

@ -1,6 +1,9 @@
// See src/libstd/primitive_docs.rs for documentation.
use crate::cmp::Ordering::{self, *};
#[cfg(not(bootstrap))]
use crate::marker::ConstParamTy;
use crate::marker::{StructuralEq, StructuralPartialEq};
// Recursive macro for implementing n-ary tuple functions and operations
//
@ -45,6 +48,28 @@ macro_rules! tuple_impls {
{}
}
maybe_tuple_doc! {
$($T)+ @
#[unstable(feature = "structural_match", issue = "31434")]
#[cfg(not(bootstrap))]
impl<$($T: ConstParamTy),+> ConstParamTy for ($($T,)+)
{}
}
maybe_tuple_doc! {
$($T)+ @
#[unstable(feature = "structural_match", issue = "31434")]
impl<$($T),+> StructuralPartialEq for ($($T,)+)
{}
}
maybe_tuple_doc! {
$($T)+ @
#[unstable(feature = "structural_match", issue = "31434")]
impl<$($T),+> StructuralEq for ($($T,)+)
{}
}
maybe_tuple_doc! {
$($T)+ @
#[stable(feature = "rust1", since = "1.0.0")]