mirror of
https://github.com/rust-lang/rust.git
synced 2026-04-27 18:57:42 +03:00
add AliasTermTy::with_args to simplify a common-ish pattern
This commit is contained in:
@@ -965,7 +965,7 @@ pub(super) fn relate_rigid_alias_non_alias(
|
||||
// Alternatively we could modify `Equate` for this case by adding another
|
||||
// variant to `StructurallyRelateAliases`.
|
||||
let identity_args = self.fresh_args_for_item(alias.def_id());
|
||||
let rigid_ctor = ty::AliasTerm::new_from_args(cx, alias.kind, identity_args);
|
||||
let rigid_ctor = alias.with_args(cx, identity_args);
|
||||
let ctor_term = rigid_ctor.to_term(cx);
|
||||
let obligations = self.delegate.eq_structurally_relating_aliases(
|
||||
param_env,
|
||||
|
||||
@@ -1340,11 +1340,7 @@ fn confirm_coroutine_candidate<'cx, 'tcx>(
|
||||
};
|
||||
|
||||
let predicate = ty::ProjectionPredicate {
|
||||
projection_term: ty::AliasTerm::new_from_args(
|
||||
tcx,
|
||||
obligation.predicate.kind,
|
||||
trait_ref.args,
|
||||
),
|
||||
projection_term: obligation.predicate.with_args(tcx, trait_ref.args),
|
||||
term: ty.into(),
|
||||
};
|
||||
|
||||
@@ -1388,11 +1384,7 @@ fn confirm_future_candidate<'cx, 'tcx>(
|
||||
debug_assert_eq!(tcx.associated_item(obligation.predicate.def_id()).name(), sym::Output);
|
||||
|
||||
let predicate = ty::ProjectionPredicate {
|
||||
projection_term: ty::AliasTerm::new_from_args(
|
||||
tcx,
|
||||
obligation.predicate.kind,
|
||||
trait_ref.args,
|
||||
),
|
||||
projection_term: obligation.predicate.with_args(tcx, trait_ref.args),
|
||||
term: return_ty.into(),
|
||||
};
|
||||
|
||||
@@ -1434,11 +1426,7 @@ fn confirm_iterator_candidate<'cx, 'tcx>(
|
||||
debug_assert_eq!(tcx.associated_item(obligation.predicate.def_id()).name(), sym::Item);
|
||||
|
||||
let predicate = ty::ProjectionPredicate {
|
||||
projection_term: ty::AliasTerm::new_from_args(
|
||||
tcx,
|
||||
obligation.predicate.kind,
|
||||
trait_ref.args,
|
||||
),
|
||||
projection_term: obligation.predicate.with_args(tcx, trait_ref.args),
|
||||
term: yield_ty.into(),
|
||||
};
|
||||
|
||||
@@ -1488,11 +1476,7 @@ fn confirm_async_iterator_candidate<'cx, 'tcx>(
|
||||
let item_ty = args.type_at(0);
|
||||
|
||||
let predicate = ty::ProjectionPredicate {
|
||||
projection_term: ty::AliasTerm::new_from_args(
|
||||
tcx,
|
||||
obligation.predicate.kind,
|
||||
trait_ref.args,
|
||||
),
|
||||
projection_term: obligation.predicate.with_args(tcx, trait_ref.args),
|
||||
term: item_ty.into(),
|
||||
};
|
||||
|
||||
@@ -1898,11 +1882,7 @@ fn confirm_async_fn_kind_helper_candidate<'cx, 'tcx>(
|
||||
};
|
||||
|
||||
let predicate = ty::ProjectionPredicate {
|
||||
projection_term: ty::AliasTerm::new_from_args(
|
||||
selcx.tcx(),
|
||||
obligation.predicate.kind,
|
||||
obligation.predicate.args,
|
||||
),
|
||||
projection_term: obligation.predicate.with_args(selcx.tcx(), obligation.predicate.args),
|
||||
term: ty::CoroutineClosureSignature::tupled_upvars_by_closure_kind(
|
||||
selcx.tcx(),
|
||||
goal_kind_ty.expect_ty().to_opt_closure_kind().unwrap(),
|
||||
|
||||
@@ -769,6 +769,10 @@ pub fn to_term(self, interner: I) -> I::Term {
|
||||
Ty::new_alias(interner, ty::AliasTy::new_from_args(interner, alias_ty_kind, self.args))
|
||||
.into()
|
||||
}
|
||||
|
||||
pub fn with_args(self, interner: I, args: I::GenericArgs) -> Self {
|
||||
Self::new_from_args(interner, self.kind, args)
|
||||
}
|
||||
}
|
||||
|
||||
/// The following methods work only with (trait) associated term projections.
|
||||
|
||||
@@ -256,7 +256,7 @@ fn relate<R: TypeRelation<I>>(
|
||||
relate_args_invariantly(relation, a.args, b.args)?
|
||||
}
|
||||
};
|
||||
Ok(ty::AliasTerm::new_from_args(relation.cx(), a.kind, args))
|
||||
Ok(a.with_args(relation.cx(), args))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user