Skip to content

Commit be0c06b

Browse files
committed
Split part of adt_const_params into unsized_const_params
1 parent 857ed93 commit be0c06b

File tree

4 files changed

+63
-19
lines changed

4 files changed

+63
-19
lines changed

core/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@
248248
#![feature(transparent_unions)]
249249
#![feature(try_blocks)]
250250
#![feature(unboxed_closures)]
251+
#![feature(unsized_const_params)]
251252
#![feature(unsized_fn_params)]
252253
#![feature(with_negative_coherence)]
253254
// tidy-alphabetical-end

core/src/marker.rs

+47-14
Original file line numberDiff line numberDiff line change
@@ -975,41 +975,74 @@ pub trait PointerLike {}
975975
/// that all fields are also `ConstParamTy`, which implies that recursively, all fields
976976
/// are `StructuralPartialEq`.
977977
#[lang = "const_param_ty"]
978-
#[unstable(feature = "adt_const_params", issue = "95174")]
978+
#[unstable(feature = "unsized_const_params", issue = "95174")]
979979
#[diagnostic::on_unimplemented(message = "`{Self}` can't be used as a const parameter type")]
980980
#[allow(multiple_supertrait_upcastable)]
981-
pub trait ConstParamTy: StructuralPartialEq + Eq {}
981+
// We name this differently than the derive macro so that the `adt_const_params` can
982+
// be used independently of `unsized_const_params` without requiring a full path
983+
// to the derive macro every time it is used. This should be renamed on stabilization.
984+
pub trait ConstParamTy_: UnsizedConstParamTy + StructuralPartialEq + Eq {}
982985

983986
/// Derive macro generating an impl of the trait `ConstParamTy`.
984987
#[rustc_builtin_macro]
988+
#[allow_internal_unstable(unsized_const_params)]
985989
#[unstable(feature = "adt_const_params", issue = "95174")]
986990
pub macro ConstParamTy($item:item) {
987991
/* compiler built-in */
988992
}
989993

994+
#[cfg_attr(not(bootstrap), lang = "unsized_const_param_ty")]
995+
#[unstable(feature = "unsized_const_params", issue = "95174")]
996+
#[diagnostic::on_unimplemented(message = "`{Self}` can't be used as a const parameter type")]
997+
/// A marker for types which can be used as types of `const` generic parameters.
998+
///
999+
/// Equivalent to [`ConstParamTy_`] except that this is used by
1000+
/// the `unsized_const_params` to allow for fake unstable impls.
1001+
pub trait UnsizedConstParamTy: StructuralPartialEq + Eq {}
1002+
1003+
/// Derive macro generating an impl of the trait `ConstParamTy`.
1004+
#[cfg(not(bootstrap))]
1005+
#[cfg_attr(not(bootstrap), rustc_builtin_macro)]
1006+
#[cfg_attr(not(bootstrap), allow_internal_unstable(unsized_const_params))]
1007+
#[cfg_attr(not(bootstrap), unstable(feature = "unsized_const_params", issue = "95174"))]
1008+
pub macro UnsizedConstParamTy($item:item) {
1009+
/* compiler built-in */
1010+
}
1011+
9901012
// FIXME(adt_const_params): handle `ty::FnDef`/`ty::Closure`
9911013
marker_impls! {
9921014
#[unstable(feature = "adt_const_params", issue = "95174")]
993-
ConstParamTy for
1015+
ConstParamTy_ for
9941016
usize, u8, u16, u32, u64, u128,
9951017
isize, i8, i16, i32, i64, i128,
9961018
bool,
9971019
char,
9981020
(),
999-
{T: ConstParamTy, const N: usize} [T; N],
1021+
{T: ConstParamTy_, const N: usize} [T; N],
1022+
}
1023+
#[cfg(bootstrap)]
1024+
marker_impls! {
1025+
#[unstable(feature = "adt_const_params", issue = "95174")]
1026+
ConstParamTy_ for
1027+
str,
1028+
{T: ConstParamTy_} [T],
1029+
{T: ConstParamTy_ + ?Sized} &T,
10001030
}
10011031

1002-
#[unstable(feature = "adt_const_params", issue = "95174")]
1003-
#[rustc_reservation_impl = "types that are not `Sized` are not supported as the type of a const generic parameter"]
1004-
impl<T> ConstParamTy for [T] {}
1005-
1006-
#[unstable(feature = "adt_const_params", issue = "95174")]
1007-
#[rustc_reservation_impl = "types that are not `Sized` are not supported as the type of a const generic parameter"]
1008-
impl ConstParamTy for str {}
1032+
marker_impls! {
1033+
#[unstable(feature = "unsized_const_params", issue = "95174")]
1034+
UnsizedConstParamTy for
1035+
usize, u8, u16, u32, u64, u128,
1036+
isize, i8, i16, i32, i64, i128,
1037+
bool,
1038+
char,
1039+
(),
1040+
{T: UnsizedConstParamTy, const N: usize} [T; N],
10091041

1010-
#[unstable(feature = "adt_const_params", issue = "95174")]
1011-
#[rustc_reservation_impl = "references are not supported as the type of a const generic parameter"]
1012-
impl<T: ?Sized> ConstParamTy for &T {}
1042+
str,
1043+
{T: UnsizedConstParamTy} [T],
1044+
{T: UnsizedConstParamTy + ?Sized} &T,
1045+
}
10131046

10141047
/// A common trait implemented by all function pointers.
10151048
#[unstable(

core/src/mem/transmutability.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::marker::ConstParamTy;
1+
use crate::marker::{ConstParamTy_, UnsizedConstParamTy};
22

33
/// Are values of a type transmutable into values of another type?
44
///
@@ -39,7 +39,9 @@ pub struct Assume {
3939
}
4040

4141
#[unstable(feature = "transmutability", issue = "99571")]
42-
impl ConstParamTy for Assume {}
42+
impl ConstParamTy_ for Assume {}
43+
#[unstable(feature = "transmutability", issue = "99571")]
44+
impl UnsizedConstParamTy for Assume {}
4345

4446
impl Assume {
4547
/// Do not assume that *you* have ensured any safety properties are met.

core/src/tuple.rs

+11-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
// See core/src/primitive_docs.rs for documentation.
22

33
use crate::cmp::Ordering::{self, *};
4-
use crate::marker::ConstParamTy;
4+
use crate::marker::ConstParamTy_;
55
use crate::marker::StructuralPartialEq;
6+
use crate::marker::UnsizedConstParamTy;
67

78
// Recursive macro for implementing n-ary tuple functions and operations
89
//
@@ -49,8 +50,15 @@ macro_rules! tuple_impls {
4950

5051
maybe_tuple_doc! {
5152
$($T)+ @
52-
#[unstable(feature = "structural_match", issue = "31434")]
53-
impl<$($T: ConstParamTy),+> ConstParamTy for ($($T,)+)
53+
#[unstable(feature = "adt_const_params", issue = "95174")]
54+
impl<$($T: ConstParamTy_),+> ConstParamTy_ for ($($T,)+)
55+
{}
56+
}
57+
58+
maybe_tuple_doc! {
59+
$($T)+ @
60+
#[unstable(feature = "unsized_const_params", issue = "95174")]
61+
impl<$($T: UnsizedConstParamTy),+> UnsizedConstParamTy for ($($T,)+)
5462
{}
5563
}
5664

0 commit comments

Comments
 (0)