1
Fork 0

Auto merge of #126813 - compiler-errors:SliceLike, r=lcnr

Add `SliceLike` to `rustc_type_ir`, use it in the generic solver code (+ some other changes)

First, we split out `TraitRef::new_from_args` which takes *just* `ty::GenericArgsRef` from `TraitRef::new` which takes `impl IntoIterator<Item: Into<GenericArg>>`. I will explain in a minute why.

Second, we introduce `SliceLike`, which allows us to be generic over `List<T>` and `[T]`. This trait has an `as_slice()` and `into_iter()` method, and some other convenience functions. However, importantly, since types like `I::GenericArgs` now implement `SliceLike` rather than `IntoIter<Item = I::GenericArg>`, we can't use `TraitRef::new` on this directly. That's where `new_from_args` comes in.

Finally, we adjust all the code to use these slice operators. Some things get simpler, some things get a bit more annoying since we need to use `as_slice()` in a few places. 🤷

r? lcnr
This commit is contained in:
bors 2024-06-25 00:33:49 +00:00
commit 5b270e1198
52 changed files with 378 additions and 254 deletions

View file

@ -719,7 +719,7 @@ pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) {
tcx, tcx,
assoc_item, assoc_item,
assoc_item, assoc_item,
ty::TraitRef::new(tcx, def_id.to_def_id(), trait_args), ty::TraitRef::new_from_args(tcx, def_id.to_def_id(), trait_args),
); );
} }
_ => {} _ => {}

View file

@ -2032,7 +2032,7 @@ pub(super) fn check_type_bounds<'tcx>(
// to its definition type. This should be the param-env we use to *prove* the // to its definition type. This should be the param-env we use to *prove* the
// predicate too, but we don't do that because of performance issues. // predicate too, but we don't do that because of performance issues.
// See <https://github.com/rust-lang/rust/pull/117542#issue-1976337685>. // See <https://github.com/rust-lang/rust/pull/117542#issue-1976337685>.
let trait_projection_ty = Ty::new_projection(tcx, trait_ty.def_id, rebased_args); let trait_projection_ty = Ty::new_projection_from_args(tcx, trait_ty.def_id, rebased_args);
let impl_identity_ty = tcx.type_of(impl_ty.def_id).instantiate_identity(); let impl_identity_ty = tcx.type_of(impl_ty.def_id).instantiate_identity();
let normalize_param_env = param_env_with_gat_bounds(tcx, impl_ty, impl_trait_ref); let normalize_param_env = param_env_with_gat_bounds(tcx, impl_ty, impl_trait_ref);
for mut obligation in util::elaborate(tcx, obligations) { for mut obligation in util::elaborate(tcx, obligations) {
@ -2230,7 +2230,11 @@ fn param_env_with_gat_bounds<'tcx>(
_ => predicates.push( _ => predicates.push(
ty::Binder::bind_with_vars( ty::Binder::bind_with_vars(
ty::ProjectionPredicate { ty::ProjectionPredicate {
projection_term: ty::AliasTerm::new(tcx, trait_ty.def_id, rebased_args), projection_term: ty::AliasTerm::new_from_args(
tcx,
trait_ty.def_id,
rebased_args,
),
term: normalize_impl_ty.into(), term: normalize_impl_ty.into(),
}, },
bound_vars, bound_vars,

View file

@ -504,7 +504,11 @@ pub fn check_intrinsic_type(
ty::Region::new_bound(tcx, ty::INNERMOST, br), ty::Region::new_bound(tcx, ty::INNERMOST, br),
param(0), param(0),
)], )],
Ty::new_projection(tcx, discriminant_def_id, tcx.mk_args(&[param(0).into()])), Ty::new_projection_from_args(
tcx,
discriminant_def_id,
tcx.mk_args(&[param(0).into()]),
),
) )
} }

View file

@ -423,7 +423,7 @@ impl<'tcx> HirTyLowerer<'tcx> for ItemCtxt<'tcx> {
item_segment, item_segment,
trait_ref.args, trait_ref.args,
); );
Ty::new_projection(self.tcx(), item_def_id, item_args) Ty::new_projection_from_args(self.tcx(), item_def_id, item_args)
} else { } else {
// There are no late-bound regions; we can just ignore the binder. // There are no late-bound regions; we can just ignore the binder.
let (mut mpart_sugg, mut inferred_sugg) = (None, None); let (mut mpart_sugg, mut inferred_sugg) = (None, None);
@ -1607,7 +1607,7 @@ pub fn suggest_impl_trait<'tcx>(
let item_ty = ocx.normalize( let item_ty = ocx.normalize(
&ObligationCause::dummy(), &ObligationCause::dummy(),
param_env, param_env,
Ty::new_projection(infcx.tcx, assoc_item_def_id, args), Ty::new_projection_from_args(infcx.tcx, assoc_item_def_id, args),
); );
// FIXME(compiler-errors): We may benefit from resolving regions here. // FIXME(compiler-errors): We may benefit from resolving regions here.
if ocx.select_where_possible().is_empty() if ocx.select_where_possible().is_empty()

View file

@ -23,7 +23,7 @@ fn associated_type_bounds<'tcx>(
span: Span, span: Span,
filter: PredicateFilter, filter: PredicateFilter,
) -> &'tcx [(ty::Clause<'tcx>, Span)] { ) -> &'tcx [(ty::Clause<'tcx>, Span)] {
let item_ty = Ty::new_projection( let item_ty = Ty::new_projection_from_args(
tcx, tcx,
assoc_item_def_id.to_def_id(), assoc_item_def_id.to_def_id(),
GenericArgs::identity_for_item(tcx, assoc_item_def_id), GenericArgs::identity_for_item(tcx, assoc_item_def_id),
@ -108,7 +108,7 @@ pub(super) fn explicit_item_bounds_with_filter(
tcx, tcx,
opaque_def_id.expect_local(), opaque_def_id.expect_local(),
opaque_ty.bounds, opaque_ty.bounds,
Ty::new_projection( Ty::new_projection_from_args(
tcx, tcx,
def_id.to_def_id(), def_id.to_def_id(),
ty::GenericArgs::identity_for_item(tcx, def_id), ty::GenericArgs::identity_for_item(tcx, def_id),

View file

@ -409,7 +409,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
); );
debug!(?alias_args); debug!(?alias_args);
ty::AliasTerm::new(tcx, assoc_item.def_id, alias_args) ty::AliasTerm::new_from_args(tcx, assoc_item.def_id, alias_args)
}); });
// Provide the resolved type of the associated constant to `type_of(AnonConst)`. // Provide the resolved type of the associated constant to `type_of(AnonConst)`.

View file

