Remove UnsizedConstParamTy trait and make it into an unstable impl
This commit is contained in:
@@ -51,43 +51,4 @@ pub(crate) fn expand_deriving_const_param_ty(
|
|||||||
};
|
};
|
||||||
|
|
||||||
trait_def.expand(cx, mitem, item, push);
|
trait_def.expand(cx, mitem, item, push);
|
||||||
|
|
||||||
let trait_def = TraitDef {
|
|
||||||
span,
|
|
||||||
path: path_std!(marker::UnsizedConstParamTy),
|
|
||||||
skip_path_as_bound: false,
|
|
||||||
needs_copy_as_bound_if_packed: false,
|
|
||||||
additional_bounds: vec![ty::Ty::Path(path_std!(cmp::Eq))],
|
|
||||||
supports_unions: false,
|
|
||||||
methods: Vec::new(),
|
|
||||||
associated_types: Vec::new(),
|
|
||||||
is_const,
|
|
||||||
is_staged_api_crate: cx.ecfg.features.staged_api(),
|
|
||||||
};
|
|
||||||
|
|
||||||
trait_def.expand(cx, mitem, item, push);
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn expand_deriving_unsized_const_param_ty(
|
|
||||||
cx: &ExtCtxt<'_>,
|
|
||||||
span: Span,
|
|
||||||
mitem: &MetaItem,
|
|
||||||
item: &Annotatable,
|
|
||||||
push: &mut dyn FnMut(Annotatable),
|
|
||||||
is_const: bool,
|
|
||||||
) {
|
|
||||||
let trait_def = TraitDef {
|
|
||||||
span,
|
|
||||||
path: path_std!(marker::UnsizedConstParamTy),
|
|
||||||
skip_path_as_bound: false,
|
|
||||||
needs_copy_as_bound_if_packed: false,
|
|
||||||
additional_bounds: vec![ty::Ty::Path(path_std!(cmp::Eq))],
|
|
||||||
supports_unions: false,
|
|
||||||
methods: Vec::new(),
|
|
||||||
associated_types: Vec::new(),
|
|
||||||
is_const,
|
|
||||||
is_staged_api_crate: cx.ecfg.features.staged_api(),
|
|
||||||
};
|
|
||||||
|
|
||||||
trait_def.expand(cx, mitem, item, push);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -129,7 +129,6 @@ pub fn register_builtin_macros(resolver: &mut dyn ResolverExpand) {
|
|||||||
Clone: clone::expand_deriving_clone,
|
Clone: clone::expand_deriving_clone,
|
||||||
Copy: bounds::expand_deriving_copy,
|
Copy: bounds::expand_deriving_copy,
|
||||||
ConstParamTy: bounds::expand_deriving_const_param_ty,
|
ConstParamTy: bounds::expand_deriving_const_param_ty,
|
||||||
UnsizedConstParamTy: bounds::expand_deriving_unsized_const_param_ty,
|
|
||||||
Debug: debug::expand_deriving_debug,
|
Debug: debug::expand_deriving_debug,
|
||||||
Default: default::expand_deriving_default,
|
Default: default::expand_deriving_default,
|
||||||
Eq: eq::expand_deriving_eq,
|
Eq: eq::expand_deriving_eq,
|
||||||
|
|||||||
@@ -370,7 +370,6 @@ language_item_table! {
|
|||||||
CoercePointeeValidated, sym::coerce_pointee_validated, coerce_pointee_validated_trait, Target::Trait, GenericRequirement::Exact(0);
|
CoercePointeeValidated, sym::coerce_pointee_validated, coerce_pointee_validated_trait, Target::Trait, GenericRequirement::Exact(0);
|
||||||
|
|
||||||
ConstParamTy, sym::const_param_ty, const_param_ty_trait, Target::Trait, GenericRequirement::Exact(0);
|
ConstParamTy, sym::const_param_ty, const_param_ty_trait, Target::Trait, GenericRequirement::Exact(0);
|
||||||
UnsizedConstParamTy, sym::unsized_const_param_ty, unsized_const_param_ty_trait, Target::Trait, GenericRequirement::Exact(0);
|
|
||||||
|
|
||||||
Poll, sym::Poll, poll, Target::Enum, GenericRequirement::None;
|
Poll, sym::Poll, poll, Target::Enum, GenericRequirement::None;
|
||||||
PollReady, sym::Ready, poll_ready_variant, Target::Variant, GenericRequirement::None;
|
PollReady, sym::Ready, poll_ready_variant, Target::Variant, GenericRequirement::None;
|
||||||
|
|||||||
@@ -819,17 +819,7 @@ fn check_param_wf(tcx: TyCtxt<'_>, param: &ty::GenericParamDef) -> Result<(), Er
|
|||||||
let span = tcx.def_span(param.def_id);
|
let span = tcx.def_span(param.def_id);
|
||||||
let def_id = param.def_id.expect_local();
|
let def_id = param.def_id.expect_local();
|
||||||
|
|
||||||
if tcx.features().unsized_const_params() {
|
if tcx.features().adt_const_params() {
|
||||||
enter_wf_checking_ctxt(tcx, tcx.local_parent(def_id), |wfcx| {
|
|
||||||
wfcx.register_bound(
|
|
||||||
ObligationCause::new(span, def_id, ObligationCauseCode::ConstParam(ty)),
|
|
||||||
wfcx.param_env,
|
|
||||||
ty,
|
|
||||||
tcx.require_lang_item(LangItem::UnsizedConstParamTy, span),
|
|
||||||
);
|
|
||||||
Ok(())
|
|
||||||
})
|
|
||||||
} else if tcx.features().adt_const_params() {
|
|
||||||
enter_wf_checking_ctxt(tcx, tcx.local_parent(def_id), |wfcx| {
|
enter_wf_checking_ctxt(tcx, tcx.local_parent(def_id), |wfcx| {
|
||||||
wfcx.register_bound(
|
wfcx.register_bound(
|
||||||
ObligationCause::new(span, def_id, ObligationCauseCode::ConstParam(ty)),
|
ObligationCause::new(span, def_id, ObligationCauseCode::ConstParam(ty)),
|
||||||
@@ -880,7 +870,6 @@ fn check_param_wf(tcx: TyCtxt<'_>, param: &ty::GenericParamDef) -> Result<(), Er
|
|||||||
tcx,
|
tcx,
|
||||||
tcx.param_env(param.def_id),
|
tcx.param_env(param.def_id),
|
||||||
ty,
|
ty,
|
||||||
LangItem::ConstParamTy,
|
|
||||||
cause,
|
cause,
|
||||||
) {
|
) {
|
||||||
// Can never implement `ConstParamTy`, don't suggest anything.
|
// Can never implement `ConstParamTy`, don't suggest anything.
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
//! Check properties that are required by built-in traits and set
|
//! Check properties that are required by built-in traits and set
|
||||||
//! up data structures required by type-checking/codegen.
|
//! up data structures required by type-checking/codegen.
|
||||||
|
|
||||||
use std::assert_matches::assert_matches;
|
|
||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
|
|
||||||
use rustc_data_structures::fx::FxHashSet;
|
use rustc_data_structures::fx::FxHashSet;
|
||||||
@@ -40,10 +39,7 @@ pub(super) fn check_trait<'tcx>(
|
|||||||
checker.check(lang_items.async_drop_trait(), visit_implementation_of_drop)?;
|
checker.check(lang_items.async_drop_trait(), visit_implementation_of_drop)?;
|
||||||
checker.check(lang_items.copy_trait(), visit_implementation_of_copy)?;
|
checker.check(lang_items.copy_trait(), visit_implementation_of_copy)?;
|
||||||
checker.check(lang_items.const_param_ty_trait(), |checker| {
|
checker.check(lang_items.const_param_ty_trait(), |checker| {
|
||||||
visit_implementation_of_const_param_ty(checker, LangItem::ConstParamTy)
|
visit_implementation_of_const_param_ty(checker)
|
||||||
})?;
|
|
||||||
checker.check(lang_items.unsized_const_param_ty_trait(), |checker| {
|
|
||||||
visit_implementation_of_const_param_ty(checker, LangItem::UnsizedConstParamTy)
|
|
||||||
})?;
|
})?;
|
||||||
checker.check(lang_items.coerce_unsized_trait(), visit_implementation_of_coerce_unsized)?;
|
checker.check(lang_items.coerce_unsized_trait(), visit_implementation_of_coerce_unsized)?;
|
||||||
checker
|
checker
|
||||||
@@ -138,12 +134,7 @@ fn visit_implementation_of_copy(checker: &Checker<'_>) -> Result<(), ErrorGuaran
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_implementation_of_const_param_ty(
|
fn visit_implementation_of_const_param_ty(checker: &Checker<'_>) -> Result<(), ErrorGuaranteed> {
|
||||||
checker: &Checker<'_>,
|
|
||||||
kind: LangItem,
|
|
||||||
) -> Result<(), ErrorGuaranteed> {
|
|
||||||
assert_matches!(kind, LangItem::ConstParamTy | LangItem::UnsizedConstParamTy);
|
|
||||||
|
|
||||||
let tcx = checker.tcx;
|
let tcx = checker.tcx;
|
||||||
let header = checker.impl_header;
|
let header = checker.impl_header;
|
||||||
let impl_did = checker.impl_def_id;
|
let impl_did = checker.impl_def_id;
|
||||||
@@ -157,7 +148,7 @@ fn visit_implementation_of_const_param_ty(
|
|||||||
}
|
}
|
||||||
|
|
||||||
let cause = traits::ObligationCause::misc(DUMMY_SP, impl_did);
|
let cause = traits::ObligationCause::misc(DUMMY_SP, impl_did);
|
||||||
match type_allowed_to_implement_const_param_ty(tcx, param_env, self_type, kind, cause) {
|
match type_allowed_to_implement_const_param_ty(tcx, param_env, self_type, cause) {
|
||||||
Ok(()) => Ok(()),
|
Ok(()) => Ok(()),
|
||||||
Err(ConstParamTyImplementationError::InfrigingFields(fields)) => {
|
Err(ConstParamTyImplementationError::InfrigingFields(fields)) => {
|
||||||
let span = tcx.hir_expect_item(impl_did).expect_impl().self_ty.span;
|
let span = tcx.hir_expect_item(impl_did).expect_impl().self_ty.span;
|
||||||
|
|||||||
@@ -1083,7 +1083,7 @@ pub trait Tuple {}
|
|||||||
// We name this differently than the derive macro so that the `adt_const_params` can
|
// We name this differently than the derive macro so that the `adt_const_params` can
|
||||||
// be used independently of `unsized_const_params` without requiring a full path
|
// be used independently of `unsized_const_params` without requiring a full path
|
||||||
// to the derive macro every time it is used. This should be renamed on stabilization.
|
// to the derive macro every time it is used. This should be renamed on stabilization.
|
||||||
pub trait ConstParamTy_: UnsizedConstParamTy + StructuralPartialEq + Eq {}
|
pub trait ConstParamTy_: StructuralPartialEq + Eq {}
|
||||||
|
|
||||||
/// Derive macro generating an impl of the trait `ConstParamTy`.
|
/// Derive macro generating an impl of the trait `ConstParamTy`.
|
||||||
#[rustc_builtin_macro]
|
#[rustc_builtin_macro]
|
||||||
@@ -1093,23 +1093,6 @@ pub macro ConstParamTy($item:item) {
|
|||||||
/* compiler built-in */
|
/* compiler built-in */
|
||||||
}
|
}
|
||||||
|
|
||||||
#[lang = "unsized_const_param_ty"]
|
|
||||||
#[unstable(feature = "unsized_const_params", issue = "95174")]
|
|
||||||
#[diagnostic::on_unimplemented(message = "`{Self}` can't be used as a const parameter type")]
|
|
||||||
/// A marker for types which can be used as types of `const` generic parameters.
|
|
||||||
///
|
|
||||||
/// Equivalent to [`ConstParamTy_`] except that this is used by
|
|
||||||
/// the `unsized_const_params` to allow for fake unstable impls.
|
|
||||||
pub trait UnsizedConstParamTy: StructuralPartialEq + Eq {}
|
|
||||||
|
|
||||||
/// Derive macro generating an impl of the trait `ConstParamTy`.
|
|
||||||
#[rustc_builtin_macro]
|
|
||||||
#[allow_internal_unstable(unsized_const_params)]
|
|
||||||
#[unstable(feature = "unsized_const_params", issue = "95174")]
|
|
||||||
pub macro UnsizedConstParamTy($item:item) {
|
|
||||||
/* compiler built-in */
|
|
||||||
}
|
|
||||||
|
|
||||||
// FIXME(adt_const_params): handle `ty::FnDef`/`ty::Closure`
|
// FIXME(adt_const_params): handle `ty::FnDef`/`ty::Closure`
|
||||||
marker_impls! {
|
marker_impls! {
|
||||||
#[unstable(feature = "adt_const_params", issue = "95174")]
|
#[unstable(feature = "adt_const_params", issue = "95174")]
|
||||||
@@ -1124,17 +1107,11 @@ marker_impls! {
|
|||||||
|
|
||||||
marker_impls! {
|
marker_impls! {
|
||||||
#[unstable(feature = "unsized_const_params", issue = "95174")]
|
#[unstable(feature = "unsized_const_params", issue = "95174")]
|
||||||
UnsizedConstParamTy for
|
#[unstable_feature_bound(unsized_const_params)]
|
||||||
usize, u8, u16, u32, u64, u128,
|
ConstParamTy_ for
|
||||||
isize, i8, i16, i32, i64, i128,
|
|
||||||
bool,
|
|
||||||
char,
|
|
||||||
(),
|
|
||||||
{T: UnsizedConstParamTy, const N: usize} [T; N],
|
|
||||||
|
|
||||||
str,
|
str,
|
||||||
{T: UnsizedConstParamTy} [T],
|
{T: ConstParamTy_} [T],
|
||||||
{T: UnsizedConstParamTy + ?Sized} &T,
|
{T: ConstParamTy_ + ?Sized} &T,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A common trait implemented by all function pointers.
|
/// A common trait implemented by all function pointers.
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
use crate::marker::{ConstParamTy_, UnsizedConstParamTy};
|
use crate::marker::ConstParamTy_;
|
||||||
|
|
||||||
/// Marks that `Src` is transmutable into `Self`.
|
/// Marks that `Src` is transmutable into `Self`.
|
||||||
///
|
///
|
||||||
@@ -83,6 +83,7 @@ use crate::marker::{ConstParamTy_, UnsizedConstParamTy};
|
|||||||
/// Furthermore, stability does not imply portability. For example, the size of
|
/// Furthermore, stability does not imply portability. For example, the size of
|
||||||
/// `usize` is stable, but not portable.
|
/// `usize` is stable, but not portable.
|
||||||
#[unstable(feature = "transmutability", issue = "99571")]
|
#[unstable(feature = "transmutability", issue = "99571")]
|
||||||
|
#[unstable_feature_bound(transmutability)]
|
||||||
#[lang = "transmute_trait"]
|
#[lang = "transmute_trait"]
|
||||||
#[rustc_deny_explicit_impl]
|
#[rustc_deny_explicit_impl]
|
||||||
#[rustc_do_not_implement_via_object]
|
#[rustc_do_not_implement_via_object]
|
||||||
@@ -288,9 +289,8 @@ pub struct Assume {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[unstable(feature = "transmutability", issue = "99571")]
|
#[unstable(feature = "transmutability", issue = "99571")]
|
||||||
|
#[unstable_feature_bound(transmutability)]
|
||||||
impl ConstParamTy_ for Assume {}
|
impl ConstParamTy_ for Assume {}
|
||||||
#[unstable(feature = "transmutability", issue = "99571")]
|
|
||||||
impl UnsizedConstParamTy for Assume {}
|
|
||||||
|
|
||||||
impl Assume {
|
impl Assume {
|
||||||
/// With this, [`TransmuteFrom`] does not assume you have ensured any safety
|
/// With this, [`TransmuteFrom`] does not assume you have ensured any safety
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
// See core/src/primitive_docs.rs for documentation.
|
// See core/src/primitive_docs.rs for documentation.
|
||||||
|
|
||||||
use crate::cmp::Ordering::{self, *};
|
use crate::cmp::Ordering::{self, *};
|
||||||
use crate::marker::{ConstParamTy_, StructuralPartialEq, UnsizedConstParamTy};
|
use crate::marker::{ConstParamTy_, StructuralPartialEq};
|
||||||
use crate::ops::ControlFlow::{self, Break, Continue};
|
use crate::ops::ControlFlow::{self, Break, Continue};
|
||||||
|
|
||||||
// Recursive macro for implementing n-ary tuple functions and operations
|
// Recursive macro for implementing n-ary tuple functions and operations
|
||||||
@@ -47,17 +47,11 @@ macro_rules! tuple_impls {
|
|||||||
maybe_tuple_doc! {
|
maybe_tuple_doc! {
|
||||||
$($T)+ @
|
$($T)+ @
|
||||||
#[unstable(feature = "adt_const_params", issue = "95174")]
|
#[unstable(feature = "adt_const_params", issue = "95174")]
|
||||||
|
#[unstable_feature_bound(unsized_const_params)]
|
||||||
impl<$($T: ConstParamTy_),+> ConstParamTy_ for ($($T,)+)
|
impl<$($T: ConstParamTy_),+> ConstParamTy_ for ($($T,)+)
|
||||||
{}
|
{}
|
||||||
}
|
}
|
||||||
|
|
||||||
maybe_tuple_doc! {
|
|
||||||
$($T)+ @
|
|
||||||
#[unstable(feature = "unsized_const_params", issue = "95174")]
|
|
||||||
impl<$($T: UnsizedConstParamTy),+> UnsizedConstParamTy for ($($T,)+)
|
|
||||||
{}
|
|
||||||
}
|
|
||||||
|
|
||||||
maybe_tuple_doc! {
|
maybe_tuple_doc! {
|
||||||
$($T)+ @
|
$($T)+ @
|
||||||
#[unstable(feature = "structural_match", issue = "31434")]
|
#[unstable(feature = "structural_match", issue = "31434")]
|
||||||
|
|||||||
Reference in New Issue
Block a user