Auto merge of #127722 - BoxyUwU:new_adt_const_params_limitations, r=c… · model-checking/verify-rust-std@2fff48d
@@ -975,31 +975,73 @@ 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 {}
982985983986/// 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")]
986990pub macro ConstParamTy($item:item) {
987991/* compiler built-in */
988992}
989993994+#[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`
9911013marker_impls! {
9921014 #[unstable(feature = "adt_const_params", issue = "95174")]
993-ConstParamTy for
1015+ConstParamTy_ for
1016+usize, u8, u16, u32, u64, u128,
1017+isize, i8, i16, i32, i64, i128,
1018+bool,
1019+char,
1020+(),
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,
1030+}
1031+1032+marker_impls! {
1033+ #[unstable(feature = "unsized_const_params", issue = "95174")]
1034+UnsizedConstParamTy for
9941035usize, u8, u16, u32, u64, u128,
9951036isize, i8, i16, i32, i64, i128,
9961037bool,
9971038char,
998-str /* Technically requires `[u8]: ConstParamTy` */,
9991039(),
1000-{T: ConstParamTy, const N: usize} [T; N],
1001-{T: ConstParamTy} [T],
1002-{T: ?Sized + ConstParamTy} &T,
1040+{T: UnsizedConstParamTy, const N: usize} [T; N],
1041+1042+str,
1043+{T: UnsizedConstParamTy} [T],
1044+{T: UnsizedConstParamTy + ?Sized} &T,
10031045}
1004104610051047/// A common trait implemented by all function pointers.