@ -693,7 +693,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
debug!(?bound_vars); debug!(?bound_vars);
let poly_trait_ref = ty::Binder::bind_with_vars( let poly_trait_ref = ty::Binder::bind_with_vars(
ty::TraitRef::new(tcx, trait_def_id, generic_args), ty::TraitRef::new_from_args(tcx, trait_def_id, generic_args),
bound_vars, bound_vars,
); );
@ -759,7 +759,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
Some((trait_def_id, trait_segment, span)), Some((trait_def_id, trait_segment, span)),
); );
} }
ty::TraitRef::new(self.tcx(), trait_def_id, generic_args) ty::TraitRef::new_from_args(self.tcx(), trait_def_id, generic_args)
} }
fn probe_trait_that_defines_assoc_item( fn probe_trait_that_defines_assoc_item(
@ -789,7 +789,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
// Type aliases defined in crates that have the // Type aliases defined in crates that have the
// feature `lazy_type_alias` enabled get encoded as a type alias that normalization will // feature `lazy_type_alias` enabled get encoded as a type alias that normalization will
// then actually instantiate the where bounds of. // then actually instantiate the where bounds of.
let alias_ty = ty::AliasTy::new(tcx, did, args); let alias_ty = ty::AliasTy::new_from_args(tcx, did, args);
Ty::new_alias(tcx, ty::Weak, alias_ty) Ty::new_alias(tcx, ty::Weak, alias_ty)
} else { } else {
tcx.at(span).type_of(did).instantiate(tcx, args) tcx.at(span).type_of(did).instantiate(tcx, args)
@ -1267,7 +1267,8 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
.chain(args.into_iter().skip(parent_args.len())), .chain(args.into_iter().skip(parent_args.len())),
); );
let ty = Ty::new_alias(tcx, ty::Inherent, ty::AliasTy::new(tcx, assoc_item, args)); let ty =
Ty::new_alias(tcx, ty::Inherent, ty::AliasTy::new_from_args(tcx, assoc_item, args));
Ok(Some((ty, assoc_item))) Ok(Some((ty, assoc_item)))
} }
@ -1534,7 +1535,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
let item_args = let item_args =
self.lower_generic_args_of_assoc_item(span, item_def_id, item_segment, trait_ref.args); self.lower_generic_args_of_assoc_item(span, item_def_id, item_segment, trait_ref.args);
Ty::new_projection(tcx, item_def_id, item_args) Ty::new_projection_from_args(tcx, item_def_id, item_args)
} }
pub fn prohibit_generic_args<'a>( pub fn prohibit_generic_args<'a>(
@ -2302,7 +2303,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
debug!(?args); debug!(?args);
if in_trait { if in_trait {
Ty::new_projection(tcx, def_id, args) Ty::new_projection_from_args(tcx, def_id, args)
} else { } else {
Ty::new_opaque(tcx, def_id, args) Ty::new_opaque(tcx, def_id, args)
} }

View file

@ -3108,7 +3108,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let element_ty = ocx.normalize( let element_ty = ocx.normalize(
&cause, &cause,
self.param_env, self.param_env,
Ty::new_projection(self.tcx, index_trait_output_def_id, impl_trait_ref.args), Ty::new_projection_from_args(
self.tcx,
index_trait_output_def_id,
impl_trait_ref.args,
),
); );
let true_errors = ocx.select_where_possible(); let true_errors = ocx.select_where_possible();

View file

@ -569,7 +569,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// For the purposes of this function, we hope that it is a `struct` type, and that our current `expr` is a literal of // For the purposes of this function, we hope that it is a `struct` type, and that our current `expr` is a literal of
// that struct type. // that struct type.
let impl_trait_self_ref = if self.tcx.is_trait_alias(obligation.impl_or_alias_def_id) { let impl_trait_self_ref = if self.tcx.is_trait_alias(obligation.impl_or_alias_def_id) {
ty::TraitRef::new( ty::TraitRef::new_from_args(
self.tcx, self.tcx,
obligation.impl_or_alias_def_id, obligation.impl_or_alias_def_id,
ty::GenericArgs::identity_for_item(self.tcx, obligation.impl_or_alias_def_id), ty::GenericArgs::identity_for_item(self.tcx, obligation.impl_or_alias_def_id),

View file

@ -297,7 +297,7 @@ impl<'tcx> HirTyLowerer<'tcx> for FnCtxt<'_, 'tcx> {
trait_ref.args, trait_ref.args,
); );
Ty::new_projection(self.tcx(), item_def_id, item_args) Ty::new_projection_from_args(self.tcx(), item_def_id, item_args)
} }
fn probe_adt(&self, span: Span, ty: Ty<'tcx>) -> Option<ty::AdtDef<'tcx>> { fn probe_adt(&self, span: Span, ty: Ty<'tcx>) -> Option<ty::AdtDef<'tcx>> {

View file

@ -333,7 +333,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
self.var_for_def(cause.span, param) self.var_for_def(cause.span, param)
}); });
let trait_ref = ty::TraitRef::new(self.tcx, trait_def_id, args); let trait_ref = ty::TraitRef::new_from_args(self.tcx, trait_def_id, args);
// Construct an obligation // Construct an obligation
let poly_trait_ref = ty::Binder::dummy(trait_ref); let poly_trait_ref = ty::Binder::dummy(trait_ref);

View file

@ -870,7 +870,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
trait_def_id: DefId, trait_def_id: DefId,
) { ) {
let trait_args = self.fresh_args_for_item(self.span, trait_def_id); let trait_args = self.fresh_args_for_item(self.span, trait_def_id);
let trait_ref = ty::TraitRef::new(self.tcx, trait_def_id, trait_args); let trait_ref = ty::TraitRef::new_from_args(self.tcx, trait_def_id, trait_args);
if self.tcx.is_trait_alias(trait_def_id) { if self.tcx.is_trait_alias(trait_def_id) {
// For trait aliases, recursively assume all explicitly named traits are relevant // For trait aliases, recursively assume all explicitly named traits are relevant

View file

@ -1978,7 +1978,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
err, err,
self_source, self_source,
args, args,
ty::TraitRef::new( ty::TraitRef::new_from_args(
self.tcx, self.tcx,
trait_did, trait_did,
self.fresh_args_for_item(sugg_span, trait_did), self.fresh_args_for_item(sugg_span, trait_did),

View file

@ -256,12 +256,12 @@ impl<'tcx> NiceRegionError<'_, 'tcx> {
(false, None, None, Some(span), String::new()) (false, None, None, Some(span), String::new())
}; };
let expected_trait_ref = self.cx.resolve_vars_if_possible(ty::TraitRef::new( let expected_trait_ref = self.cx.resolve_vars_if_possible(ty::TraitRef::new_from_args(
self.cx.tcx, self.cx.tcx,
trait_def_id, trait_def_id,
expected_args, expected_args,
)); ));
let actual_trait_ref = self.cx.resolve_vars_if_possible(ty::TraitRef::new( let actual_trait_ref = self.cx.resolve_vars_if_possible(ty::TraitRef::new_from_args(
self.cx.tcx, self.cx.tcx,
trait_def_id, trait_def_id,
actual_args, actual_args,

View file

@ -109,7 +109,7 @@ impl<'tcx> LateLintPass<'tcx> for OpaqueHiddenInferredBound {
return; return;
} }
let proj_ty = Ty::new_projection( let proj_ty = Ty::new_projection_from_args(
cx.tcx, cx.tcx,
proj.projection_term.def_id, proj.projection_term.def_id,
proj.projection_term.args, proj.projection_term.args,

View file

@ -240,7 +240,7 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
assert_matches!(self.def_kind(trait_def_id), DefKind::Trait); assert_matches!(self.def_kind(trait_def_id), DefKind::Trait);
let trait_generics = self.generics_of(trait_def_id); let trait_generics = self.generics_of(trait_def_id);
( (
ty::TraitRef::new(self, trait_def_id, args.truncate_to(self, trait_generics)), ty::TraitRef::new_from_args(self, trait_def_id, args.truncate_to(self, trait_generics)),
&args[trait_generics.count()..], &args[trait_generics.count()..],
) )
} }
@ -261,12 +261,8 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
self.check_args_compatible(def_id, args) self.check_args_compatible(def_id, args)
} }
fn check_and_mk_args( fn debug_assert_args_compatible(self, def_id: DefId, args: ty::GenericArgsRef<'tcx>) {
self, self.debug_assert_args_compatible(def_id, args);
def_id: DefId,
args: impl IntoIterator<Item: Into<ty::GenericArg<'tcx>>>,
) -> ty::GenericArgsRef<'tcx> {
self.check_and_mk_args(def_id, args)
} }
fn intern_canonical_goal_evaluation_step( fn intern_canonical_goal_evaluation_step(

View file

@ -133,6 +133,20 @@ impl<H, T> RawList<H, T> {
} }
} }
impl<'a, H, T: Copy> rustc_type_ir::inherent::SliceLike for &'a RawList<H, T> {
type Item = T;
type IntoIter = iter::Copied<<&'a [T] as IntoIterator>::IntoIter>;
fn iter(self) -> Self::IntoIter {
(*self).iter()
}
fn as_slice(&self) -> &[Self::Item] {
(*self).as_slice()
}
}
macro_rules! impl_list_empty { macro_rules! impl_list_empty {
($header_ty:ty, $header_init:expr) => { ($header_ty:ty, $header_init:expr) => {
impl<T> RawList<$header_ty, T> { impl<T> RawList<$header_ty, T> {

View file

@ -499,7 +499,7 @@ impl<'tcx> Ty<'tcx> {
#[inline] #[inline]
pub fn new_opaque(tcx: TyCtxt<'tcx>, def_id: DefId, args: GenericArgsRef<'tcx>) -> Ty<'tcx> { pub fn new_opaque(tcx: TyCtxt<'tcx>, def_id: DefId, args: GenericArgsRef<'tcx>) -> Ty<'tcx> {
Ty::new_alias(tcx, ty::Opaque, AliasTy::new(tcx, def_id, args)) Ty::new_alias(tcx, ty::Opaque, AliasTy::new_from_args(tcx, def_id, args))
} }
/// Constructs a `TyKind::Error` type with current `ErrorGuaranteed` /// Constructs a `TyKind::Error` type with current `ErrorGuaranteed`
@ -669,6 +669,15 @@ impl<'tcx> Ty<'tcx> {
Ty::new(tcx, Dynamic(obj, reg, repr)) Ty::new(tcx, Dynamic(obj, reg, repr))
} }
#[inline]
pub fn new_projection_from_args(
tcx: TyCtxt<'tcx>,
item_def_id: DefId,
args: ty::GenericArgsRef<'tcx>,
) -> Ty<'tcx> {
Ty::new_alias(tcx, ty::Projection, AliasTy::new_from_args(tcx, item_def_id, args))
}
#[inline] #[inline]
pub fn new_projection( pub fn new_projection(
tcx: TyCtxt<'tcx>, tcx: TyCtxt<'tcx>,
@ -1409,7 +1418,7 @@ impl<'tcx> Ty<'tcx> {
let assoc_items = tcx.associated_item_def_ids( let assoc_items = tcx.associated_item_def_ids(
tcx.require_lang_item(hir::LangItem::DiscriminantKind, None), tcx.require_lang_item(hir::LangItem::DiscriminantKind, None),
); );
Ty::new_projection(tcx, assoc_items[0], tcx.mk_args(&[self.into()])) Ty::new_projection_from_args(tcx, assoc_items[0], tcx.mk_args(&[self.into()]))
} }
ty::Pat(ty, _) => ty.discriminant_ty(tcx), ty::Pat(ty, _) => ty.discriminant_ty(tcx),

View file

@ -220,7 +220,7 @@ impl<'tcx> ConstToPat<'tcx> {
tcx, tcx,
ObligationCause::dummy(), ObligationCause::dummy(),
self.param_env, self.param_env,
ty::TraitRef::new( ty::TraitRef::new_from_args(
tcx, tcx,
partial_eq_trait_id, partial_eq_trait_id,
tcx.with_opt_host_effect_param( tcx.with_opt_host_effect_param(

View file

@ -527,7 +527,7 @@ where
}; };
for assumption in for assumption in
self.cx().item_bounds(alias_ty.def_id).iter_instantiated(self.cx(), &alias_ty.args) self.cx().item_bounds(alias_ty.def_id).iter_instantiated(self.cx(), alias_ty.args)
{ {
candidates.extend(G::probe_and_consider_implied_clause( candidates.extend(G::probe_and_consider_implied_clause(
self, self,
@ -603,7 +603,7 @@ where
// Consider all of the auto-trait and projection bounds, which don't // Consider all of the auto-trait and projection bounds, which don't
// need to be recorded as a `BuiltinImplSource::Object` since they don't // need to be recorded as a `BuiltinImplSource::Object` since they don't
// really have a vtable base... // really have a vtable base...
for bound in bounds { for bound in bounds.iter() {
match bound.skip_binder() { match bound.skip_binder() {
ty::ExistentialPredicate::Trait(_) => { ty::ExistentialPredicate::Trait(_) => {
// Skip principal // Skip principal

View file

@ -58,7 +58,7 @@ where
ty::Tuple(tys) => { ty::Tuple(tys) => {
// (T1, ..., Tn) -- meets any bound that all of T1...Tn meet // (T1, ..., Tn) -- meets any bound that all of T1...Tn meet
Ok(tys.into_iter().map(ty::Binder::dummy).collect()) Ok(tys.iter().map(ty::Binder::dummy).collect())
} }
ty::Closure(_, args) => Ok(vec![ty::Binder::dummy(args.as_closure().tupled_upvars_ty())]), ty::Closure(_, args) => Ok(vec![ty::Binder::dummy(args.as_closure().tupled_upvars_ty())]),
@ -79,23 +79,21 @@ where
.cx() .cx()
.bound_coroutine_hidden_types(def_id) .bound_coroutine_hidden_types(def_id)
.into_iter() .into_iter()
.map(|bty| bty.instantiate(tcx, &args)) .map(|bty| bty.instantiate(tcx, args))
.collect()), .collect()),
// For `PhantomData<T>`, we pass `T`. // For `PhantomData<T>`, we pass `T`.
ty::Adt(def, args) if def.is_phantom_data() => Ok(vec![ty::Binder::dummy(args.type_at(0))]), ty::Adt(def, args) if def.is_phantom_data() => Ok(vec![ty::Binder::dummy(args.type_at(0))]),
ty::Adt(def, args) => Ok(def ty::Adt(def, args) => {
.all_field_tys(tcx) Ok(def.all_field_tys(tcx).iter_instantiated(tcx, args).map(ty::Binder::dummy).collect())
.iter_instantiated(tcx, &args) }
.map(ty::Binder::dummy)
.collect()),
ty::Alias(ty::Opaque, ty::AliasTy { def_id, args, .. }) => { ty::Alias(ty::Opaque, ty::AliasTy { def_id, args, .. }) => {
// We can resolve the `impl Trait` to its concrete type, // We can resolve the `impl Trait` to its concrete type,
// which enforces a DAG between the functions requiring // which enforces a DAG between the functions requiring
// the auto trait bounds in question. // the auto trait bounds in question.
Ok(vec![ty::Binder::dummy(tcx.type_of(def_id).instantiate(tcx, &args))]) Ok(vec![ty::Binder::dummy(tcx.type_of(def_id).instantiate(tcx, args))])
} }
} }
} }
@ -147,7 +145,7 @@ where
// impl Sized for () // impl Sized for ()
// impl Sized for (T1, T2, .., Tn) where Tn: Sized if n >= 1 // impl Sized for (T1, T2, .., Tn) where Tn: Sized if n >= 1
ty::Tuple(tys) => Ok(tys.last().map_or_else(Vec::new, |&ty| vec![ty::Binder::dummy(ty)])), ty::Tuple(tys) => Ok(tys.last().map_or_else(Vec::new, |ty| vec![ty::Binder::dummy(ty)])),
// impl Sized for Adt<Args...> where sized_constraint(Adt)<Args...>: Sized // impl Sized for Adt<Args...> where sized_constraint(Adt)<Args...>: Sized
// `sized_constraint(Adt)` is the deepest struct trail that can be determined // `sized_constraint(Adt)` is the deepest struct trail that can be determined
@ -160,7 +158,7 @@ where
// if the ADT is sized for all possible args. // if the ADT is sized for all possible args.
ty::Adt(def, args) => { ty::Adt(def, args) => {
if let Some(sized_crit) = def.sized_constraint(ecx.cx()) { if let Some(sized_crit) = def.sized_constraint(ecx.cx()) {
Ok(vec![ty::Binder::dummy(sized_crit.instantiate(ecx.cx(), &args))]) Ok(vec![ty::Binder::dummy(sized_crit.instantiate(ecx.cx(), args))])
} else { } else {
Ok(vec![]) Ok(vec![])
} }
@ -213,7 +211,7 @@ where
} }
// impl Copy/Clone for (T1, T2, .., Tn) where T1: Copy/Clone, T2: Copy/Clone, .. Tn: Copy/Clone // impl Copy/Clone for (T1, T2, .., Tn) where T1: Copy/Clone, T2: Copy/Clone, .. Tn: Copy/Clone
ty::Tuple(tys) => Ok(tys.into_iter().map(ty::Binder::dummy).collect()), ty::Tuple(tys) => Ok(tys.iter().map(ty::Binder::dummy).collect()),
// impl Copy/Clone for Closure where Self::TupledUpvars: Copy/Clone // impl Copy/Clone for Closure where Self::TupledUpvars: Copy/Clone
ty::Closure(_, args) => Ok(vec![ty::Binder::dummy(args.as_closure().tupled_upvars_ty())]), ty::Closure(_, args) => Ok(vec![ty::Binder::dummy(args.as_closure().tupled_upvars_ty())]),
@ -242,7 +240,7 @@ where
.cx() .cx()
.bound_coroutine_hidden_types(def_id) .bound_coroutine_hidden_types(def_id)
.into_iter() .into_iter()
.map(|bty| bty.instantiate(ecx.cx(), &args)) .map(|bty| bty.instantiate(ecx.cx(), args))
.collect()), .collect()),
} }
} }
@ -259,8 +257,8 @@ pub(in crate::solve) fn extract_tupled_inputs_and_output_from_callable<I: Intern
let sig = tcx.fn_sig(def_id); let sig = tcx.fn_sig(def_id);
if sig.skip_binder().is_fn_trait_compatible() && !tcx.has_target_features(def_id) { if sig.skip_binder().is_fn_trait_compatible() && !tcx.has_target_features(def_id) {
Ok(Some( Ok(Some(
sig.instantiate(tcx, &args) sig.instantiate(tcx, args)
.map_bound(|sig| (Ty::new_tup(tcx, &sig.inputs()), sig.output())), .map_bound(|sig| (Ty::new_tup(tcx, sig.inputs().as_slice()), sig.output())),
)) ))
} else { } else {
Err(NoSolution) Err(NoSolution)
@ -269,7 +267,9 @@ pub(in crate::solve) fn extract_tupled_inputs_and_output_from_callable<I: Intern
// keep this in sync with assemble_fn_pointer_candidates until the old solver is removed. // keep this in sync with assemble_fn_pointer_candidates until the old solver is removed.
ty::FnPtr(sig) => { ty::FnPtr(sig) => {
if sig.is_fn_trait_compatible() { if sig.is_fn_trait_compatible() {
Ok(Some(sig.map_bound(|sig| (Ty::new_tup(tcx, &sig.inputs()), sig.output())))) Ok(Some(
sig.map_bound(|sig| (Ty::new_tup(tcx, sig.inputs().as_slice()), sig.output())),
))
} else { } else {
Err(NoSolution) Err(NoSolution)
} }
@ -292,7 +292,9 @@ pub(in crate::solve) fn extract_tupled_inputs_and_output_from_callable<I: Intern
} }
} }
} }
Ok(Some(closure_args.sig().map_bound(|sig| (sig.inputs()[0], sig.output())))) Ok(Some(
closure_args.sig().map_bound(|sig| (sig.inputs().get(0).unwrap(), sig.output())),
))
} }
// Coroutine-closures don't implement `Fn` traits the normal way. // Coroutine-closures don't implement `Fn` traits the normal way.
@ -470,7 +472,7 @@ pub(in crate::solve) fn extract_tupled_inputs_and_output_from_async_callable<I:
let future_output_ty = Ty::new_projection(tcx, future_output_def_id, [sig.output()]); let future_output_ty = Ty::new_projection(tcx, future_output_def_id, [sig.output()]);
Ok(( Ok((
bound_sig.rebind(AsyncCallableRelevantTypes { bound_sig.rebind(AsyncCallableRelevantTypes {
tupled_inputs_ty: Ty::new_tup(tcx, &sig.inputs()), tupled_inputs_ty: Ty::new_tup(tcx, sig.inputs().as_slice()),
output_coroutine_ty: sig.output(), output_coroutine_ty: sig.output(),
coroutine_return_ty: future_output_ty, coroutine_return_ty: future_output_ty,
}), }),
@ -521,7 +523,7 @@ pub(in crate::solve) fn extract_tupled_inputs_and_output_from_async_callable<I:
let future_output_ty = Ty::new_projection(tcx, future_output_def_id, [sig.output()]); let future_output_ty = Ty::new_projection(tcx, future_output_def_id, [sig.output()]);
Ok(( Ok((
bound_sig.rebind(AsyncCallableRelevantTypes { bound_sig.rebind(AsyncCallableRelevantTypes {
tupled_inputs_ty: sig.inputs()[0], tupled_inputs_ty: sig.inputs().get(0).unwrap(),
output_coroutine_ty: sig.output(), output_coroutine_ty: sig.output(),
coroutine_return_ty: future_output_ty, coroutine_return_ty: future_output_ty,
}), }),
@ -669,7 +671,7 @@ where
let tcx = ecx.cx(); let tcx = ecx.cx();
let mut requirements = vec![]; let mut requirements = vec![];
requirements requirements
.extend(tcx.super_predicates_of(trait_ref.def_id).iter_instantiated(tcx, &trait_ref.args)); .extend(tcx.super_predicates_of(trait_ref.def_id).iter_instantiated(tcx, trait_ref.args));
// FIXME(associated_const_equality): Also add associated consts to // FIXME(associated_const_equality): Also add associated consts to
// the requirements here. // the requirements here.
@ -680,13 +682,12 @@ where
continue; continue;
} }
requirements.extend( requirements
tcx.item_bounds(associated_type_def_id).iter_instantiated(tcx, &trait_ref.args), .extend(tcx.item_bounds(associated_type_def_id).iter_instantiated(tcx, trait_ref.args));
);
} }
let mut replace_projection_with = HashMap::default(); let mut replace_projection_with = HashMap::default();
for bound in object_bounds { for bound in object_bounds.iter() {
if let ty::ExistentialPredicate::Projection(proj) = bound.skip_binder() { if let ty::ExistentialPredicate::Projection(proj) = bound.skip_binder() {
let proj = proj.with_self_ty(tcx, trait_ref.self_ty()); let proj = proj.with_self_ty(tcx, trait_ref.self_ty());
let old_ty = replace_projection_with.insert(proj.def_id(), bound.rebind(proj)); let old_ty = replace_projection_with.insert(proj.def_id(), bound.rebind(proj));

View file

@ -267,7 +267,9 @@ where
// We therefore instantiate the existential variable in the canonical response with the // We therefore instantiate the existential variable in the canonical response with the
// inference variable of the input right away, which is more performant. // inference variable of the input right away, which is more performant.
let mut opt_values = IndexVec::from_elem_n(None, response.variables.len()); let mut opt_values = IndexVec::from_elem_n(None, response.variables.len());
for (original_value, result_value) in iter::zip(original_values, var_values.var_values) { for (original_value, result_value) in
iter::zip(original_values, var_values.var_values.iter())
{
match result_value.kind() { match result_value.kind() {
ty::GenericArgKind::Type(t) => { ty::GenericArgKind::Type(t) => {
if let ty::Bound(debruijn, b) = t.kind() { if let ty::Bound(debruijn, b) = t.kind() {
@ -291,7 +293,7 @@ where
} }
let var_values = delegate.cx().mk_args_from_iter( let var_values = delegate.cx().mk_args_from_iter(
response.variables.into_iter().enumerate().map(|(index, info)| { response.variables.iter().enumerate().map(|(index, info)| {
if info.universe() != ty::UniverseIndex::ROOT { if info.universe() != ty::UniverseIndex::ROOT {
// A variable from inside a binder of the query. While ideally these shouldn't // A variable from inside a binder of the query. While ideally these shouldn't
// exist at all (see the FIXME at the start of this method), we have to deal with // exist at all (see the FIXME at the start of this method), we have to deal with
@ -344,7 +346,7 @@ where
) { ) {
assert_eq!(original_values.len(), var_values.len()); assert_eq!(original_values.len(), var_values.len());
for (&orig, response) in iter::zip(original_values, var_values.var_values) { for (&orig, response) in iter::zip(original_values, var_values.var_values.iter()) {
let goals = let goals =
delegate.eq_structurally_relating_aliases(param_env, orig, response).unwrap(); delegate.eq_structurally_relating_aliases(param_env, orig, response).unwrap();
assert!(goals.is_empty()); assert!(goals.is_empty());
@ -413,7 +415,8 @@ where
// In case any fresh inference variables have been created between `state` // In case any fresh inference variables have been created between `state`
// and the previous instantiation, extend `orig_values` for it. // and the previous instantiation, extend `orig_values` for it.
assert!(orig_values.len() <= state.value.var_values.len()); assert!(orig_values.len() <= state.value.var_values.len());
for &arg in &state.value.var_values.var_values[orig_values.len()..state.value.var_values.len()] for &arg in &state.value.var_values.var_values.as_slice()
[orig_values.len()..state.value.var_values.len()]
{ {
// FIXME: This is so ugly. // FIXME: This is so ugly.
let unconstrained = delegate.fresh_var_for_kind_with_span(arg, span); let unconstrained = delegate.fresh_var_for_kind_with_span(arg, span);

View file

@ -787,7 +787,7 @@ where
// Alternatively we could modify `Equate` for this case by adding another // Alternatively we could modify `Equate` for this case by adding another
// variant to `StructurallyRelateAliases`. // variant to `StructurallyRelateAliases`.
let identity_args = self.fresh_args_for_item(alias.def_id); let identity_args = self.fresh_args_for_item(alias.def_id);
let rigid_ctor = ty::AliasTerm::new(tcx, alias.def_id, identity_args); let rigid_ctor = ty::AliasTerm::new_from_args(tcx, alias.def_id, identity_args);
let ctor_term = rigid_ctor.to_term(tcx); let ctor_term = rigid_ctor.to_term(tcx);
let obligations = let obligations =
self.delegate.eq_structurally_relating_aliases(param_env, term, ctor_term)?; self.delegate.eq_structurally_relating_aliases(param_env, term, ctor_term)?;
@ -875,7 +875,7 @@ where
pub(super) fn fresh_args_for_item(&mut self, def_id: I::DefId) -> I::GenericArgs { pub(super) fn fresh_args_for_item(&mut self, def_id: I::DefId) -> I::GenericArgs {
let args = self.delegate.fresh_args_for_item(def_id); let args = self.delegate.fresh_args_for_item(def_id);
for arg in args { for arg in args.iter() {
self.inspect.add_var_value(arg); self.inspect.add_var_value(arg);
} }
args args
@ -979,7 +979,7 @@ where
result: *result, result: *result,
}) })
.enter(|ecx| { .enter(|ecx| {
for (a, b) in std::iter::zip(candidate_key.args, key.args) { for (a, b) in std::iter::zip(candidate_key.args.iter(), key.args.iter()) {
ecx.eq(param_env, a, b)?; ecx.eq(param_env, a, b)?;
} }
ecx.eq(param_env, candidate_ty, ty)?; ecx.eq(param_env, candidate_ty, ty)?;

View file

@ -7,6 +7,7 @@
use std::marker::PhantomData; use std::marker::PhantomData;
use std::mem; use std::mem;
use rustc_type_ir::inherent::*;
use rustc_type_ir::{self as ty, Interner}; use rustc_type_ir::{self as ty, Interner};
use crate::delegate::SolverDelegate; use crate::delegate::SolverDelegate;

View file

@ -182,7 +182,7 @@ where
return self.evaluate_added_goals_and_make_canonical_response(Certainty::Yes); return self.evaluate_added_goals_and_make_canonical_response(Certainty::Yes);
} }
ty::ConstKind::Unevaluated(uv) => { ty::ConstKind::Unevaluated(uv) => {
self.cx().type_of(uv.def).instantiate(self.cx(), &uv.args) self.cx().type_of(uv.def).instantiate(self.cx(), uv.args)
} }
ty::ConstKind::Expr(_) => unimplemented!( ty::ConstKind::Expr(_) => unimplemented!(
"`feature(generic_const_exprs)` is not supported in the new trait solver" "`feature(generic_const_exprs)` is not supported in the new trait solver"

View file

@ -29,7 +29,7 @@ where
self.eq( self.eq(
goal.param_env, goal.param_env,
inherent.self_ty(), inherent.self_ty(),
tcx.type_of(impl_def_id).instantiate(tcx, &impl_args), tcx.type_of(impl_def_id).instantiate(tcx, impl_args),
)?; )?;
// Equate IAT with the RHS of the project goal // Equate IAT with the RHS of the project goal
@ -44,11 +44,11 @@ where
self.add_goals( self.add_goals(
GoalSource::Misc, GoalSource::Misc,
tcx.predicates_of(inherent.def_id) tcx.predicates_of(inherent.def_id)
.iter_instantiated(tcx, &inherent_args) .iter_instantiated(tcx, inherent_args)
.map(|pred| goal.with(tcx, pred)), .map(|pred| goal.with(tcx, pred)),
); );
let normalized = tcx.type_of(inherent.def_id).instantiate(tcx, &inherent_args); let normalized = tcx.type_of(inherent.def_id).instantiate(tcx, inherent_args);
self.instantiate_normalizes_to_term(goal, normalized.into()); self.instantiate_normalizes_to_term(goal, normalized.into());
self.evaluate_added_goals_and_make_canonical_response(Certainty::Yes) self.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)
} }

View file

@ -121,7 +121,7 @@ where
ecx.add_goals( ecx.add_goals(
GoalSource::Misc, GoalSource::Misc,
tcx.own_predicates_of(goal.predicate.def_id()) tcx.own_predicates_of(goal.predicate.def_id())
.iter_instantiated(tcx, &goal.predicate.alias.args) .iter_instantiated(tcx, goal.predicate.alias.args)
.map(|pred| goal.with(tcx, pred)), .map(|pred| goal.with(tcx, pred)),
); );
@ -163,13 +163,13 @@ where
ecx.probe_trait_candidate(CandidateSource::Impl(impl_def_id)).enter(|ecx| { ecx.probe_trait_candidate(CandidateSource::Impl(impl_def_id)).enter(|ecx| {
let impl_args = ecx.fresh_args_for_item(impl_def_id); let impl_args = ecx.fresh_args_for_item(impl_def_id);
let impl_trait_ref = impl_trait_ref.instantiate(tcx, &impl_args); let impl_trait_ref = impl_trait_ref.instantiate(tcx, impl_args);
ecx.eq(goal.param_env, goal_trait_ref, impl_trait_ref)?; ecx.eq(goal.param_env, goal_trait_ref, impl_trait_ref)?;
let where_clause_bounds = tcx let where_clause_bounds = tcx
.predicates_of(impl_def_id) .predicates_of(impl_def_id)
.iter_instantiated(tcx, &impl_args) .iter_instantiated(tcx, impl_args)
.map(|pred| goal.with(tcx, pred)); .map(|pred| goal.with(tcx, pred));
ecx.add_goals(GoalSource::ImplWhereBound, where_clause_bounds); ecx.add_goals(GoalSource::ImplWhereBound, where_clause_bounds);
@ -177,7 +177,7 @@ where
ecx.add_goals( ecx.add_goals(
GoalSource::Misc, GoalSource::Misc,
tcx.own_predicates_of(goal.predicate.def_id()) tcx.own_predicates_of(goal.predicate.def_id())
.iter_instantiated(tcx, &goal.predicate.alias.args) .iter_instantiated(tcx, goal.predicate.alias.args)
.map(|pred| goal.with(tcx, pred)), .map(|pred| goal.with(tcx, pred)),
); );
@ -254,7 +254,7 @@ where
kind => panic!("expected projection, found {kind:?}"), kind => panic!("expected projection, found {kind:?}"),
}; };
ecx.instantiate_normalizes_to_term(goal, term.instantiate(tcx, &target_args)); ecx.instantiate_normalizes_to_term(goal, term.instantiate(tcx, target_args));
ecx.evaluate_added_goals_and_make_canonical_response(Certainty::Yes) ecx.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)
}) })
} }
@ -467,7 +467,7 @@ where
tupled_inputs_ty, tupled_inputs_ty,
tupled_upvars_ty, tupled_upvars_ty,
coroutine_captures_by_ref_ty, coroutine_captures_by_ref_ty,
] = **goal.predicate.alias.args ] = *goal.predicate.alias.args.as_slice()
else { else {
panic!(); panic!();
}; };
@ -567,14 +567,14 @@ where
ty::Adt(def, args) if def.is_struct() => match def.struct_tail_ty(tcx) { ty::Adt(def, args) if def.is_struct() => match def.struct_tail_ty(tcx) {
None => Ty::new_unit(tcx), None => Ty::new_unit(tcx),
Some(tail_ty) => { Some(tail_ty) => {
Ty::new_projection(tcx, metadata_def_id, [tail_ty.instantiate(tcx, &args)]) Ty::new_projection(tcx, metadata_def_id, [tail_ty.instantiate(tcx, args)])
} }
}, },
ty::Adt(_, _) => Ty::new_unit(tcx), ty::Adt(_, _) => Ty::new_unit(tcx),
ty::Tuple(elements) => match elements.last() { ty::Tuple(elements) => match elements.last() {
None => Ty::new_unit(tcx), None => Ty::new_unit(tcx),
Some(&tail_ty) => Ty::new_projection(tcx, metadata_def_id, [tail_ty]), Some(tail_ty) => Ty::new_projection(tcx, metadata_def_id, [tail_ty]),
}, },
ty::Infer( ty::Infer(
@ -895,7 +895,7 @@ where
} else { } else {
let target_args = self.fresh_args_for_item(target_container_def_id); let target_args = self.fresh_args_for_item(target_container_def_id);
let target_trait_ref = let target_trait_ref =
tcx.impl_trait_ref(target_container_def_id).instantiate(tcx, &target_args); tcx.impl_trait_ref(target_container_def_id).instantiate(tcx, target_args);
// Relate source impl to target impl by equating trait refs. // Relate source impl to target impl by equating trait refs.
self.eq(goal.param_env, impl_trait_ref, target_trait_ref)?; self.eq(goal.param_env, impl_trait_ref, target_trait_ref)?;
// Also add predicates since they may be needed to constrain the // Also add predicates since they may be needed to constrain the
@ -903,7 +903,7 @@ where
self.add_goals( self.add_goals(
GoalSource::Misc, GoalSource::Misc,
tcx.predicates_of(target_container_def_id) tcx.predicates_of(target_container_def_id)
.iter_instantiated(tcx, &target_args) .iter_instantiated(tcx, target_args)
.map(|pred| goal.with(tcx, pred)), .map(|pred| goal.with(tcx, pred)),
); );
goal.predicate.alias.args.rebase_onto(tcx, impl_trait_ref.def_id, target_args) goal.predicate.alias.args.rebase_onto(tcx, impl_trait_ref.def_id, target_args)

View file

@ -86,7 +86,7 @@ where
} }
(Reveal::All, _) => { (Reveal::All, _) => {
// FIXME: Add an assertion that opaque type storage is empty. // FIXME: Add an assertion that opaque type storage is empty.
let actual = tcx.type_of(opaque_ty.def_id).instantiate(tcx, &opaque_ty.args); let actual = tcx.type_of(opaque_ty.def_id).instantiate(tcx, opaque_ty.args);
self.eq(goal.param_env, expected, actual)?; self.eq(goal.param_env, expected, actual)?;
self.evaluate_added_goals_and_make_canonical_response(Certainty::Yes) self.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)
} }
@ -102,7 +102,7 @@ pub fn uses_unique_placeholders_ignoring_regions<I: Interner>(
args: I::GenericArgs, args: I::GenericArgs,
) -> Result<(), NotUniqueParam<I>> { ) -> Result<(), NotUniqueParam<I>> {
let mut seen = GrowableBitSet::default(); let mut seen = GrowableBitSet::default();
for arg in args { for arg in args.iter() {
match arg.kind() { match arg.kind() {
// Ignore regions, since we can't resolve those in a canonicalized // Ignore regions, since we can't resolve those in a canonicalized
// query in the trait solver. // query in the trait solver.

View file

@ -25,11 +25,11 @@ where
self.add_goals( self.add_goals(
GoalSource::Misc, GoalSource::Misc,
tcx.predicates_of(weak_ty.def_id) tcx.predicates_of(weak_ty.def_id)
.iter_instantiated(tcx, &weak_ty.args) .iter_instantiated(tcx, weak_ty.args)
.map(|pred| goal.with(tcx, pred)), .map(|pred| goal.with(tcx, pred)),
); );
let actual = tcx.type_of(weak_ty.def_id).instantiate(tcx, &weak_ty.args); let actual = tcx.type_of(weak_ty.def_id).instantiate(tcx, weak_ty.args);
self.instantiate_normalizes_to_term(goal, actual.into()); self.instantiate_normalizes_to_term(goal, actual.into());
self.evaluate_added_goals_and_make_canonical_response(Certainty::Yes) self.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)

View file

@ -77,12 +77,12 @@ where
ecx.probe_trait_candidate(CandidateSource::Impl(impl_def_id)).enter(|ecx| { ecx.probe_trait_candidate(CandidateSource::Impl(impl_def_id)).enter(|ecx| {
let impl_args = ecx.fresh_args_for_item(impl_def_id); let impl_args = ecx.fresh_args_for_item(impl_def_id);
ecx.record_impl_args(impl_args); ecx.record_impl_args(impl_args);
let impl_trait_ref = impl_trait_ref.instantiate(tcx, &impl_args); let impl_trait_ref = impl_trait_ref.instantiate(tcx, impl_args);
ecx.eq(goal.param_env, goal.predicate.trait_ref, impl_trait_ref)?; ecx.eq(goal.param_env, goal.predicate.trait_ref, impl_trait_ref)?;
let where_clause_bounds = tcx let where_clause_bounds = tcx
.predicates_of(impl_def_id) .predicates_of(impl_def_id)
.iter_instantiated(tcx, &impl_args) .iter_instantiated(tcx, impl_args)
.map(|pred| goal.with(tcx, pred)); .map(|pred| goal.with(tcx, pred));
ecx.add_goals(GoalSource::ImplWhereBound, where_clause_bounds); ecx.add_goals(GoalSource::ImplWhereBound, where_clause_bounds);
@ -186,7 +186,7 @@ where
ecx.probe_builtin_trait_candidate(BuiltinImplSource::Misc).enter(|ecx| { ecx.probe_builtin_trait_candidate(BuiltinImplSource::Misc).enter(|ecx| {
let nested_obligations = tcx let nested_obligations = tcx
.predicates_of(goal.predicate.def_id()) .predicates_of(goal.predicate.def_id())
.iter_instantiated(tcx, &goal.predicate.trait_ref.args) .iter_instantiated(tcx, goal.predicate.trait_ref.args)
.map(|p| goal.with(tcx, p)); .map(|p| goal.with(tcx, p));
// FIXME(-Znext-solver=coinductive): Should this be `GoalSource::ImplWhereBound`? // FIXME(-Znext-solver=coinductive): Should this be `GoalSource::ImplWhereBound`?
ecx.add_goals(GoalSource::Misc, nested_obligations); ecx.add_goals(GoalSource::Misc, nested_obligations);
@ -373,7 +373,7 @@ where
ecx: &mut EvalCtxt<'_, D>, ecx: &mut EvalCtxt<'_, D>,
goal: Goal<I, Self>, goal: Goal<I, Self>,
) -> Result<Candidate<I>, NoSolution> { ) -> Result<Candidate<I>, NoSolution> {
let [closure_fn_kind_ty, goal_kind_ty] = **goal.predicate.trait_ref.args else { let [closure_fn_kind_ty, goal_kind_ty] = *goal.predicate.trait_ref.args.as_slice() else {
panic!(); panic!();
}; };
@ -783,7 +783,7 @@ where
// (i.e. the principal, all of the associated types match, and any auto traits) // (i.e. the principal, all of the associated types match, and any auto traits)
ecx.add_goals( ecx.add_goals(
GoalSource::ImplWhereBound, GoalSource::ImplWhereBound,
b_data.into_iter().map(|pred| goal.with(tcx, pred.with_self_ty(tcx, a_ty))), b_data.iter().map(|pred| goal.with(tcx, pred.with_self_ty(tcx, a_ty))),
); );
// The type must be `Sized` to be unsized. // The type must be `Sized` to be unsized.
@ -851,7 +851,7 @@ where
}; };
self.probe_trait_candidate(source).enter(|ecx| { self.probe_trait_candidate(source).enter(|ecx| {
for bound in b_data { for bound in b_data.iter() {
match bound.skip_binder() { match bound.skip_binder() {
// Check that a's supertrait (upcast_principal) is compatible // Check that a's supertrait (upcast_principal) is compatible
// with the target (b_ty). // with the target (b_ty).
@ -953,18 +953,15 @@ where
let tail_field_ty = def.struct_tail_ty(tcx).unwrap(); let tail_field_ty = def.struct_tail_ty(tcx).unwrap();
let a_tail_ty = tail_field_ty.instantiate(tcx, &a_args); let a_tail_ty = tail_field_ty.instantiate(tcx, a_args);
let b_tail_ty = tail_field_ty.instantiate(tcx, &b_args); let b_tail_ty = tail_field_ty.instantiate(tcx, b_args);
// Instantiate just the unsizing params from B into A. The type after // Instantiate just the unsizing params from B into A. The type after
// this instantiation must be equal to B. This is so we don't unsize // this instantiation must be equal to B. This is so we don't unsize
// unrelated type parameters. // unrelated type parameters.
let new_a_args = tcx.mk_args_from_iter( let new_a_args = tcx.mk_args_from_iter(a_args.iter().enumerate().map(|(i, a)| {
a_args if unsizing_params.contains(i as u32) { b_args.get(i).unwrap() } else { a }
.iter() }));
.enumerate()
.map(|(i, a)| if unsizing_params.contains(i as u32) { b_args[i] } else { *a }),
);
let unsized_a_ty = Ty::new_adt(tcx, def, new_a_args); let unsized_a_ty = Ty::new_adt(tcx, def, new_a_args);
// Finally, we require that `TailA: Unsize<TailB>` for the tail field // Finally, we require that `TailA: Unsize<TailB>` for the tail field
@ -1005,7 +1002,7 @@ where
let Goal { predicate: (_a_ty, b_ty), .. } = goal; let Goal { predicate: (_a_ty, b_ty), .. } = goal;
let (&a_last_ty, a_rest_tys) = a_tys.split_last().unwrap(); let (&a_last_ty, a_rest_tys) = a_tys.split_last().unwrap();
let &b_last_ty = b_tys.last().unwrap(); let b_last_ty = b_tys.last().unwrap();
// Instantiate just the tail field of B., and require that they're equal. // Instantiate just the tail field of B., and require that they're equal.
let unsized_a_ty = let unsized_a_ty =

View file

@ -232,7 +232,8 @@ fn trait_object_ty<'tcx>(tcx: TyCtxt<'tcx>, poly_trait_ref: ty::PolyTraitRef<'tc
.filter(|item| item.kind == ty::AssocKind::Type) .filter(|item| item.kind == ty::AssocKind::Type)
.map(move |assoc_ty| { .map(move |assoc_ty| {
super_poly_trait_ref.map_bound(|super_trait_ref| { super_poly_trait_ref.map_bound(|super_trait_ref| {
let alias_ty = ty::AliasTy::new(tcx, assoc_ty.def_id, super_trait_ref.args); let alias_ty =
ty::AliasTy::new_from_args(tcx, assoc_ty.def_id, super_trait_ref.args);
let resolved = tcx.normalize_erasing_regions( let resolved = tcx.normalize_erasing_regions(
ty::ParamEnv::reveal_all(), ty::ParamEnv::reveal_all(),
alias_ty.to_ty(tcx), alias_ty.to_ty(tcx),
@ -351,7 +352,7 @@ pub fn transform_instance<'tcx>(
// Adjust the type ids of VTableShims to the type id expected in the call sites for the // Adjust the type ids of VTableShims to the type id expected in the call sites for the
// entry in the vtable (i.e., by using the signature of the closure passed as an argument // entry in the vtable (i.e., by using the signature of the closure passed as an argument
// to the shim, or by just removing self). // to the shim, or by just removing self).
let trait_ref = ty::TraitRef::new(tcx, trait_id, instance.args); let trait_ref = ty::TraitRef::new_from_args(tcx, trait_id, instance.args);
let invoke_ty = trait_object_ty(tcx, ty::Binder::dummy(trait_ref)); let invoke_ty = trait_object_ty(tcx, ty::Binder::dummy(trait_ref));
instance.args = tcx.mk_args_trait(invoke_ty, trait_ref.args.into_iter().skip(1)); instance.args = tcx.mk_args_trait(invoke_ty, trait_ref.args.into_iter().skip(1));
} }
@ -432,7 +433,7 @@ pub fn transform_instance<'tcx>(
x => bug!("Unexpected type kind for closure-like: {x:?}"), x => bug!("Unexpected type kind for closure-like: {x:?}"),
}; };
let concrete_args = tcx.mk_args_trait(closure_ty, inputs.map(Into::into)); let concrete_args = tcx.mk_args_trait(closure_ty, inputs.map(Into::into));
let trait_ref = ty::TraitRef::new(tcx, trait_id, concrete_args); let trait_ref = ty::TraitRef::new_from_args(tcx, trait_id, concrete_args);
let invoke_ty = trait_object_ty(tcx, ty::Binder::dummy(trait_ref)); let invoke_ty = trait_object_ty(tcx, ty::Binder::dummy(trait_ref));
let abstract_args = tcx.mk_args_trait(invoke_ty, trait_ref.args.into_iter().skip(1)); let abstract_args = tcx.mk_args_trait(invoke_ty, trait_ref.args.into_iter().skip(1));
// There should be exactly one method on this trait, and it should be the one we're // There should be exactly one method on this trait, and it should be the one we're

View file

@ -408,7 +408,7 @@ impl RustcInternal for TraitRef {
type T<'tcx> = rustc_ty::TraitRef<'tcx>; type T<'tcx> = rustc_ty::TraitRef<'tcx>;
fn internal<'tcx>(&self, tables: &mut Tables<'_>, tcx: TyCtxt<'tcx>) -> Self::T<'tcx> { fn internal<'tcx>(&self, tables: &mut Tables<'_>, tcx: TyCtxt<'tcx>) -> Self::T<'tcx> {
rustc_ty::TraitRef::new( rustc_ty::TraitRef::new_from_args(
tcx, tcx,
self.def_id.0.internal(tables, tcx), self.def_id.0.internal(tables, tcx),
self.args().internal(tables, tcx), self.args().internal(tables, tcx),

View file

@ -630,7 +630,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
let trait_pred_and_ty = trait_pred.map_bound(|inner| { let trait_pred_and_ty = trait_pred.map_bound(|inner| {
( (
ty::TraitPredicate { ty::TraitPredicate {
trait_ref: ty::TraitRef::new( trait_ref: ty::TraitRef::new_from_args(
self.tcx, self.tcx,
inner.trait_ref.def_id, inner.trait_ref.def_id,
self.tcx.mk_args( self.tcx.mk_args(
@ -3929,7 +3929,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
// Extract `<U as Deref>::Target` assoc type and check that it is `T` // Extract `<U as Deref>::Target` assoc type and check that it is `T`
&& let Some(deref_target_did) = tcx.lang_items().deref_target() && 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) && 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)) && obligations.iter().all(|obligation| infcx.predicate_must_hold_modulo_regions(obligation))
&& infcx.can_eq(param_env, deref_target, target_ty) && infcx.can_eq(param_env, deref_target, target_ty)
@ -4264,7 +4264,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
// This corresponds to `<ExprTy as Iterator>::Item = _`. // This corresponds to `<ExprTy as Iterator>::Item = _`.
let projection = ty::Binder::dummy(ty::PredicateKind::Clause( let projection = ty::Binder::dummy(ty::PredicateKind::Clause(
ty::ClauseKind::Projection(ty::ProjectionPredicate { 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(), 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) } 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 = let caller_bounds =

View file

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

View file

@ -940,7 +940,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
let ty = traits::normalize_projection_ty( let ty = traits::normalize_projection_ty(
self, self,
param_env, 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(), cause.clone(),
0, 0,
// We're *intentionally* throwing these away, // We're *intentionally* throwing these away,

View file

@ -2487,7 +2487,7 @@ impl<'tcx> SelectionContext<'_, 'tcx> {
trait_def_id, trait_def_id,
&[normalized_ty.into()], &[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); let obligation = Obligation::new(self.tcx(), cause.clone(), param_env, trait_ref);

View file

@ -320,7 +320,7 @@ impl<I: Interner> TypeVisitor<I> for ValidateBoundVars<I> {
if self.bound_vars.len() <= idx { if self.bound_vars.len() <= idx {
panic!("Not enough bound vars: {:?} not found in {:?}", t, self.bound_vars); panic!("Not enough bound vars: {:?} not found in {:?}", t, self.bound_vars);
} }
bound_ty.assert_eq(self.bound_vars[idx]); bound_ty.assert_eq(self.bound_vars.get(idx).unwrap());
} }
_ => {} _ => {}
}; };
@ -335,7 +335,7 @@ impl<I: Interner> TypeVisitor<I> for ValidateBoundVars<I> {
if self.bound_vars.len() <= idx { if self.bound_vars.len() <= idx {
panic!("Not enough bound vars: {:?} not found in {:?}", r, self.bound_vars); panic!("Not enough bound vars: {:?} not found in {:?}", r, self.bound_vars);
} }
br.assert_eq(self.bound_vars[idx]); br.assert_eq(self.bound_vars.get(idx).unwrap());
} }
_ => (), _ => (),
@ -435,15 +435,14 @@ impl<I: Interner, T> EarlyBinder<I, Option<T>> {
} }
} }
impl<'s, I: Interner, Iter: IntoIterator> EarlyBinder<I, Iter> impl<I: Interner, Iter: IntoIterator> EarlyBinder<I, Iter>
where where
Iter::Item: TypeFoldable<I>, Iter::Item: TypeFoldable<I>,
{ {
pub fn iter_instantiated( pub fn iter_instantiated<A>(self, tcx: I, args: A) -> IterInstantiated<I, Iter, A>
self, where
tcx: I, A: SliceLike<Item = I::GenericArg>,
args: &'s [I::GenericArg], {
) -> IterInstantiated<'s, I, Iter> {
IterInstantiated { it: self.value.into_iter(), tcx, args } IterInstantiated { it: self.value.into_iter(), tcx, args }
} }
@ -454,15 +453,16 @@ where
} }
} }
pub struct IterInstantiated<'s, I: Interner, Iter: IntoIterator> { pub struct IterInstantiated<I: Interner, Iter: IntoIterator, A> {
it: Iter::IntoIter, it: Iter::IntoIter,
tcx: I, tcx: I,
args: &'s [I::GenericArg], args: A,
} }
impl<I: Interner, Iter: IntoIterator> Iterator for IterInstantiated<'_, I, Iter> impl<I: Interner, Iter: IntoIterator, A> Iterator for IterInstantiated<I, Iter, A>
where where
Iter::Item: TypeFoldable<I>, Iter::Item: TypeFoldable<I>,
A: SliceLike<Item = I::GenericArg>,
{ {
type Item = Iter::Item; type Item = Iter::Item;
@ -478,10 +478,11 @@ where
} }
} }
impl<I: Interner, Iter: IntoIterator> DoubleEndedIterator for IterInstantiated<'_, I, Iter> impl<I: Interner, Iter: IntoIterator, A> DoubleEndedIterator for IterInstantiated<I, Iter, A>
where where
Iter::IntoIter: DoubleEndedIterator, Iter::IntoIter: DoubleEndedIterator,
Iter::Item: TypeFoldable<I>, Iter::Item: TypeFoldable<I>,
A: SliceLike<Item = I::GenericArg>,
{ {
fn next_back(&mut self) -> Option<Self::Item> { fn next_back(&mut self) -> Option<Self::Item> {
Some( Some(
@ -491,10 +492,11 @@ where
} }
} }
impl<I: Interner, Iter: IntoIterator> ExactSizeIterator for IterInstantiated<'_, I, Iter> impl<I: Interner, Iter: IntoIterator, A> ExactSizeIterator for IterInstantiated<I, Iter, A>
where where
Iter::IntoIter: ExactSizeIterator, Iter::IntoIter: ExactSizeIterator,
Iter::Item: TypeFoldable<I>, Iter::Item: TypeFoldable<I>,
A: SliceLike<Item = I::GenericArg>,
{ {
} }
@ -589,8 +591,11 @@ impl<I: Interner, T: Iterator> Iterator for EarlyBinderIter<I, T> {
} }
impl<I: Interner, T: TypeFoldable<I>> ty::EarlyBinder<I, T> { impl<I: Interner, T: TypeFoldable<I>> ty::EarlyBinder<I, T> {
pub fn instantiate(self, tcx: I, args: &[I::GenericArg]) -> T { pub fn instantiate<A>(self, tcx: I, args: A) -> T
let mut folder = ArgFolder { tcx, args, binders_passed: 0 }; where
A: SliceLike<Item = I::GenericArg>,
{
let mut folder = ArgFolder { tcx, args: args.as_slice(), binders_passed: 0 };
self.value.fold_with(&mut folder) self.value.fold_with(&mut folder)
} }

View file

@ -283,7 +283,7 @@ pub struct CanonicalVarValues<I: Interner> {
impl<I: Interner> CanonicalVarValues<I> { impl<I: Interner> CanonicalVarValues<I> {
pub fn is_identity(&self) -> bool { pub fn is_identity(&self) -> bool {
self.var_values.into_iter().enumerate().all(|(bv, arg)| match arg.kind() { self.var_values.iter().enumerate().all(|(bv, arg)| match arg.kind() {
ty::GenericArgKind::Lifetime(r) => { ty::GenericArgKind::Lifetime(r) => {
matches!(r.kind(), ty::ReBound(ty::INNERMOST, br) if br.var().as_usize() == bv) matches!(r.kind(), ty::ReBound(ty::INNERMOST, br) if br.var().as_usize() == bv)
} }
@ -298,7 +298,7 @@ impl<I: Interner> CanonicalVarValues<I> {
pub fn is_identity_modulo_regions(&self) -> bool { pub fn is_identity_modulo_regions(&self) -> bool {
let mut var = ty::BoundVar::ZERO; let mut var = ty::BoundVar::ZERO;
for arg in self.var_values { for arg in self.var_values.iter() {
match arg.kind() { match arg.kind() {
ty::GenericArgKind::Lifetime(r) => { ty::GenericArgKind::Lifetime(r) => {
if matches!(r.kind(), ty::ReBound(ty::INNERMOST, br) if var == br.var()) { if matches!(r.kind(), ty::ReBound(ty::INNERMOST, br) if var == br.var()) {
@ -332,7 +332,7 @@ impl<I: Interner> CanonicalVarValues<I> {
// the identity response. // the identity response.
pub fn make_identity(tcx: I, infos: I::CanonicalVars) -> CanonicalVarValues<I> { pub fn make_identity(tcx: I, infos: I::CanonicalVars) -> CanonicalVarValues<I> {
CanonicalVarValues { CanonicalVarValues {
var_values: tcx.mk_args_from_iter(infos.into_iter().enumerate().map( var_values: tcx.mk_args_from_iter(infos.iter().enumerate().map(
|(i, info)| -> I::GenericArg { |(i, info)| -> I::GenericArg {
match info.kind { match info.kind {
CanonicalVarKind::Ty(_) | CanonicalVarKind::PlaceholderTy(_) => { CanonicalVarKind::Ty(_) | CanonicalVarKind::PlaceholderTy(_) => {
@ -371,10 +371,10 @@ impl<I: Interner> CanonicalVarValues<I> {
impl<'a, I: Interner> IntoIterator for &'a CanonicalVarValues<I> { impl<'a, I: Interner> IntoIterator for &'a CanonicalVarValues<I> {
type Item = I::GenericArg; type Item = I::GenericArg;
type IntoIter = <I::GenericArgs as IntoIterator>::IntoIter; type IntoIter = <I::GenericArgs as SliceLike>::IntoIter;
fn into_iter(self) -> Self::IntoIter { fn into_iter(self) -> Self::IntoIter {
self.var_values.into_iter() self.var_values.iter()
} }
} }
@ -382,6 +382,6 @@ impl<I: Interner> Index<ty::BoundVar> for CanonicalVarValues<I> {
type Output = I::GenericArg; type Output = I::GenericArg;
fn index(&self, value: ty::BoundVar) -> &I::GenericArg { fn index(&self, value: ty::BoundVar) -> &I::GenericArg {
&self.var_values[value.as_usize()] &self.var_values.as_slice()[value.as_usize()]
} }
} }

View file

@ -5,7 +5,6 @@
use std::fmt::Debug; use std::fmt::Debug;
use std::hash::Hash; use std::hash::Hash;
use std::ops::Deref;
use rustc_ast_ir::Mutability; use rustc_ast_ir::Mutability;
@ -47,6 +46,14 @@ pub trait Ty<I: Interner<Ty = Self>>:
fn new_alias(interner: I, kind: ty::AliasTyKind, alias_ty: ty::AliasTy<I>) -> Self; fn new_alias(interner: I, kind: ty::AliasTyKind, alias_ty: ty::AliasTy<I>) -> Self;
fn new_projection_from_args(interner: I, def_id: I::DefId, args: I::GenericArgs) -> Self {
Ty::new_alias(
interner,
ty::AliasTyKind::Projection,
ty::AliasTy::new_from_args(interner, def_id, args),
)
}
fn new_projection( fn new_projection(
interner: I, interner: I,
def_id: I::DefId, def_id: I::DefId,
@ -120,7 +127,7 @@ pub trait Ty<I: Interner<Ty = Self>>:
fn fn_sig(self, interner: I) -> ty::Binder<I, ty::FnSig<I>> { fn fn_sig(self, interner: I) -> ty::Binder<I, ty::FnSig<I>> {
match self.kind() { match self.kind() {
ty::FnPtr(sig) => sig, ty::FnPtr(sig) => sig,
ty::FnDef(def_id, args) => interner.fn_sig(def_id).instantiate(interner, &args), ty::FnDef(def_id, args) => interner.fn_sig(def_id).instantiate(interner, args),
ty::Error(_) => { ty::Error(_) => {
// ignore errors (#54954) // ignore errors (#54954)
ty::Binder::dummy(ty::FnSig { ty::Binder::dummy(ty::FnSig {
@ -182,14 +189,7 @@ pub trait Ty<I: Interner<Ty = Self>>:
} }
pub trait Tys<I: Interner<Tys = Self>>: pub trait Tys<I: Interner<Tys = Self>>:
Copy Copy + Debug + Hash + Eq + SliceLike<Item = I::Ty> + TypeFoldable<I> + Default
+ Debug
+ Hash
+ Eq
+ IntoIterator<Item = I::Ty>
+ Deref<Target: Deref<Target = [I::Ty]>>
+ TypeFoldable<I>
+ Default
{ {
fn split_inputs_and_output(self) -> (I::FnInputTys, I::Ty); fn split_inputs_and_output(self) -> (I::FnInputTys, I::Ty);
} }
@ -354,14 +354,7 @@ pub trait Term<I: Interner<Term = Self>>:
} }
pub trait GenericArgs<I: Interner<GenericArgs = Self>>: pub trait GenericArgs<I: Interner<GenericArgs = Self>>:
Copy Copy + Debug + Hash + Eq + SliceLike<Item = I::GenericArg> + Default + Relate<I>
+ Debug
+ Hash
+ Eq
+ IntoIterator<Item = I::GenericArg>
+ Deref<Target: Deref<Target = [I::GenericArg]>>
+ Default
+ Relate<I>
{ {
fn rebase_onto( fn rebase_onto(
self, self,
@ -553,12 +546,7 @@ pub trait DefId<I: Interner>: Copy + Debug + Hash + Eq + TypeFoldable<I> {
} }
pub trait BoundExistentialPredicates<I: Interner>: pub trait BoundExistentialPredicates<I: Interner>:
Copy Copy + Debug + Hash + Eq + Relate<I> + SliceLike<Item = ty::Binder<I, ty::ExistentialPredicate<I>>>
+ Debug
+ Hash
+ Eq
+ Relate<I>
+ IntoIterator<Item = ty::Binder<I, ty::ExistentialPredicate<I>>>
{ {
fn principal_def_id(self) -> Option<I::DefId>; fn principal_def_id(self) -> Option<I::DefId>;
@ -570,3 +558,82 @@ pub trait BoundExistentialPredicates<I: Interner>:
self, self,
) -> impl IntoIterator<Item = ty::Binder<I, ty::ExistentialProjection<I>>>; ) -> impl IntoIterator<Item = ty::Binder<I, ty::ExistentialProjection<I>>>;
} }
pub trait SliceLike: Sized + Copy {
type Item: Copy;
type IntoIter: Iterator<Item = Self::Item>;
fn iter(self) -> Self::IntoIter;
fn as_slice(&self) -> &[Self::Item];
fn get(self, idx: usize) -> Option<Self::Item> {
self.as_slice().get(idx).copied()
}
fn len(self) -> usize {
self.as_slice().len()
}
fn is_empty(self) -> bool {
self.len() == 0
}
fn contains(self, t: &Self::Item) -> bool
where
Self::Item: PartialEq,
{
self.as_slice().contains(t)
}
fn to_vec(self) -> Vec<Self::Item> {
self.as_slice().to_vec()
}
fn last(self) -> Option<Self::Item> {
self.as_slice().last().copied()
}
fn split_last(&self) -> Option<(&Self::Item, &[Self::Item])> {
self.as_slice().split_last()
}
}
impl<'a, T: Copy> SliceLike for &'a [T] {
type Item = T;
type IntoIter = std::iter::Copied<std::slice::Iter<'a, T>>;
fn iter(self) -> Self::IntoIter {
self.iter().copied()
}
fn as_slice(&self) -> &[Self::Item] {
*self
}
}
impl<'a, T: Copy, const N: usize> SliceLike for &'a [T; N] {
type Item = T;
type IntoIter = std::iter::Copied<std::slice::Iter<'a, T>>;
fn iter(self) -> Self::IntoIter {
self.into_iter().copied()
}
fn as_slice(&self) -> &[Self::Item] {
*self
}
}
impl<'a, S: SliceLike> SliceLike for &'a S {
type Item = S::Item;
type IntoIter = S::IntoIter;
fn iter(self) -> Self::IntoIter {
(*self).iter()
}
fn as_slice(&self) -> &[Self::Item] {
(*self).as_slice()
}
}

View file

@ -34,16 +34,11 @@ pub trait Interner:
type LocalDefId: Copy + Debug + Hash + Eq + Into<Self::DefId> + TypeFoldable<Self>; type LocalDefId: Copy + Debug + Hash + Eq + Into<Self::DefId> + TypeFoldable<Self>;
type GenericArgs: GenericArgs<Self>; type GenericArgs: GenericArgs<Self>;
type GenericArgsSlice: Copy + Debug + Hash + Eq + Deref<Target = [Self::GenericArg]>; type GenericArgsSlice: Copy + Debug + Hash + Eq + SliceLike<Item = Self::GenericArg>;
type GenericArg: GenericArg<Self>; type GenericArg: GenericArg<Self>;
type Term: Term<Self>; type Term: Term<Self>;
type BoundVarKinds: Copy type BoundVarKinds: Copy + Debug + Hash + Eq + SliceLike<Item = Self::BoundVarKind> + Default;
+ Debug
+ Hash
+ Eq
+ Deref<Target: Deref<Target = [Self::BoundVarKind]>>
+ Default;
type BoundVarKind: Copy + Debug + Hash + Eq; type BoundVarKind: Copy + Debug + Hash + Eq;
type PredefinedOpaques: Copy type PredefinedOpaques: Copy
@ -63,7 +58,7 @@ pub trait Interner:
+ Default + Default
+ Eq + Eq
+ TypeVisitable<Self> + TypeVisitable<Self>
+ Deref<Target: Deref<Target = [Self::LocalDefId]>>; + SliceLike<Item = Self::LocalDefId>;
type CanonicalGoalEvaluationStepRef: Copy type CanonicalGoalEvaluationStepRef: Copy
+ Debug + Debug
+ Hash + Hash
@ -74,8 +69,7 @@ pub trait Interner:
+ Debug + Debug
+ Hash + Hash
+ Eq + Eq
+ IntoIterator<Item = ty::CanonicalVarInfo<Self>> + SliceLike<Item = ty::CanonicalVarInfo<Self>>
+ Deref<Target: Deref<Target = [ty::CanonicalVarInfo<Self>]>>
+ Default; + Default;
fn mk_canonical_var_infos(self, infos: &[ty::CanonicalVarInfo<Self>]) -> Self::CanonicalVars; fn mk_canonical_var_infos(self, infos: &[ty::CanonicalVarInfo<Self>]) -> Self::CanonicalVars;
@ -96,7 +90,7 @@ pub trait Interner:
// Kinds of tys // Kinds of tys
type Ty: Ty<Self>; type Ty: Ty<Self>;
type Tys: Tys<Self>; type Tys: Tys<Self>;
type FnInputTys: Copy + Debug + Hash + Eq + Deref<Target = [Self::Ty]> + TypeVisitable<Self>; type FnInputTys: Copy + Debug + Hash + Eq + SliceLike<Item = Self::Ty> + TypeVisitable<Self>;
type ParamTy: Copy + Debug + Hash + Eq + ParamLike; type ParamTy: Copy + Debug + Hash + Eq + ParamLike;
type BoundTy: Copy + Debug + Hash + Eq + BoundVarLike<Self>; type BoundTy: Copy + Debug + Hash + Eq + BoundVarLike<Self>;
type PlaceholderTy: PlaceholderLike; type PlaceholderTy: PlaceholderLike;
@ -138,11 +132,7 @@ pub trait Interner:
type GenericsOf: GenericsOf<Self>; type GenericsOf: GenericsOf<Self>;
fn generics_of(self, def_id: Self::DefId) -> Self::GenericsOf; fn generics_of(self, def_id: Self::DefId) -> Self::GenericsOf;
type VariancesOf: Copy type VariancesOf: Copy + Debug + SliceLike<Item = ty::Variance>;
+ Debug
+ Deref<Target = [ty::Variance]>
// FIXME: This is terrible!
+ IntoIterator<Item: Deref<Target = ty::Variance>>;
fn variances_of(self, def_id: Self::DefId) -> Self::VariancesOf; fn variances_of(self, def_id: Self::DefId) -> Self::VariancesOf;
fn type_of(self, def_id: Self::DefId) -> ty::EarlyBinder<Self, Self::Ty>; fn type_of(self, def_id: Self::DefId) -> ty::EarlyBinder<Self, Self::Ty>;
@ -169,11 +159,7 @@ pub trait Interner:
fn check_args_compatible(self, def_id: Self::DefId, args: Self::GenericArgs) -> bool; fn check_args_compatible(self, def_id: Self::DefId, args: Self::GenericArgs) -> bool;
fn check_and_mk_args( fn debug_assert_args_compatible(self, def_id: Self::DefId, args: Self::GenericArgs);
self,
def_id: Self::DefId,
args: impl IntoIterator<Item: Into<Self::GenericArg>>,
) -> Self::GenericArgs;
fn intern_canonical_goal_evaluation_step( fn intern_canonical_goal_evaluation_step(
self, self,

View file

@ -24,13 +24,13 @@ pub struct OpaqueTypeKey<I: Interner> {
impl<I: Interner> OpaqueTypeKey<I> { impl<I: Interner> OpaqueTypeKey<I> {
pub fn iter_captured_args(self, tcx: I) -> impl Iterator<Item = (usize, I::GenericArg)> { pub fn iter_captured_args(self, tcx: I) -> impl Iterator<Item = (usize, I::GenericArg)> {
let variances = tcx.variances_of(self.def_id.into()); let variances = tcx.variances_of(self.def_id.into());
std::iter::zip(self.args, variances.into_iter()).enumerate().filter_map(|(i, (arg, v))| { std::iter::zip(self.args.iter(), variances.iter()).enumerate().filter_map(
match (arg.kind(), *v) { |(i, (arg, v))| match (arg.kind(), v) {
(_, ty::Invariant) => Some((i, arg)), (_, ty::Invariant) => Some((i, arg)),
(ty::GenericArgKind::Lifetime(_), ty::Bivariant) => None, (ty::GenericArgKind::Lifetime(_), ty::Bivariant) => None,
_ => panic!("unexpected opaque type arg variance"), _ => panic!("unexpected opaque type arg variance"),
} },
}) )
} }
pub fn fold_captured_lifetime_args( pub fn fold_captured_lifetime_args(
@ -41,7 +41,7 @@ impl<I: Interner> OpaqueTypeKey<I> {
let Self { def_id, args } = self; let Self { def_id, args } = self;
let variances = tcx.variances_of(def_id.into()); let variances = tcx.variances_of(def_id.into());
let args = let args =
std::iter::zip(args, variances.into_iter()).map(|(arg, v)| match (arg.kind(), *v) { std::iter::zip(args.iter(), variances.iter()).map(|(arg, v)| match (arg.kind(), v) {
(ty::GenericArgKind::Lifetime(_), ty::Bivariant) => arg, (ty::GenericArgKind::Lifetime(_), ty::Bivariant) => arg,
(ty::GenericArgKind::Lifetime(lt), _) => f(lt).into(), (ty::GenericArgKind::Lifetime(lt), _) => f(lt).into(),
_ => arg, _ => arg,

View file

@ -64,36 +64,45 @@ pub struct TraitRef<I: Interner> {
pub def_id: I::DefId, pub def_id: I::DefId,
pub args: I::GenericArgs, pub args: I::GenericArgs,
/// This field exists to prevent the creation of `TraitRef` without /// This field exists to prevent the creation of `TraitRef` without
/// calling [`TraitRef::new`]. /// calling [`TraitRef::new_from_args`].
_use_trait_ref_new_instead: (), _use_trait_ref_new_instead: (),
} }
impl<I: Interner> TraitRef<I> { impl<I: Interner> TraitRef<I> {
pub fn new_from_args(interner: I, trait_def_id: I::DefId, args: I::GenericArgs) -> Self {
interner.debug_assert_args_compatible(trait_def_id, args);
Self { def_id: trait_def_id, args, _use_trait_ref_new_instead: () }
}
pub fn new( pub fn new(
interner: I, interner: I,
trait_def_id: I::DefId, trait_def_id: I::DefId,
args: impl IntoIterator<Item: Into<I::GenericArg>>, args: impl IntoIterator<Item: Into<I::GenericArg>>,
) -> Self { ) -> Self {
let args = interner.check_and_mk_args(trait_def_id, args); let args = interner.mk_args_from_iter(args.into_iter().map(Into::into));
Self { def_id: trait_def_id, args, _use_trait_ref_new_instead: () } Self::new_from_args(interner, trait_def_id, args)
} }
pub fn from_method(interner: I, trait_id: I::DefId, args: I::GenericArgs) -> TraitRef<I> { pub fn from_method(interner: I, trait_id: I::DefId, args: I::GenericArgs) -> TraitRef<I> {
let generics = interner.generics_of(trait_id); let generics = interner.generics_of(trait_id);
TraitRef::new(interner, trait_id, args.into_iter().take(generics.count())) TraitRef::new(interner, trait_id, args.iter().take(generics.count()))
} }
/// Returns a `TraitRef` of the form `P0: Foo<P1..Pn>` where `Pi` /// Returns a `TraitRef` of the form `P0: Foo<P1..Pn>` where `Pi`
/// are the parameters defined on trait. /// are the parameters defined on trait.
pub fn identity(interner: I, def_id: I::DefId) -> TraitRef<I> { pub fn identity(interner: I, def_id: I::DefId) -> TraitRef<I> {
TraitRef::new(interner, def_id, I::GenericArgs::identity_for_item(interner, def_id)) TraitRef::new_from_args(
interner,
def_id,
I::GenericArgs::identity_for_item(interner, def_id),
)
} }
pub fn with_self_ty(self, interner: I, self_ty: I::Ty) -> Self { pub fn with_self_ty(self, interner: I, self_ty: I::Ty) -> Self {
TraitRef::new( TraitRef::new(
interner, interner,
self.def_id, self.def_id,
[self_ty.into()].into_iter().chain(self.args.into_iter().skip(1)), [self_ty.into()].into_iter().chain(self.args.iter().skip(1)),
) )
} }
@ -274,7 +283,7 @@ impl<I: Interner> ty::Binder<I, ExistentialPredicate<I>> {
// If this is an ill-formed auto trait, then synthesize // If this is an ill-formed auto trait, then synthesize
// new error args for the missing generics. // new error args for the missing generics.
let err_args = GenericArgs::extend_with_error(tcx, did, &[self_ty.into()]); let err_args = GenericArgs::extend_with_error(tcx, did, &[self_ty.into()]);
ty::TraitRef::new(tcx, did, err_args) ty::TraitRef::new_from_args(tcx, did, err_args)
}; };
self.rebind(trait_ref).upcast(tcx) self.rebind(trait_ref).upcast(tcx)
} }
@ -311,7 +320,7 @@ impl<I: Interner> ExistentialTraitRef<I> {
ExistentialTraitRef { ExistentialTraitRef {
def_id: trait_ref.def_id, def_id: trait_ref.def_id,
args: interner.mk_args(&trait_ref.args[1..]), args: interner.mk_args(&trait_ref.args.as_slice()[1..]),
} }
} }
@ -323,11 +332,7 @@ impl<I: Interner> ExistentialTraitRef<I> {
// otherwise the escaping vars would be captured by the binder // otherwise the escaping vars would be captured by the binder
// debug_assert!(!self_ty.has_escaping_bound_vars()); // debug_assert!(!self_ty.has_escaping_bound_vars());
TraitRef::new( TraitRef::new(interner, self.def_id, [self_ty.into()].into_iter().chain(self.args.iter()))
interner,
self.def_id,
[self_ty.into()].into_iter().chain(self.args.into_iter()),
)
} }
} }
@ -370,7 +375,7 @@ impl<I: Interner> ExistentialProjection<I> {
pub fn trait_ref(&self, interner: I) -> ExistentialTraitRef<I> { pub fn trait_ref(&self, interner: I) -> ExistentialTraitRef<I> {
let def_id = interner.parent(self.def_id); let def_id = interner.parent(self.def_id);
let args_count = interner.generics_of(def_id).count() - 1; let args_count = interner.generics_of(def_id).count() - 1;
let args = interner.mk_args(&self.args[..args_count]); let args = interner.mk_args(&self.args.as_slice()[..args_count]);
ExistentialTraitRef { def_id, args } ExistentialTraitRef { def_id, args }
} }
@ -382,7 +387,7 @@ impl<I: Interner> ExistentialProjection<I> {
projection_term: AliasTerm::new( projection_term: AliasTerm::new(
interner, interner,
self.def_id, self.def_id,
[self_ty.into()].into_iter().chain(self.args), [self_ty.into()].iter().chain(self.args.iter()),
), ),
term: self.term, term: self.term,
} }
@ -394,7 +399,7 @@ impl<I: Interner> ExistentialProjection<I> {
Self { Self {
def_id: projection_predicate.projection_term.def_id, def_id: projection_predicate.projection_term.def_id,
args: interner.mk_args(&projection_predicate.projection_term.args[1..]), args: interner.mk_args(&projection_predicate.projection_term.args.as_slice()[1..]),
term: projection_predicate.term, term: projection_predicate.term,
} }
} }
@ -485,19 +490,24 @@ pub struct AliasTerm<I: Interner> {
/// aka. `interner.parent(def_id)`. /// aka. `interner.parent(def_id)`.
pub def_id: I::DefId, pub def_id: I::DefId,
/// This field exists to prevent the creation of `AliasTerm` without using [`AliasTerm::new`]. /// This field exists to prevent the creation of `AliasTerm` without using [`AliasTerm::new_from_args`].
#[derivative(Debug = "ignore")] #[derivative(Debug = "ignore")]
_use_alias_term_new_instead: (), _use_alias_term_new_instead: (),
} }
impl<I: Interner> AliasTerm<I> { impl<I: Interner> AliasTerm<I> {
pub fn new_from_args(interner: I, def_id: I::DefId, args: I::GenericArgs) -> AliasTerm<I> {
interner.debug_assert_args_compatible(def_id, args);
AliasTerm { def_id, args, _use_alias_term_new_instead: () }
}
pub fn new( pub fn new(
interner: I, interner: I,
def_id: I::DefId, def_id: I::DefId,
args: impl IntoIterator<Item: Into<I::GenericArg>>, args: impl IntoIterator<Item: Into<I::GenericArg>>,
) -> AliasTerm<I> { ) -> AliasTerm<I> {
let args = interner.check_and_mk_args(def_id, args); let args = interner.mk_args_from_iter(args.into_iter().map(Into::into));
AliasTerm { def_id, args, _use_alias_term_new_instead: () } Self::new_from_args(interner, def_id, args)
} }
pub fn expect_ty(self, interner: I) -> ty::AliasTy<I> { pub fn expect_ty(self, interner: I) -> ty::AliasTy<I> {
@ -564,7 +574,7 @@ impl<I: Interner> AliasTerm<I> {
AliasTerm::new( AliasTerm::new(
interner, interner,
self.def_id, self.def_id,
[self_ty.into()].into_iter().chain(self.args.into_iter().skip(1)), [self_ty.into()].into_iter().chain(self.args.iter().skip(1)),
) )
} }

View file

@ -127,7 +127,6 @@ impl std::fmt::Display for AliasRelationDirection {
} }
} }
// FIXME: Convert to DebugWithInfcx impl
impl<I: Interner> fmt::Debug for ClauseKind<I> { impl<I: Interner> fmt::Debug for ClauseKind<I> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self { match self {
@ -144,7 +143,6 @@ impl<I: Interner> fmt::Debug for ClauseKind<I> {
} }
} }
// FIXME: Convert to DebugWithInfcx impl
impl<I: Interner> fmt::Debug for PredicateKind<I> { impl<I: Interner> fmt::Debug for PredicateKind<I> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self { match self {

View file

@ -82,7 +82,7 @@ pub trait TypeRelation<I: Interner>: Sized {
let tcx = self.tcx(); let tcx = self.tcx();
let opt_variances = tcx.variances_of(item_def_id); let opt_variances = tcx.variances_of(item_def_id);
relate_args_with_variances(self, item_def_id, &opt_variances, a_arg, b_arg, true) relate_args_with_variances(self, item_def_id, opt_variances, a_arg, b_arg, true)
} }
/// Switch variance for the purpose of relating `a` and `b`. /// Switch variance for the purpose of relating `a` and `b`.
@ -128,7 +128,7 @@ pub fn relate_args_invariantly<I: Interner, R: TypeRelation<I>>(
a_arg: I::GenericArgs, a_arg: I::GenericArgs,
b_arg: I::GenericArgs, b_arg: I::GenericArgs,
) -> RelateResult<I, I::GenericArgs> { ) -> RelateResult<I, I::GenericArgs> {
relation.tcx().mk_args_from_iter(iter::zip(a_arg, b_arg).map(|(a, b)| { relation.tcx().mk_args_from_iter(iter::zip(a_arg.iter(), b_arg.iter()).map(|(a, b)| {
relation.relate_with_variance(ty::Invariant, VarianceDiagInfo::default(), a, b) relation.relate_with_variance(ty::Invariant, VarianceDiagInfo::default(), a, b)
})) }))
} }
@ -136,7 +136,7 @@ pub fn relate_args_invariantly<I: Interner, R: TypeRelation<I>>(
pub fn relate_args_with_variances<I: Interner, R: TypeRelation<I>>( pub fn relate_args_with_variances<I: Interner, R: TypeRelation<I>>(
relation: &mut R, relation: &mut R,
ty_def_id: I::DefId, ty_def_id: I::DefId,
variances: &[ty::Variance], variances: I::VariancesOf,
a_arg: I::GenericArgs, a_arg: I::GenericArgs,
b_arg: I::GenericArgs, b_arg: I::GenericArgs,
fetch_ty_for_diag: bool, fetch_ty_for_diag: bool,
@ -144,11 +144,11 @@ pub fn relate_args_with_variances<I: Interner, R: TypeRelation<I>>(
let tcx = relation.tcx(); let tcx = relation.tcx();
let mut cached_ty = None; let mut cached_ty = None;
let params = iter::zip(a_arg, b_arg).enumerate().map(|(i, (a, b))| { let params = iter::zip(a_arg.iter(), b_arg.iter()).enumerate().map(|(i, (a, b))| {
let variance = variances[i]; let variance = variances.get(i).unwrap();
let variance_info = if variance == ty::Invariant && fetch_ty_for_diag { let variance_info = if variance == ty::Invariant && fetch_ty_for_diag {
let ty = let ty =
*cached_ty.get_or_insert_with(|| tcx.type_of(ty_def_id).instantiate(tcx, &a_arg)); *cached_ty.get_or_insert_with(|| tcx.type_of(ty_def_id).instantiate(tcx, a_arg));
VarianceDiagInfo::Invariant { ty, param_index: i.try_into().unwrap() } VarianceDiagInfo::Invariant { ty, param_index: i.try_into().unwrap() }
} else { } else {
VarianceDiagInfo::default() VarianceDiagInfo::default()
@ -185,7 +185,7 @@ impl<I: Interner> Relate<I> for ty::FnSig<I> {
} }
let inputs_and_output = iter::zip(a_inputs.iter(), b_inputs.iter()) let inputs_and_output = iter::zip(a_inputs.iter(), b_inputs.iter())
.map(|(&a, &b)| ((a, b), false)) .map(|(a, b)| ((a, b), false))
.chain(iter::once(((a.output(), b.output()), true))) .chain(iter::once(((a.output(), b.output()), true)))
.map(|((a, b), is_output)| { .map(|((a, b), is_output)| {
if is_output { if is_output {
@ -249,7 +249,7 @@ impl<I: Interner> Relate<I> for ty::AliasTy<I> {
ty::Opaque => relate_args_with_variances( ty::Opaque => relate_args_with_variances(
relation, relation,
a.def_id, a.def_id,
&relation.tcx().variances_of(a.def_id), relation.tcx().variances_of(a.def_id),
a.args, a.args,
b.args, b.args,
false, // do not fetch `type_of(a_def_id)`, as it will cause a cycle false, // do not fetch `type_of(a_def_id)`, as it will cause a cycle
@ -258,7 +258,7 @@ impl<I: Interner> Relate<I> for ty::AliasTy<I> {
relate_args_invariantly(relation, a.args, b.args)? relate_args_invariantly(relation, a.args, b.args)?
} }
}; };
Ok(ty::AliasTy::new(relation.tcx(), a.def_id, args)) Ok(ty::AliasTy::new_from_args(relation.tcx(), a.def_id, args))
} }
} }
} }
@ -280,7 +280,7 @@ impl<I: Interner> Relate<I> for ty::AliasTerm<I> {
ty::AliasTermKind::OpaqueTy => relate_args_with_variances( ty::AliasTermKind::OpaqueTy => relate_args_with_variances(
relation, relation,
a.def_id, a.def_id,
&relation.tcx().variances_of(a.def_id), relation.tcx().variances_of(a.def_id),
a.args, a.args,
b.args, b.args,
false, // do not fetch `type_of(a_def_id)`, as it will cause a cycle false, // do not fetch `type_of(a_def_id)`, as it will cause a cycle
@ -293,7 +293,7 @@ impl<I: Interner> Relate<I> for ty::AliasTerm<I> {
relate_args_invariantly(relation, a.args, b.args)? relate_args_invariantly(relation, a.args, b.args)?
} }
}; };
Ok(ty::AliasTerm::new(relation.tcx(), a.def_id, args)) Ok(ty::AliasTerm::new_from_args(relation.tcx(), a.def_id, args))
} }
} }
} }
@ -343,7 +343,7 @@ impl<I: Interner> Relate<I> for ty::TraitRef<I> {
})) }))
} else { } else {
let args = relate_args_invariantly(relation, a.args, b.args)?; let args = relate_args_invariantly(relation, a.args, b.args)?;
Ok(ty::TraitRef::new(relation.tcx(), a.def_id, args)) Ok(ty::TraitRef::new_from_args(relation.tcx(), a.def_id, args))
} }
} }
} }
@ -525,7 +525,7 @@ pub fn structurally_relate_tys<I: Interner, R: TypeRelation<I>>(
if as_.len() == bs.len() { if as_.len() == bs.len() {
Ok(Ty::new_tup_from_iter( Ok(Ty::new_tup_from_iter(
tcx, tcx,
iter::zip(as_, bs).map(|(a, b)| relation.relate(a, b)), iter::zip(as_.iter(), bs.iter()).map(|(a, b)| relation.relate(a, b)),
)?) )?)
} else if !(as_.is_empty() || bs.is_empty()) { } else if !(as_.is_empty() || bs.is_empty()) {
Err(TypeError::TupleSize(ExpectedFound::new(true, as_.len(), bs.len()))) Err(TypeError::TupleSize(ExpectedFound::new(true, as_.len(), bs.len())))
@ -607,8 +607,8 @@ pub fn structurally_relate_consts<I: Interner, R: TypeRelation<I>>(
// be stabilized. // be stabilized.
(ty::ConstKind::Unevaluated(au), ty::ConstKind::Unevaluated(bu)) if au.def == bu.def => { (ty::ConstKind::Unevaluated(au), ty::ConstKind::Unevaluated(bu)) if au.def == bu.def => {
if cfg!(debug_assertions) { if cfg!(debug_assertions) {
let a_ty = tcx.type_of(au.def).instantiate(tcx, &au.args); let a_ty = tcx.type_of(au.def).instantiate(tcx, au.args);
let b_ty = tcx.type_of(bu.def).instantiate(tcx, &bu.args); let b_ty = tcx.type_of(bu.def).instantiate(tcx, bu.args);
assert_eq!(a_ty, b_ty); assert_eq!(a_ty, b_ty);
} }

View file

@ -352,7 +352,7 @@ impl<I: Interner> fmt::Debug for TyKind<I> {
Float(float) => write!(f, "{float:?}"), Float(float) => write!(f, "{float:?}"),
Adt(d, s) => { Adt(d, s) => {
write!(f, "{d:?}")?; write!(f, "{d:?}")?;
let mut s = s.into_iter(); let mut s = s.iter();
let first = s.next(); let first = s.next();
match first { match first {
Some(first) => write!(f, "<{:?}", first)?, Some(first) => write!(f, "<{:?}", first)?,
@ -388,7 +388,7 @@ impl<I: Interner> fmt::Debug for TyKind<I> {
Tuple(t) => { Tuple(t) => {
write!(f, "(")?; write!(f, "(")?;
let mut count = 0; let mut count = 0;
for ty in *t { for ty in t.iter() {
if count > 0 { if count > 0 {
write!(f, ", ")?; write!(f, ", ")?;
} }
@ -452,19 +452,24 @@ pub struct AliasTy<I: Interner> {
/// aka. `interner.parent(def_id)`. /// aka. `interner.parent(def_id)`.
pub def_id: I::DefId, pub def_id: I::DefId,
/// This field exists to prevent the creation of `AliasTy` without using [`AliasTy::new`]. /// This field exists to prevent the creation of `AliasTy` without using [`AliasTy::new_from_args`].
#[derivative(Debug = "ignore")] #[derivative(Debug = "ignore")]
pub(crate) _use_alias_ty_new_instead: (), pub(crate) _use_alias_ty_new_instead: (),
} }
impl<I: Interner> AliasTy<I> { impl<I: Interner> AliasTy<I> {
pub fn new_from_args(interner: I, def_id: I::DefId, args: I::GenericArgs) -> AliasTy<I> {
interner.debug_assert_args_compatible(def_id, args);
AliasTy { def_id, args, _use_alias_ty_new_instead: () }
}
pub fn new( pub fn new(
interner: I, interner: I,
def_id: I::DefId, def_id: I::DefId,
args: impl IntoIterator<Item: Into<I::GenericArg>>, args: impl IntoIterator<Item: Into<I::GenericArg>>,
) -> AliasTy<I> { ) -> AliasTy<I> {
let args = interner.check_and_mk_args(def_id, args); let args = interner.mk_args_from_iter(args.into_iter().map(Into::into));
AliasTy { def_id, args, _use_alias_ty_new_instead: () } Self::new_from_args(interner, def_id, args)
} }
pub fn kind(self, interner: I) -> AliasTyKind { pub fn kind(self, interner: I) -> AliasTyKind {
@ -491,7 +496,7 @@ impl<I: Interner> AliasTy<I> {
AliasTy::new( AliasTy::new(
interner, interner,
self.def_id, self.def_id,
[self_ty.into()].into_iter().chain(self.args.into_iter().skip(1)), [self_ty.into()].into_iter().chain(self.args.iter().skip(1)),
) )
} }
@ -539,7 +544,7 @@ impl<I: Interner> AliasTy<I> {
interner: I, interner: I,
) -> I::GenericArgs { ) -> I::GenericArgs {
debug_assert_eq!(self.kind(interner), AliasTyKind::Inherent); debug_assert_eq!(self.kind(interner), AliasTyKind::Inherent);
interner.mk_args_from_iter(impl_args.into_iter().chain(self.args.into_iter().skip(1))) interner.mk_args_from_iter(impl_args.iter().chain(self.args.iter().skip(1)))
} }
} }
@ -1000,7 +1005,7 @@ impl<I: Interner> ty::Binder<I, FnSig<I>> {
#[inline] #[inline]
#[track_caller] #[track_caller]
pub fn input(self, index: usize) -> ty::Binder<I, I::Ty> { pub fn input(self, index: usize) -> ty::Binder<I, I::Ty> {
self.map_bound(|fn_sig| fn_sig.inputs()[index]) self.map_bound(|fn_sig| fn_sig.inputs().get(index).unwrap())
} }
pub fn inputs_and_output(self) -> ty::Binder<I, I::Tys> { pub fn inputs_and_output(self) -> ty::Binder<I, I::Tys> {

View file

@ -138,7 +138,7 @@ impl<I: Interner> ClosureArgs<I> {
/// for the closure parent, alongside additional closure-specific components. /// for the closure parent, alongside additional closure-specific components.
pub fn new(tcx: I, parts: ClosureArgsParts<I>) -> ClosureArgs<I> { pub fn new(tcx: I, parts: ClosureArgsParts<I>) -> ClosureArgs<I> {
ClosureArgs { ClosureArgs {
args: tcx.mk_args_from_iter(parts.parent_args.iter().copied().chain([ args: tcx.mk_args_from_iter(parts.parent_args.iter().chain([
parts.closure_kind_ty.into(), parts.closure_kind_ty.into(),
parts.closure_sig_as_fn_ptr_ty.into(), parts.closure_sig_as_fn_ptr_ty.into(),
parts.tupled_upvars_ty.into(), parts.tupled_upvars_ty.into(),
@ -260,7 +260,7 @@ pub struct CoroutineClosureArgsParts<I: Interner> {
impl<I: Interner> CoroutineClosureArgs<I> { impl<I: Interner> CoroutineClosureArgs<I> {
pub fn new(tcx: I, parts: CoroutineClosureArgsParts<I>) -> CoroutineClosureArgs<I> { pub fn new(tcx: I, parts: CoroutineClosureArgsParts<I>) -> CoroutineClosureArgs<I> {
CoroutineClosureArgs { CoroutineClosureArgs {
args: tcx.mk_args_from_iter(parts.parent_args.iter().copied().chain([ args: tcx.mk_args_from_iter(parts.parent_args.iter().chain([
parts.closure_kind_ty.into(), parts.closure_kind_ty.into(),
parts.signature_parts_ty.into(), parts.signature_parts_ty.into(),
parts.tupled_upvars_ty.into(), parts.tupled_upvars_ty.into(),
@ -309,10 +309,10 @@ impl<I: Interner> CoroutineClosureArgs<I> {
let interior = self.coroutine_witness_ty(); let interior = self.coroutine_witness_ty();
let ty::FnPtr(sig) = self.signature_parts_ty().kind() else { panic!() }; let ty::FnPtr(sig) = self.signature_parts_ty().kind() else { panic!() };
sig.map_bound(|sig| { sig.map_bound(|sig| {
let [resume_ty, tupled_inputs_ty] = *sig.inputs() else { let [resume_ty, tupled_inputs_ty] = *sig.inputs().as_slice() else {
panic!(); panic!();
}; };
let [yield_ty, return_ty] = **sig.output().tuple_fields() else { panic!() }; let [yield_ty, return_ty] = *sig.output().tuple_fields().as_slice() else { panic!() };
CoroutineClosureSignature { CoroutineClosureSignature {
interior, interior,
tupled_inputs_ty, tupled_inputs_ty,
@ -496,16 +496,16 @@ impl<I: Interner> CoroutineClosureSignature<I> {
tcx, tcx,
tupled_inputs_ty tupled_inputs_ty
.tuple_fields() .tuple_fields()
.into_iter() .iter()
.chain(coroutine_captures_by_ref_ty.tuple_fields()), .chain(coroutine_captures_by_ref_ty.tuple_fields().iter()),
) )
} }
ty::ClosureKind::FnOnce => Ty::new_tup_from_iter( ty::ClosureKind::FnOnce => Ty::new_tup_from_iter(
tcx, tcx,
tupled_inputs_ty tupled_inputs_ty
.tuple_fields() .tuple_fields()
.into_iter() .iter()
.chain(closure_tupled_upvars_ty.tuple_fields()), .chain(closure_tupled_upvars_ty.tuple_fields().iter()),
), ),
} }
} }
@ -617,7 +617,7 @@ impl<I: Interner> CoroutineArgs<I> {
/// for the coroutine parent, alongside additional coroutine-specific components. /// for the coroutine parent, alongside additional coroutine-specific components.
pub fn new(tcx: I, parts: CoroutineArgsParts<I>) -> CoroutineArgs<I> { pub fn new(tcx: I, parts: CoroutineArgsParts<I>) -> CoroutineArgs<I> {
CoroutineArgs { CoroutineArgs {
args: tcx.mk_args_from_iter(parts.parent_args.iter().copied().chain([ args: tcx.mk_args_from_iter(parts.parent_args.iter().chain([
parts.kind_ty.into(), parts.kind_ty.into(),
parts.resume_ty.into(), parts.resume_ty.into(),
parts.yield_ty.into(), parts.yield_ty.into(),

View file

@ -61,7 +61,7 @@ fn is_impl_not_trait_with_bool_out<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -
) )
}) })
.map_or(false, |assoc_item| { .map_or(false, |assoc_item| {
let proj = Ty::new_projection(cx.tcx, assoc_item.def_id, cx.tcx.mk_args_trait(ty, [])); let proj = Ty::new_projection_from_args(cx.tcx, assoc_item.def_id, cx.tcx.mk_args_trait(ty, []));
let nty = cx.tcx.normalize_erasing_regions(cx.param_env, proj); let nty = cx.tcx.normalize_erasing_regions(cx.param_env, proj);
nty.is_bool() nty.is_bool()

View file

@ -206,7 +206,7 @@ fn iterates_same_ty<'tcx>(cx: &LateContext<'tcx>, iter_ty: Ty<'tcx>, collect_ty:
&& let Some(into_iter_item_proj) = make_projection(cx.tcx, into_iter_trait, sym::Item, [collect_ty]) && let Some(into_iter_item_proj) = make_projection(cx.tcx, into_iter_trait, sym::Item, [collect_ty])
&& let Ok(into_iter_item_ty) = cx.tcx.try_normalize_erasing_regions( && let Ok(into_iter_item_ty) = cx.tcx.try_normalize_erasing_regions(
cx.param_env, cx.param_env,
Ty::new_projection(cx.tcx, into_iter_item_proj.def_id, into_iter_item_proj.args), Ty::new_projection_from_args(cx.tcx, into_iter_item_proj.def_id, into_iter_item_proj.args),
) )
{ {
iter_item_ty == into_iter_item_ty iter_item_ty == into_iter_item_ty
@ -235,7 +235,7 @@ fn is_contains_sig(cx: &LateContext<'_>, call_id: HirId, iter_expr: &Expr<'_>) -
iter_trait, iter_trait,
) )
&& let args = cx.tcx.mk_args(&[GenericArg::from(typeck.expr_ty_adjusted(iter_expr))]) && let args = cx.tcx.mk_args(&[GenericArg::from(typeck.expr_ty_adjusted(iter_expr))])
&& let proj_ty = Ty::new_projection(cx.tcx, iter_item.def_id, args) && let proj_ty = Ty::new_projection_from_args(cx.tcx, iter_item.def_id, args)
&& let Ok(item_ty) = cx.tcx.try_normalize_erasing_regions(cx.param_env, proj_ty) && let Ok(item_ty) = cx.tcx.try_normalize_erasing_regions(cx.param_env, proj_ty)
{ {
item_ty == EarlyBinder::bind(search_ty).instantiate(cx.tcx, cx.typeck_results().node_args(call_id)) item_ty == EarlyBinder::bind(search_ty).instantiate(cx.tcx, cx.typeck_results().node_args(call_id))

View file

@ -267,7 +267,7 @@ fn needless_borrow_count<'tcx>(
return false; return false;
} }
let predicate = EarlyBinder::bind(predicate).instantiate(cx.tcx, &args_with_referent_ty); let predicate = EarlyBinder::bind(predicate).instantiate(cx.tcx, &args_with_referent_ty[..]);
let obligation = Obligation::new(cx.tcx, ObligationCause::dummy(), cx.param_env, predicate); let obligation = Obligation::new(cx.tcx, ObligationCause::dummy(), cx.param_env, predicate);
let infcx = cx.tcx.infer_ctxt().build(); let infcx = cx.tcx.infer_ctxt().build();
infcx.predicate_must_hold_modulo_regions(&obligation) infcx.predicate_must_hold_modulo_regions(&obligation)

View file

@ -133,7 +133,7 @@ impl<'tcx> LateLintPass<'tcx> for RedundantSlicing {
} else if let Some(target_id) = cx.tcx.lang_items().deref_target() { } else if let Some(target_id) = cx.tcx.lang_items().deref_target() {
if let Ok(deref_ty) = cx.tcx.try_normalize_erasing_regions( if let Ok(deref_ty) = cx.tcx.try_normalize_erasing_regions(
cx.param_env, cx.param_env,
Ty::new_projection(cx.tcx, target_id, cx.tcx.mk_args(&[GenericArg::from(indexed_ty)])), Ty::new_projection_from_args(cx.tcx, target_id, cx.tcx.mk_args(&[GenericArg::from(indexed_ty)])),
) { ) {
if deref_ty == expr_ty { if deref_ty == expr_ty {
let snip = snippet_with_context(cx, indexed.span, ctxt, "..", &mut app).0; let snip = snippet_with_context(cx, indexed.span, ctxt, "..", &mut app).0;

View file

@ -292,7 +292,7 @@ pub fn implements_trait_with_env_from_iter<'tcx>(
let trait_ref = TraitRef::new( let trait_ref = TraitRef::new(
tcx, tcx,
trait_id, trait_id,
Some(GenericArg::from(ty)).into_iter().chain(args).chain(effect_arg), [GenericArg::from(ty)].into_iter().chain(args).chain(effect_arg),
); );
debug_assert_matches!( debug_assert_matches!(
@ -1126,7 +1126,7 @@ pub fn make_projection<'tcx>(
#[cfg(debug_assertions)] #[cfg(debug_assertions)]
assert_generic_args_match(tcx, assoc_item.def_id, args); assert_generic_args_match(tcx, assoc_item.def_id, args);
Some(AliasTy::new(tcx, assoc_item.def_id, args)) Some(AliasTy::new_from_args(tcx, assoc_item.def_id, args))
} }
helper( helper(
tcx, tcx,
@ -1165,7 +1165,7 @@ pub fn make_normalized_projection<'tcx>(
); );
return None; return None;
} }
match tcx.try_normalize_erasing_regions(param_env, Ty::new_projection(tcx, ty.def_id, ty.args)) { match tcx.try_normalize_erasing_regions(param_env, Ty::new_projection_from_args(tcx, ty.def_id, ty.args)) {
Ok(ty) => Some(ty), Ok(ty) => Some(ty),
Err(e) => { Err(e) => {
debug_assert!(false, "failed to normalize type `{ty}`: {e:#?}"); debug_assert!(false, "failed to normalize type `{ty}`: {e:#?}");
@ -1289,7 +1289,7 @@ pub fn make_normalized_projection_with_regions<'tcx>(
.infer_ctxt() .infer_ctxt()
.build() .build()
.at(&cause, param_env) .at(&cause, param_env)
.query_normalize(Ty::new_projection(tcx, ty.def_id, ty.args)) .query_normalize(Ty::new_projection_from_args(tcx, ty.def_id, ty.args))
{ {
Ok(ty) => Some(ty.value), Ok(ty) => Some(ty.value),
Err(e) => { Err(e) => {