1
Fork 0

Split out IntoIterator and non-Iterator constructors for AliasTy/AliasTerm/TraitRef/projection

This commit is contained in:
Michael Goulet 2024-06-21 13:33:08 -04:00
parent 06c072f158
commit f26cc349d9
35 changed files with 144 additions and 84 deletions

View file

@ -630,7 +630,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
let trait_pred_and_ty = trait_pred.map_bound(|inner| {
(
ty::TraitPredicate {
trait_ref: ty::TraitRef::new(
trait_ref: ty::TraitRef::new_from_args(
self.tcx,
inner.trait_ref.def_id,
self.tcx.mk_args(
@ -3955,7 +3955,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
// Extract `<U as Deref>::Target` assoc type and check that it is `T`
&& let Some(deref_target_did) = tcx.lang_items().deref_target()
&& let projection = Ty::new_projection(tcx,deref_target_did, tcx.mk_args(&[ty::GenericArg::from(found_ty)]))
&& let projection = Ty::new_projection_from_args(tcx,deref_target_did, tcx.mk_args(&[ty::GenericArg::from(found_ty)]))
&& let InferOk { value: deref_target, obligations } = infcx.at(&ObligationCause::dummy(), param_env).normalize(projection)
&& obligations.iter().all(|obligation| infcx.predicate_must_hold_modulo_regions(obligation))
&& infcx.can_eq(param_env, deref_target, target_ty)
@ -4290,7 +4290,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
// This corresponds to `<ExprTy as Iterator>::Item = _`.
let projection = ty::Binder::dummy(ty::PredicateKind::Clause(
ty::ClauseKind::Projection(ty::ProjectionPredicate {
projection_term: ty::AliasTerm::new(self.tcx, proj.def_id, args),
projection_term: ty::AliasTerm::new_from_args(self.tcx, proj.def_id, args),
term: ty.into(),
}),
));

View file

@ -689,7 +689,7 @@ fn receiver_is_dispatchable<'tcx>(
if param.index == 0 { unsized_self_ty.into() } else { tcx.mk_param_from_def(param) }
});
ty::TraitRef::new(tcx, trait_def_id, args).upcast(tcx)
ty::TraitRef::new_from_args(tcx, trait_def_id, args).upcast(tcx)
};
let caller_bounds =

View file

@ -727,10 +727,12 @@ fn project<'cx, 'tcx>(
ProjectionCandidateSet::None => {
let tcx = selcx.tcx();
let term = match tcx.def_kind(obligation.predicate.def_id) {
DefKind::AssocTy => {
Ty::new_projection(tcx, obligation.predicate.def_id, obligation.predicate.args)
.into()
}
DefKind::AssocTy => Ty::new_projection_from_args(
tcx,
obligation.predicate.def_id,
obligation.predicate.args,
)
.into(),
DefKind::AssocConst => ty::Const::new_unevaluated(
tcx,
ty::UnevaluatedConst::new(
@ -1387,7 +1389,11 @@ fn confirm_coroutine_candidate<'cx, 'tcx>(
};
let predicate = ty::ProjectionPredicate {
projection_term: ty::AliasTerm::new(tcx, obligation.predicate.def_id, trait_ref.args),
projection_term: ty::AliasTerm::new_from_args(
tcx,
obligation.predicate.def_id,
trait_ref.args,
),
term: ty.into(),
};
@ -1431,7 +1437,11 @@ fn confirm_future_candidate<'cx, 'tcx>(
debug_assert_eq!(tcx.associated_item(obligation.predicate.def_id).name, sym::Output);
let predicate = ty::ProjectionPredicate {
projection_term: ty::AliasTerm::new(tcx, obligation.predicate.def_id, trait_ref.args),
projection_term: ty::AliasTerm::new_from_args(
tcx,
obligation.predicate.def_id,
trait_ref.args,
),
term: return_ty.into(),
};
@ -1473,7 +1483,11 @@ fn confirm_iterator_candidate<'cx, 'tcx>(
debug_assert_eq!(tcx.associated_item(obligation.predicate.def_id).name, sym::Item);
let predicate = ty::ProjectionPredicate {
projection_term: ty::AliasTerm::new(tcx, obligation.predicate.def_id, trait_ref.args),
projection_term: ty::AliasTerm::new_from_args(
tcx,
obligation.predicate.def_id,
trait_ref.args,
),
term: yield_ty.into(),
};
@ -1523,7 +1537,11 @@ fn confirm_async_iterator_candidate<'cx, 'tcx>(
let item_ty = args.type_at(0);
let predicate = ty::ProjectionPredicate {
projection_term: ty::AliasTerm::new(tcx, obligation.predicate.def_id, trait_ref.args),
projection_term: ty::AliasTerm::new_from_args(
tcx,
obligation.predicate.def_id,
trait_ref.args,
),
term: item_ty.into(),
};
@ -1592,7 +1610,7 @@ fn confirm_builtin_candidate<'cx, 'tcx>(
};
let predicate = ty::ProjectionPredicate {
projection_term: ty::AliasTerm::new(tcx, item_def_id, args),
projection_term: ty::AliasTerm::new_from_args(tcx, item_def_id, args),
term,
};
@ -1753,7 +1771,7 @@ fn confirm_callable_candidate<'cx, 'tcx>(
fn_host_effect,
)
.map_bound(|(trait_ref, ret_type)| ty::ProjectionPredicate {
projection_term: ty::AliasTerm::new(tcx, fn_once_output_def_id, trait_ref.args),
projection_term: ty::AliasTerm::new_from_args(tcx, fn_once_output_def_id, trait_ref.args),
term: ret_type.into(),
});
@ -1937,7 +1955,7 @@ fn confirm_async_fn_kind_helper_candidate<'cx, 'tcx>(
};
let predicate = ty::ProjectionPredicate {
projection_term: ty::AliasTerm::new(
projection_term: ty::AliasTerm::new_from_args(
selcx.tcx(),
obligation.predicate.def_id,
obligation.predicate.args,

View file

@ -940,7 +940,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
let ty = traits::normalize_projection_ty(
self,
param_env,
ty::AliasTy::new(tcx, tcx.lang_items().deref_target()?, trait_ref.args),
ty::AliasTy::new_from_args(tcx, tcx.lang_items().deref_target()?, trait_ref.args),
cause.clone(),
0,
// We're *intentionally* throwing these away,

View file

@ -2487,7 +2487,7 @@ impl<'tcx> SelectionContext<'_, 'tcx> {
trait_def_id,
&[normalized_ty.into()],
);
ty::TraitRef::new(tcx, trait_def_id, err_args)
ty::TraitRef::new_from_args(tcx, trait_def_id, err_args)
};
let obligation = Obligation::new(self.tcx(), cause.clone(), param_env, trait_ref);