diff options
| author | Maybe Waffle <waffle.lapkin@gmail.com> | 2023-03-03 18:02:11 +0000 |
|---|---|---|
| committer | Maybe Waffle <waffle.lapkin@gmail.com> | 2023-04-27 15:59:07 +0000 |
| commit | 1bf6bbb1bd199956d1be3d8988f0d8b6036cd2e3 (patch) | |
| tree | b220bc716c77b014467c0baa25d8e1941f372911 | |
| parent | 2205c3fa5ffdb8794917d541e580742f527be8f1 (diff) | |
| download | rust-1bf6bbb1bd199956d1be3d8988f0d8b6036cd2e3.tar.gz rust-1bf6bbb1bd199956d1be3d8988f0d8b6036cd2e3.zip | |
Impl `StructuralEq` & `ConstParamTy` for `str`, `&T`, `[T; N]` and `[T]`
| -rw-r--r-- | compiler/rustc_trait_selection/src/traits/misc.rs | 9 | ||||
| -rw-r--r-- | library/core/src/marker.rs | 9 |
2 files changed, 17 insertions, 1 deletions
diff --git a/compiler/rustc_trait_selection/src/traits/misc.rs b/compiler/rustc_trait_selection/src/traits/misc.rs index cb8f64dd2e8..2210ef975e6 100644 --- a/compiler/rustc_trait_selection/src/traits/misc.rs +++ b/compiler/rustc_trait_selection/src/traits/misc.rs @@ -93,7 +93,14 @@ pub fn type_allowed_to_implement_const_param_ty<'tcx>( ) -> Result<(), ConstParamTyImplementationError<'tcx>> { let (adt, substs) = match self_type.kind() { // `core` provides these impls. - ty::Uint(_) | ty::Int(_) | ty::Bool | ty::Char => return Ok(()), + ty::Uint(_) + | ty::Int(_) + | ty::Bool + | ty::Char + | ty::Str + | ty::Array(..) + | ty::Slice(_) + | ty::Ref(.., hir::Mutability::Not) => return Ok(()), &ty::Adt(adt, substs) => (adt, substs), diff --git a/library/core/src/marker.rs b/library/core/src/marker.rs index 8c240661b2b..2f9138c56f2 100644 --- a/library/core/src/marker.rs +++ b/library/core/src/marker.rs @@ -268,6 +268,7 @@ pub trait StructuralEq { // Empty. } +// FIXME: Remove special cases of these types from the compiler pattern checking code and always check `T: StructuralEq` instead marker_impls! { #[unstable(feature = "structural_match", issue = "31434")] StructuralEq for @@ -275,6 +276,10 @@ marker_impls! { isize, i8, i16, i32, i64, i128, bool, char, + str /* Technically requires `[u8]: StructuralEq` */, + {T: ConstParamTy, const N: usize} [T; N], + {T: ConstParamTy} [T], + {T: ConstParamTy} &T, } /// Types whose values can be duplicated simply by copying bits. @@ -988,6 +993,10 @@ marker_impls! { isize, i8, i16, i32, i64, i128, bool, char, + str /* Technically requires `[u8]: ConstParamTy` */, + {T: ConstParamTy, const N: usize} [T; N], + {T: ConstParamTy} [T], + {T: ConstParamTy} &T, } /// A common trait implemented by all function pointers. |
