Skip to content

Commit 1bf6bbb

Browse files
committed
Impl StructuralEq & ConstParamTy for str, &T, [T; N] and [T]
1 parent 2205c3f commit 1bf6bbb

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

compiler/rustc_trait_selection/src/traits/misc.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,14 @@ pub fn type_allowed_to_implement_const_param_ty<'tcx>(
9393
) -> Result<(), ConstParamTyImplementationError<'tcx>> {
9494
let (adt, substs) = match self_type.kind() {
9595
// `core` provides these impls.
96-
ty::Uint(_) | ty::Int(_) | ty::Bool | ty::Char => return Ok(()),
96+
ty::Uint(_)
97+
| ty::Int(_)
98+
| ty::Bool
99+
| ty::Char
100+
| ty::Str
101+
| ty::Array(..)
102+
| ty::Slice(_)
103+
| ty::Ref(.., hir::Mutability::Not) => return Ok(()),
97104

98105
&ty::Adt(adt, substs) => (adt, substs),
99106

library/core/src/marker.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,13 +268,18 @@ pub trait StructuralEq {
268268
// Empty.
269269
}
270270

271+
// FIXME: Remove special cases of these types from the compiler pattern checking code and always check `T: StructuralEq` instead
271272
marker_impls! {
272273
#[unstable(feature = "structural_match", issue = "31434")]
273274
StructuralEq for
274275
usize, u8, u16, u32, u64, u128,
275276
isize, i8, i16, i32, i64, i128,
276277
bool,
277278
char,
279+
str /* Technically requires `[u8]: StructuralEq` */,
280+
{T: ConstParamTy, const N: usize} [T; N],
281+
{T: ConstParamTy} [T],
282+
{T: ConstParamTy} &T,
278283
}
279284

280285
/// Types whose values can be duplicated simply by copying bits.
@@ -988,6 +993,10 @@ marker_impls! {
988993
isize, i8, i16, i32, i64, i128,
989994
bool,
990995
char,
996+
str /* Technically requires `[u8]: ConstParamTy` */,
997+
{T: ConstParamTy, const N: usize} [T; N],
998+
{T: ConstParamTy} [T],
999+
{T: ConstParamTy} &T,
9911000
}
9921001

9931002
/// A common trait implemented by all function pointers.

0 commit comments

Comments
 (0)