Impl ConstParamTy for tuples, make PartialStructuralEq a supertrait too
This commit is contained in:
parent
8ab10bacdf
commit
a9fcb524ff
@ -100,7 +100,8 @@ pub fn type_allowed_to_implement_const_param_ty<'tcx>(
|
|||||||
| ty::Str
|
| ty::Str
|
||||||
| ty::Array(..)
|
| ty::Array(..)
|
||||||
| ty::Slice(_)
|
| ty::Slice(_)
|
||||||
| ty::Ref(.., hir::Mutability::Not) => return Ok(()),
|
| ty::Ref(.., hir::Mutability::Not)
|
||||||
|
| ty::Tuple(_) => return Ok(()),
|
||||||
|
|
||||||
&ty::Adt(adt, substs) => (adt, substs),
|
&ty::Adt(adt, substs) => (adt, substs),
|
||||||
|
|
||||||
|
@ -205,6 +205,20 @@ pub trait StructuralPartialEq {
|
|||||||
// Empty.
|
// 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.
|
/// Required trait for constants used in pattern matches.
|
||||||
///
|
///
|
||||||
/// Any type that derives `Eq` automatically implements this trait, *regardless*
|
/// Any type that derives `Eq` automatically implements this trait, *regardless*
|
||||||
@ -267,6 +281,7 @@ marker_impls! {
|
|||||||
bool,
|
bool,
|
||||||
char,
|
char,
|
||||||
str /* Technically requires `[u8]: StructuralEq` */,
|
str /* Technically requires `[u8]: StructuralEq` */,
|
||||||
|
(),
|
||||||
{T, const N: usize} [T; N],
|
{T, const N: usize} [T; N],
|
||||||
{T} [T],
|
{T} [T],
|
||||||
{T: ?Sized} &T,
|
{T: ?Sized} &T,
|
||||||
@ -974,7 +989,8 @@ pub trait PointerLike {}
|
|||||||
#[lang = "const_param_ty"]
|
#[lang = "const_param_ty"]
|
||||||
#[unstable(feature = "adt_const_params", issue = "95174")]
|
#[unstable(feature = "adt_const_params", issue = "95174")]
|
||||||
#[rustc_on_unimplemented(message = "`{Self}` can't be used as a const parameter type")]
|
#[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`.
|
/// Derive macro generating an impl of the trait `ConstParamTy`.
|
||||||
#[rustc_builtin_macro]
|
#[rustc_builtin_macro]
|
||||||
@ -983,8 +999,7 @@ pub macro ConstParamTy($item:item) {
|
|||||||
/* compiler built-in */
|
/* compiler built-in */
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME(generic_const_parameter_types): handle `ty::FnDef`/`ty::Closure`
|
// FIXME(adt_const_params): handle `ty::FnDef`/`ty::Closure`
|
||||||
// FIXME(generic_const_parameter_types): handle `ty::Tuple`
|
|
||||||
marker_impls! {
|
marker_impls! {
|
||||||
#[unstable(feature = "adt_const_params", issue = "95174")]
|
#[unstable(feature = "adt_const_params", issue = "95174")]
|
||||||
ConstParamTy for
|
ConstParamTy for
|
||||||
@ -998,6 +1013,11 @@ marker_impls! {
|
|||||||
{T: ?Sized + ConstParamTy} &T,
|
{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.
|
/// A common trait implemented by all function pointers.
|
||||||
#[unstable(
|
#[unstable(
|
||||||
feature = "fn_ptr_trait",
|
feature = "fn_ptr_trait",
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
// See src/libstd/primitive_docs.rs for documentation.
|
// See src/libstd/primitive_docs.rs for documentation.
|
||||||
|
|
||||||
use crate::cmp::Ordering::{self, *};
|
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
|
// 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! {
|
maybe_tuple_doc! {
|
||||||
$($T)+ @
|
$($T)+ @
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
|
@ -49,5 +49,7 @@ fn main() {
|
|||||||
check::<D<u8>>();
|
check::<D<u8>>();
|
||||||
check::<D<[&[bool]; 8]>>();
|
check::<D<[&[bool]; 8]>>();
|
||||||
|
|
||||||
// FIXME: test tuples
|
check::<()>();
|
||||||
|
check::<(i32,)>();
|
||||||
|
check::<(D<u8>, D<i32>)>();
|
||||||
}
|
}
|
||||||
|
@ -9,9 +9,11 @@ struct CantParam(ImplementsConstParamTy);
|
|||||||
|
|
||||||
impl std::marker::ConstParamTy for CantParam {}
|
impl std::marker::ConstParamTy for CantParam {}
|
||||||
//~^ error: the type `CantParam` does not `#[derive(Eq)]`
|
//~^ error: the type `CantParam` does not `#[derive(Eq)]`
|
||||||
|
//~| error: the type `CantParam` does not `#[derive(PartialEq)]`
|
||||||
|
|
||||||
#[derive(std::marker::ConstParamTy)]
|
#[derive(std::marker::ConstParamTy)]
|
||||||
//~^ error: the type `CantParamDerive` does not `#[derive(Eq)]`
|
//~^ error: the type `CantParamDerive` does not `#[derive(Eq)]`
|
||||||
|
//~| error: the type `CantParamDerive` does not `#[derive(PartialEq)]`
|
||||||
struct CantParamDerive(ImplementsConstParamTy);
|
struct CantParamDerive(ImplementsConstParamTy);
|
||||||
|
|
||||||
fn check<T: std::marker::ConstParamTy>() {}
|
fn check<T: std::marker::ConstParamTy>() {}
|
||||||
|
@ -14,6 +14,7 @@ impl Eq for Union {}
|
|||||||
impl std::marker::StructuralEq for Union {}
|
impl std::marker::StructuralEq for Union {}
|
||||||
|
|
||||||
impl std::marker::ConstParamTy for Union {}
|
impl std::marker::ConstParamTy for Union {}
|
||||||
|
//~^ ERROR the type `Union` does not `#[derive(PartialEq)]`
|
||||||
|
|
||||||
#[derive(std::marker::ConstParamTy)]
|
#[derive(std::marker::ConstParamTy)]
|
||||||
//~^ ERROR this trait cannot be derived for unions
|
//~^ ERROR this trait cannot be derived for unions
|
||||||
|
@ -1,8 +1,18 @@
|
|||||||
error: this trait cannot be derived for unions
|
error: this trait cannot be derived for unions
|
||||||
--> $DIR/const_param_ty_impl_union.rs:18:10
|
--> $DIR/const_param_ty_impl_union.rs:19:10
|
||||||
|
|
|
|
||||||
LL | #[derive(std::marker::ConstParamTy)]
|
LL | #[derive(std::marker::ConstParamTy)]
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
error: aborting due to previous error
|
error[E0277]: the type `Union` does not `#[derive(PartialEq)]`
|
||||||
|
--> $DIR/const_param_ty_impl_union.rs:16:36
|
||||||
|
|
|
||||||
|
LL | impl std::marker::ConstParamTy for Union {}
|
||||||
|
| ^^^^^ the trait `StructuralPartialEq` is not implemented for `Union`
|
||||||
|
|
|
||||||
|
note: required by a bound in `ConstParamTy`
|
||||||
|
--> $SRC_DIR/core/src/marker.rs:LL:COL
|
||||||
|
|
||||||
|
error: aborting due to 2 previous errors
|
||||||
|
|
||||||
|
For more information about this error, try `rustc --explain E0277`.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user