Skip to content

Commit a4bd0a8

Browse files
committed
wip0: compile pass
1 parent 2886b36 commit a4bd0a8

File tree

2 files changed

+23
-19
lines changed

2 files changed

+23
-19
lines changed

compiler/rustc_trait_selection/src/traits/misc.rs

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ use rustc_ast::Mutability;
77
use rustc_hir as hir;
88
use rustc_infer::infer::{RegionResolutionError, TyCtxtInferExt};
99
use rustc_middle::ty::{self, AdtDef, Ty, TyCtxt, TypeVisitableExt, TypingMode};
10+
use rustc_span::sym;
1011

1112
use crate::regions::InferCtxtRegionExt;
12-
use crate::traits::{self, FulfillmentError, ObligationCause};
13+
use crate::traits::{self, FulfillmentError, Obligation, ObligationCause};
1314

1415
pub enum CopyImplementationError<'tcx> {
1516
InfringingFields(Vec<(&'tcx ty::FieldDef, Ty<'tcx>, InfringingFieldsReason<'tcx>)>),
@@ -101,7 +102,9 @@ pub fn type_allowed_to_implement_const_param_ty<'tcx>(
101102
lang_item: LangItem,
102103
parent_cause: ObligationCause<'tcx>,
103104
) -> Result<(), ConstParamTyImplementationError<'tcx>> {
105+
// FIXME: remove the unsizedconstparamty item
104106
assert_matches!(lang_item, LangItem::ConstParamTy | LangItem::UnsizedConstParamTy);
107+
let mut need_unstable_feature_bound = false;
105108

106109
let inner_tys: Vec<_> = match *self_type.kind() {
107110
// Trivially okay as these types are all:
@@ -112,17 +115,14 @@ pub fn type_allowed_to_implement_const_param_ty<'tcx>(
112115

113116
// Handle types gated under `feature(unsized_const_params)`
114117
// FIXME(unsized_const_params): Make `const N: [u8]` work then forbid references
115-
ty::Slice(inner_ty) | ty::Ref(_, inner_ty, Mutability::Not)
116-
if lang_item == LangItem::UnsizedConstParamTy =>
117-
{
118+
ty::Slice(inner_ty) | ty::Ref(_, inner_ty, Mutability::Not) => {
119+
need_unstable_feature_bound = true;
118120
vec![inner_ty]
119121
}
120-
ty::Str if lang_item == LangItem::UnsizedConstParamTy => {
122+
ty::Str => {
123+
need_unstable_feature_bound = true;
121124
vec![Ty::new_slice(tcx, tcx.types.u8)]
122125
}
123-
ty::Str | ty::Slice(..) | ty::Ref(_, _, Mutability::Not) => {
124-
return Err(ConstParamTyImplementationError::UnsizedConstParamsFeatureRequired);
125-
}
126126

127127
ty::Array(inner_ty, _) => vec![inner_ty],
128128

@@ -153,6 +153,16 @@ pub fn type_allowed_to_implement_const_param_ty<'tcx>(
153153
let infcx = tcx.infer_ctxt().build(TypingMode::non_body_analysis());
154154
let ocx = traits::ObligationCtxt::new_with_diagnostics(&infcx);
155155

156+
// FIXME: add a comment here
157+
if need_unstable_feature_bound {
158+
ocx.register_obligation(Obligation::new(
159+
tcx,
160+
parent_cause.clone(),
161+
param_env,
162+
ty::ClauseKind::UnstableFeature(sym::unsized_const_params),
163+
))
164+
}
165+
156166
ocx.register_bound(
157167
parent_cause.clone(),
158168
param_env,

library/core/src/marker.rs

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1084,7 +1084,7 @@ pub trait Tuple {}
10841084
// We name this differently than the derive macro so that the `adt_const_params` can
10851085
// be used independently of `unsized_const_params` without requiring a full path
10861086
// to the derive macro every time it is used. This should be renamed on stabilization.
1087-
pub trait ConstParamTy_: UnsizedConstParamTy + StructuralPartialEq + Eq {}
1087+
pub trait ConstParamTy_: StructuralPartialEq + Eq {}
10881088

10891089
/// Derive macro generating an impl of the trait `ConstParamTy`.
10901090
#[rustc_builtin_macro]
@@ -1125,17 +1125,11 @@ marker_impls! {
11251125

11261126
marker_impls! {
11271127
#[unstable(feature = "unsized_const_params", issue = "95174")]
1128-
UnsizedConstParamTy for
1129-
usize, u8, u16, u32, u64, u128,
1130-
isize, i8, i16, i32, i64, i128,
1131-
bool,
1132-
char,
1133-
(),
1134-
{T: UnsizedConstParamTy, const N: usize} [T; N],
1135-
1128+
#[unstable_feature_bound(unsized_const_params)]
1129+
ConstParamTy_ for
11361130
str,
1137-
{T: UnsizedConstParamTy} [T],
1138-
{T: UnsizedConstParamTy + ?Sized} &T,
1131+
{T: ConstParamTy_} [T],
1132+
{T: ConstParamTy_ + ?Sized} &T,
11391133
}
11401134

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

0 commit comments

Comments
 (0)