Auto merge of #110806 - WaffleLapkin:unmkI, r=lcnr
Replace `tcx.mk_trait_ref` with `TraitRef::new` First step in implementing https://github.com/rust-lang/compiler-team/issues/616 r? `@lcnr`
This commit is contained in:
commit
6f8c0557e0
@ -1120,7 +1120,7 @@ fn explain_captures(
|
||||
});
|
||||
}
|
||||
if let Some(clone_trait) = tcx.lang_items().clone_trait()
|
||||
&& let trait_ref = tcx.mk_trait_ref(clone_trait, [ty])
|
||||
&& let trait_ref = ty::TraitRef::new(tcx, clone_trait, [ty])
|
||||
&& let o = Obligation::new(
|
||||
tcx,
|
||||
ObligationCause::dummy(),
|
||||
|
@ -538,7 +538,8 @@ fn sanitize_place(
|
||||
|
||||
if let PlaceContext::NonMutatingUse(NonMutatingUseContext::Copy) = context {
|
||||
let tcx = self.tcx();
|
||||
let trait_ref = tcx.at(self.last_span).mk_trait_ref(LangItem::Copy, [place_ty.ty]);
|
||||
let trait_ref =
|
||||
ty::TraitRef::from_lang_item(tcx, LangItem::Copy, self.last_span, [place_ty.ty]);
|
||||
|
||||
// To have a `Copy` operand, the type `T` of the
|
||||
// value must be `Copy`. Note that we prove that `T: Copy`,
|
||||
@ -1237,8 +1238,12 @@ fn check_stmt(&mut self, body: &Body<'tcx>, stmt: &Statement<'tcx>, location: Lo
|
||||
|
||||
self.check_rvalue(body, rv, location);
|
||||
if !self.unsized_feature_enabled() {
|
||||
let trait_ref =
|
||||
tcx.at(self.last_span).mk_trait_ref(LangItem::Sized, [place_ty]);
|
||||
let trait_ref = ty::TraitRef::from_lang_item(
|
||||
tcx,
|
||||
LangItem::Sized,
|
||||
self.last_span,
|
||||
[place_ty],
|
||||
);
|
||||
self.prove_trait_ref(
|
||||
trait_ref,
|
||||
location.to_locations(),
|
||||
@ -1810,7 +1815,8 @@ fn check_rvalue(&mut self, body: &Body<'tcx>, rvalue: &Rvalue<'tcx>, location: L
|
||||
Operand::Move(place) => {
|
||||
// Make sure that repeated elements implement `Copy`.
|
||||
let ty = place.ty(body, tcx).ty;
|
||||
let trait_ref = tcx.at(span).mk_trait_ref(LangItem::Copy, [ty]);
|
||||
let trait_ref =
|
||||
ty::TraitRef::from_lang_item(tcx, LangItem::Copy, span, [ty]);
|
||||
|
||||
self.prove_trait_ref(
|
||||
trait_ref,
|
||||
@ -1823,7 +1829,7 @@ fn check_rvalue(&mut self, body: &Body<'tcx>, rvalue: &Rvalue<'tcx>, location: L
|
||||
}
|
||||
|
||||
&Rvalue::NullaryOp(NullOp::SizeOf | NullOp::AlignOf, ty) => {
|
||||
let trait_ref = tcx.at(span).mk_trait_ref(LangItem::Sized, [ty]);
|
||||
let trait_ref = ty::TraitRef::from_lang_item(tcx, LangItem::Sized, span, [ty]);
|
||||
|
||||
self.prove_trait_ref(
|
||||
trait_ref,
|
||||
@ -1835,7 +1841,7 @@ fn check_rvalue(&mut self, body: &Body<'tcx>, rvalue: &Rvalue<'tcx>, location: L
|
||||
Rvalue::ShallowInitBox(operand, ty) => {
|
||||
self.check_operand(operand, location);
|
||||
|
||||
let trait_ref = tcx.at(span).mk_trait_ref(LangItem::Sized, [*ty]);
|
||||
let trait_ref = ty::TraitRef::from_lang_item(tcx, LangItem::Sized, span, [*ty]);
|
||||
|
||||
self.prove_trait_ref(
|
||||
trait_ref,
|
||||
@ -1932,9 +1938,12 @@ fn check_rvalue(&mut self, body: &Body<'tcx>, rvalue: &Rvalue<'tcx>, location: L
|
||||
|
||||
CastKind::Pointer(PointerCast::Unsize) => {
|
||||
let &ty = ty;
|
||||
let trait_ref = tcx
|
||||
.at(span)
|
||||
.mk_trait_ref(LangItem::CoerceUnsized, [op.ty(body, tcx), ty]);
|
||||
let trait_ref = ty::TraitRef::from_lang_item(
|
||||
tcx,
|
||||
LangItem::CoerceUnsized,
|
||||
span,
|
||||
[op.ty(body, tcx), ty],
|
||||
);
|
||||
|
||||
self.prove_trait_ref(
|
||||
trait_ref,
|
||||
|
@ -157,7 +157,7 @@ fn in_any_value_of_ty<'tcx>(cx: &ConstCx<'_, 'tcx>, ty: Ty<'tcx>) -> bool {
|
||||
cx.tcx,
|
||||
ObligationCause::dummy_with_span(cx.body.span),
|
||||
cx.param_env,
|
||||
ty::Binder::dummy(cx.tcx.at(cx.body.span).mk_trait_ref(LangItem::Destruct, [ty]))
|
||||
ty::TraitRef::from_lang_item(cx.tcx, LangItem::Destruct, cx.body.span, [ty])
|
||||
.with_constness(ty::BoundConstness::ConstIfConst),
|
||||
);
|
||||
|
||||
|
@ -694,7 +694,7 @@ fn instantiate_poly_trait_ref_inner(
|
||||
let assoc_bindings = self.create_assoc_bindings_for_generic_args(args);
|
||||
|
||||
let poly_trait_ref =
|
||||
ty::Binder::bind_with_vars(tcx.mk_trait_ref(trait_def_id, substs), bound_vars);
|
||||
ty::Binder::bind_with_vars(ty::TraitRef::new(tcx, trait_def_id, substs), bound_vars);
|
||||
|
||||
debug!(?poly_trait_ref, ?assoc_bindings);
|
||||
bounds.push_trait_bound(tcx, poly_trait_ref, span, constness, polarity);
|
||||
@ -846,7 +846,7 @@ fn ast_path_to_mono_trait_ref(
|
||||
if let Some(b) = trait_segment.args().bindings.first() {
|
||||
prohibit_assoc_ty_binding(self.tcx(), b.span, Some((trait_segment, span)));
|
||||
}
|
||||
self.tcx().mk_trait_ref(trait_def_id, substs)
|
||||
ty::TraitRef::new(self.tcx(), trait_def_id, substs)
|
||||
}
|
||||
|
||||
#[instrument(level = "debug", skip(self, span))]
|
||||
|
@ -123,7 +123,7 @@ fn overloaded_deref_ty(&mut self, ty: Ty<'tcx>) -> Option<Ty<'tcx>> {
|
||||
let tcx = self.infcx.tcx;
|
||||
|
||||
// <ty as Deref>
|
||||
let trait_ref = tcx.mk_trait_ref(tcx.lang_items().deref_trait()?, [ty]);
|
||||
let trait_ref = ty::TraitRef::new(tcx, tcx.lang_items().deref_trait()?, [ty]);
|
||||
|
||||
let cause = traits::ObligationCause::misc(self.span, self.body_id);
|
||||
|
||||
|
@ -63,7 +63,7 @@ pub fn push_projection_bound(
|
||||
|
||||
pub fn push_sized(&mut self, tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, span: Span) {
|
||||
let sized_def_id = tcx.require_lang_item(LangItem::Sized, Some(span));
|
||||
let trait_ref = ty::Binder::dummy(tcx.mk_trait_ref(sized_def_id, [ty]));
|
||||
let trait_ref = ty::TraitRef::new(tcx, sized_def_id, [ty]);
|
||||
// Preferable to put this obligation first, since we report better errors for sized ambiguity.
|
||||
self.predicates.insert(0, (trait_ref.without_const().to_predicate(tcx), span));
|
||||
}
|
||||
|
@ -536,7 +536,7 @@ fn check_item_type(tcx: TyCtxt<'_>, id: hir::ItemId) {
|
||||
tcx,
|
||||
assoc_item,
|
||||
assoc_item,
|
||||
tcx.mk_trait_ref(id.owner_id.to_def_id(), trait_substs),
|
||||
ty::TraitRef::new(tcx, id.owner_id.to_def_id(), trait_substs),
|
||||
);
|
||||
}
|
||||
_ => {}
|
||||
|
@ -1779,7 +1779,7 @@ fn receiver_is_implemented<'tcx>(
|
||||
receiver_ty: Ty<'tcx>,
|
||||
) -> bool {
|
||||
let tcx = wfcx.tcx();
|
||||
let trait_ref = ty::Binder::dummy(tcx.mk_trait_ref(receiver_trait_def_id, [receiver_ty]));
|
||||
let trait_ref = ty::TraitRef::new(tcx, receiver_trait_def_id, [receiver_ty]);
|
||||
|
||||
let obligation = traits::Obligation::new(tcx, cause, wfcx.param_env, trait_ref);
|
||||
|
||||
|
@ -265,10 +265,11 @@ fn visit_implementation_of_dispatch_from_dyn(tcx: TyCtxt<'_>, impl_did: LocalDef
|
||||
tcx,
|
||||
cause.clone(),
|
||||
param_env,
|
||||
ty::Binder::dummy(tcx.mk_trait_ref(
|
||||
ty::TraitRef::new(
|
||||
tcx,
|
||||
dispatch_from_dyn_trait,
|
||||
[field.ty(tcx, substs_a), field.ty(tcx, substs_b)],
|
||||
)),
|
||||
),
|
||||
));
|
||||
}
|
||||
let errors = ocx.select_all_or_error();
|
||||
@ -504,8 +505,12 @@ pub fn coerce_unsized_info<'tcx>(tcx: TyCtxt<'tcx>, impl_did: LocalDefId) -> Coe
|
||||
// Register an obligation for `A: Trait<B>`.
|
||||
let ocx = ObligationCtxt::new(&infcx);
|
||||
let cause = traits::ObligationCause::misc(span, impl_did);
|
||||
let obligation =
|
||||
Obligation::new(tcx, cause, param_env, tcx.mk_trait_ref(trait_def_id, [source, target]));
|
||||
let obligation = Obligation::new(
|
||||
tcx,
|
||||
cause,
|
||||
param_env,
|
||||
ty::TraitRef::new(tcx, trait_def_id, [source, target]),
|
||||
);
|
||||
ocx.register_obligation(obligation);
|
||||
let errors = ocx.select_all_or_error();
|
||||
if !errors.is_empty() {
|
||||
|
@ -601,7 +601,7 @@ fn coerce_unsized(&self, mut source: Ty<'tcx>, mut target: Ty<'tcx>) -> CoerceRe
|
||||
self.tcx,
|
||||
cause,
|
||||
self.fcx.param_env,
|
||||
self.tcx.mk_trait_ref(coerce_unsized_did, [coerce_source, coerce_target])
|
||||
ty::TraitRef::new(self.tcx, coerce_unsized_did, [coerce_source, coerce_target])
|
||||
)];
|
||||
|
||||
let mut has_unsized_tuple_coercion = false;
|
||||
@ -764,8 +764,11 @@ fn coerce_dyn_star(
|
||||
self.tcx,
|
||||
self.cause.clone(),
|
||||
self.param_env,
|
||||
ty::Binder::dummy(
|
||||
self.tcx.at(self.cause.span).mk_trait_ref(hir::LangItem::PointerLike, [a]),
|
||||
ty::TraitRef::from_lang_item(
|
||||
self.tcx,
|
||||
hir::LangItem::PointerLike,
|
||||
self.cause.span,
|
||||
[a],
|
||||
),
|
||||
));
|
||||
|
||||
|
@ -481,7 +481,8 @@ fn blame_specific_expr_if_possible_for_derived_predicate_obligation(
|
||||
// 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.
|
||||
let impl_trait_self_ref = if self.tcx.is_trait_alias(obligation.impl_or_alias_def_id) {
|
||||
self.tcx.mk_trait_ref(
|
||||
ty::TraitRef::new(
|
||||
self.tcx,
|
||||
obligation.impl_or_alias_def_id,
|
||||
ty::InternalSubsts::identity_for_item(self.tcx, obligation.impl_or_alias_def_id),
|
||||
)
|
||||
|
@ -1895,7 +1895,7 @@ fn label_fn_like(
|
||||
_ => {
|
||||
// Look for a user-provided impl of a `Fn` trait, and point to it.
|
||||
let new_def_id = self.probe(|_| {
|
||||
let trait_ref = self.tcx.mk_trait_ref(
|
||||
let trait_ref = ty::TraitRef::new(self.tcx,
|
||||
call_kind.to_def_id(self.tcx),
|
||||
[
|
||||
callee_ty,
|
||||
|
@ -1096,10 +1096,10 @@ pub(crate) fn suggest_into(
|
||||
self.tcx,
|
||||
self.misc(expr.span),
|
||||
self.param_env,
|
||||
ty::Binder::dummy(self.tcx.mk_trait_ref(
|
||||
ty::TraitRef::new(self.tcx,
|
||||
into_def_id,
|
||||
[expr_ty, expected_ty]
|
||||
)),
|
||||
),
|
||||
))
|
||||
{
|
||||
let sugg = if expr.precedence().order() >= PREC_POSTFIX {
|
||||
@ -1438,7 +1438,7 @@ pub(crate) fn note_type_is_not_clone(
|
||||
&& !results.expr_adjustments(callee_expr).iter().any(|adj| matches!(adj.kind, ty::adjustment::Adjust::Deref(..)))
|
||||
// Check that we're in fact trying to clone into the expected type
|
||||
&& self.can_coerce(*pointee_ty, expected_ty)
|
||||
&& let trait_ref = ty::Binder::dummy(self.tcx.mk_trait_ref(clone_trait_did, [expected_ty]))
|
||||
&& let trait_ref = ty::TraitRef::new(self.tcx, clone_trait_did, [expected_ty])
|
||||
// And the expected type doesn't implement `Clone`
|
||||
&& !self.predicate_must_hold_considering_regions(&traits::Obligation::new(
|
||||
self.tcx,
|
||||
|
@ -316,7 +316,7 @@ pub(super) fn obligation_for_method(
|
||||
self.var_for_def(cause.span, param)
|
||||
});
|
||||
|
||||
let trait_ref = self.tcx.mk_trait_ref(trait_def_id, substs);
|
||||
let trait_ref = ty::TraitRef::new(self.tcx, trait_def_id, substs);
|
||||
|
||||
// Construct an obligation
|
||||
let poly_trait_ref = ty::Binder::dummy(trait_ref);
|
||||
|
@ -954,7 +954,7 @@ fn assemble_extension_candidates_for_trait(
|
||||
) {
|
||||
debug!("assemble_extension_candidates_for_trait(trait_def_id={:?})", trait_def_id);
|
||||
let trait_substs = self.fresh_item_substs(trait_def_id);
|
||||
let trait_ref = self.tcx.mk_trait_ref(trait_def_id, trait_substs);
|
||||
let trait_ref = ty::TraitRef::new(self.tcx, trait_def_id, trait_substs);
|
||||
|
||||
if self.tcx.is_trait_alias(trait_def_id) {
|
||||
// For trait aliases, recursively assume all explicitly named traits are relevant
|
||||
|
@ -72,7 +72,8 @@ fn is_fn_ty(&self, ty: Ty<'tcx>, span: Span) -> bool {
|
||||
self.autoderef(span, ty).any(|(ty, _)| {
|
||||
info!("check deref {:?} impl FnOnce", ty);
|
||||
self.probe(|_| {
|
||||
let trait_ref = tcx.mk_trait_ref(
|
||||
let trait_ref = ty::TraitRef::new(
|
||||
tcx,
|
||||
fn_once,
|
||||
[
|
||||
ty,
|
||||
|
@ -261,11 +261,16 @@ fn report_trait_placeholder_mismatch(
|
||||
(false, None, None, Some(span), String::new())
|
||||
};
|
||||
|
||||
let expected_trait_ref = self
|
||||
.cx
|
||||
.resolve_vars_if_possible(self.cx.tcx.mk_trait_ref(trait_def_id, expected_substs));
|
||||
let actual_trait_ref =
|
||||
self.cx.resolve_vars_if_possible(self.cx.tcx.mk_trait_ref(trait_def_id, actual_substs));
|
||||
let expected_trait_ref = self.cx.resolve_vars_if_possible(ty::TraitRef::new(
|
||||
self.cx.tcx,
|
||||
trait_def_id,
|
||||
expected_substs,
|
||||
));
|
||||
let actual_trait_ref = self.cx.resolve_vars_if_possible(ty::TraitRef::new(
|
||||
self.cx.tcx,
|
||||
trait_def_id,
|
||||
actual_substs,
|
||||
));
|
||||
|
||||
// Search the expected and actual trait references to see (a)
|
||||
// whether the sub/sup placeholders appear in them (sometimes
|
||||
|
@ -18,7 +18,7 @@ fn register_bound(
|
||||
def_id: DefId,
|
||||
cause: ObligationCause<'tcx>,
|
||||
) {
|
||||
let trait_ref = infcx.tcx.mk_trait_ref(def_id, [ty]);
|
||||
let trait_ref = ty::TraitRef::new(infcx.tcx, def_id, [ty]);
|
||||
self.register_predicate_obligation(
|
||||
infcx,
|
||||
Obligation {
|
||||
|
@ -1838,7 +1838,7 @@ pub fn mk_fn_def(
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn check_and_mk_substs(
|
||||
pub(crate) fn check_and_mk_substs(
|
||||
self,
|
||||
_def_id: DefId,
|
||||
substs: impl IntoIterator<Item: Into<GenericArg<'tcx>>>,
|
||||
@ -2238,15 +2238,6 @@ pub fn mk_substs_trait(
|
||||
self.mk_substs_from_iter(iter::once(self_ty.into()).chain(rest))
|
||||
}
|
||||
|
||||
pub fn mk_trait_ref(
|
||||
self,
|
||||
trait_def_id: DefId,
|
||||
substs: impl IntoIterator<Item: Into<GenericArg<'tcx>>>,
|
||||
) -> ty::TraitRef<'tcx> {
|
||||
let substs = self.check_and_mk_substs(trait_def_id, substs);
|
||||
ty::TraitRef { def_id: trait_def_id, substs, _use_mk_trait_ref_instead: () }
|
||||
}
|
||||
|
||||
pub fn mk_alias_ty(
|
||||
self,
|
||||
def_id: DefId,
|
||||
@ -2441,15 +2432,6 @@ pub fn ty_error_misc(self) -> Ty<'tcx> {
|
||||
pub fn ty_error_with_message(self, msg: &str) -> Ty<'tcx> {
|
||||
self.tcx.ty_error_with_message(self.span, msg)
|
||||
}
|
||||
|
||||
pub fn mk_trait_ref(
|
||||
self,
|
||||
trait_lang_item: LangItem,
|
||||
substs: impl IntoIterator<Item: Into<ty::GenericArg<'tcx>>>,
|
||||
) -> ty::TraitRef<'tcx> {
|
||||
let trait_def_id = self.require_lang_item(trait_lang_item, Some(self.span));
|
||||
self.tcx.mk_trait_ref(trait_def_id, substs)
|
||||
}
|
||||
}
|
||||
|
||||
/// Parameter attributes that can only be determined by examining the body of a function instead
|
||||
|
@ -1210,6 +1210,18 @@ fn to_predicate(self, _: TyCtxt<'tcx>) -> PolyTraitPredicate<'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> ToPredicate<'tcx, PolyTraitPredicate<'tcx>> for TraitRef<'tcx> {
|
||||
fn to_predicate(self, tcx: TyCtxt<'tcx>) -> PolyTraitPredicate<'tcx> {
|
||||
ty::Binder::dummy(self).to_predicate(tcx)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> ToPredicate<'tcx, PolyTraitPredicate<'tcx>> for TraitPredicate<'tcx> {
|
||||
fn to_predicate(self, _tcx: TyCtxt<'tcx>) -> PolyTraitPredicate<'tcx> {
|
||||
ty::Binder::dummy(self)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> ToPredicate<'tcx> for PolyTraitPredicate<'tcx> {
|
||||
fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
|
||||
self.map_bound(|p| PredicateKind::Clause(Clause::Trait(p))).to_predicate(tcx)
|
||||
@ -1234,6 +1246,12 @@ fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> ToPredicate<'tcx> for TraitPredicate<'tcx> {
|
||||
fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
|
||||
PredicateKind::Clause(Clause::Trait(self)).to_predicate(tcx)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> Predicate<'tcx> {
|
||||
pub fn to_opt_poly_trait_pred(self) -> Option<PolyTraitPredicate<'tcx>> {
|
||||
let predicate = self.kind();
|
||||
|
@ -169,8 +169,11 @@ fn default_print_def_path(
|
||||
self.path_append(
|
||||
|cx: Self| {
|
||||
if trait_qualify_parent {
|
||||
let trait_ref =
|
||||
cx.tcx().mk_trait_ref(parent_def_id, parent_substs.iter().copied());
|
||||
let trait_ref = ty::TraitRef::new(
|
||||
cx.tcx(),
|
||||
parent_def_id,
|
||||
parent_substs.iter().copied(),
|
||||
);
|
||||
cx.path_qualified(trait_ref.self_ty(), Some(trait_ref))
|
||||
} else {
|
||||
cx.print_def_path(parent_def_id, parent_substs)
|
||||
|
@ -315,7 +315,7 @@ fn relate<R: TypeRelation<'tcx>>(
|
||||
Err(TypeError::Traits(expected_found(relation, a.def_id, b.def_id)))
|
||||
} else {
|
||||
let substs = relate_substs(relation, a.substs, b.substs)?;
|
||||
Ok(relation.tcx().mk_trait_ref(a.def_id, substs))
|
||||
Ok(ty::TraitRef::new(relation.tcx(), a.def_id, substs))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -727,13 +727,13 @@ pub fn with_self_ty(&self, tcx: TyCtxt<'tcx>, self_ty: Ty<'tcx>) -> ty::Predicat
|
||||
ExistentialPredicate::AutoTrait(did) => {
|
||||
let generics = tcx.generics_of(did);
|
||||
let trait_ref = if generics.params.len() == 1 {
|
||||
tcx.mk_trait_ref(did, [self_ty])
|
||||
ty::TraitRef::new(tcx, did, [self_ty])
|
||||
} else {
|
||||
// If this is an ill-formed auto trait, then synthesize
|
||||
// new error substs for the missing generics.
|
||||
let err_substs =
|
||||
ty::InternalSubsts::extend_with_error(tcx, did, &[self_ty.into()]);
|
||||
tcx.mk_trait_ref(did, err_substs)
|
||||
ty::TraitRef::new(tcx, did, err_substs)
|
||||
};
|
||||
self.rebind(trait_ref).without_const().to_predicate(tcx)
|
||||
}
|
||||
@ -820,27 +820,28 @@ pub struct TraitRef<'tcx> {
|
||||
pub def_id: DefId,
|
||||
pub substs: SubstsRef<'tcx>,
|
||||
/// This field exists to prevent the creation of `TraitRef` without
|
||||
/// calling [TyCtxt::mk_trait_ref].
|
||||
pub(super) _use_mk_trait_ref_instead: (),
|
||||
/// calling [`TraitRef::new`].
|
||||
pub(super) _use_trait_ref_new_instead: (),
|
||||
}
|
||||
|
||||
impl<'tcx> TraitRef<'tcx> {
|
||||
pub fn with_self_ty(self, tcx: TyCtxt<'tcx>, self_ty: Ty<'tcx>) -> Self {
|
||||
tcx.mk_trait_ref(
|
||||
self.def_id,
|
||||
[self_ty.into()].into_iter().chain(self.substs.iter().skip(1)),
|
||||
)
|
||||
pub fn new(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
trait_def_id: DefId,
|
||||
substs: impl IntoIterator<Item: Into<GenericArg<'tcx>>>,
|
||||
) -> Self {
|
||||
let substs = tcx.check_and_mk_substs(trait_def_id, substs);
|
||||
Self { def_id: trait_def_id, substs, _use_trait_ref_new_instead: () }
|
||||
}
|
||||
|
||||
/// Returns a `TraitRef` of the form `P0: Foo<P1..Pn>` where `Pi`
|
||||
/// are the parameters defined on trait.
|
||||
pub fn identity(tcx: TyCtxt<'tcx>, def_id: DefId) -> Binder<'tcx, TraitRef<'tcx>> {
|
||||
ty::Binder::dummy(tcx.mk_trait_ref(def_id, InternalSubsts::identity_for_item(tcx, def_id)))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn self_ty(&self) -> Ty<'tcx> {
|
||||
self.substs.type_at(0)
|
||||
pub fn from_lang_item(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
trait_lang_item: LangItem,
|
||||
span: Span,
|
||||
substs: impl IntoIterator<Item: Into<ty::GenericArg<'tcx>>>,
|
||||
) -> Self {
|
||||
let trait_def_id = tcx.require_lang_item(trait_lang_item, Some(span));
|
||||
Self::new(tcx, trait_def_id, substs)
|
||||
}
|
||||
|
||||
pub fn from_method(
|
||||
@ -849,7 +850,38 @@ pub fn from_method(
|
||||
substs: SubstsRef<'tcx>,
|
||||
) -> ty::TraitRef<'tcx> {
|
||||
let defs = tcx.generics_of(trait_id);
|
||||
tcx.mk_trait_ref(trait_id, tcx.mk_substs(&substs[..defs.params.len()]))
|
||||
ty::TraitRef::new(tcx, trait_id, tcx.mk_substs(&substs[..defs.params.len()]))
|
||||
}
|
||||
|
||||
/// Returns a `TraitRef` of the form `P0: Foo<P1..Pn>` where `Pi`
|
||||
/// are the parameters defined on trait.
|
||||
pub fn identity(tcx: TyCtxt<'tcx>, def_id: DefId) -> TraitRef<'tcx> {
|
||||
ty::TraitRef::new(tcx, def_id, InternalSubsts::identity_for_item(tcx, def_id))
|
||||
}
|
||||
|
||||
pub fn with_self_ty(self, tcx: TyCtxt<'tcx>, self_ty: Ty<'tcx>) -> Self {
|
||||
ty::TraitRef::new(
|
||||
tcx,
|
||||
self.def_id,
|
||||
[self_ty.into()].into_iter().chain(self.substs.iter().skip(1)),
|
||||
)
|
||||
}
|
||||
|
||||
/// Converts this trait ref to a trait predicate with a given `constness` and a positive polarity.
|
||||
#[inline]
|
||||
pub fn with_constness(self, constness: ty::BoundConstness) -> ty::TraitPredicate<'tcx> {
|
||||
ty::TraitPredicate { trait_ref: self, constness, polarity: ty::ImplPolarity::Positive }
|
||||
}
|
||||
|
||||
/// Converts this trait ref to a trait predicate without `const` and a positive polarity.
|
||||
#[inline]
|
||||
pub fn without_const(self) -> ty::TraitPredicate<'tcx> {
|
||||
self.with_constness(ty::BoundConstness::NotConst)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn self_ty(&self) -> Ty<'tcx> {
|
||||
self.substs.type_at(0)
|
||||
}
|
||||
}
|
||||
|
||||
@ -907,7 +939,7 @@ pub fn with_self_ty(&self, tcx: TyCtxt<'tcx>, self_ty: Ty<'tcx>) -> ty::TraitRef
|
||||
// otherwise the escaping vars would be captured by the binder
|
||||
// debug_assert!(!self_ty.has_escaping_bound_vars());
|
||||
|
||||
tcx.mk_trait_ref(self.def_id, [self_ty.into()].into_iter().chain(self.substs.iter()))
|
||||
ty::TraitRef::new(tcx, self.def_id, [self_ty.into()].into_iter().chain(self.substs.iter()))
|
||||
}
|
||||
}
|
||||
|
||||
@ -1226,7 +1258,7 @@ pub fn trait_ref_and_own_substs(
|
||||
let trait_def_id = self.trait_def_id(tcx);
|
||||
let trait_generics = tcx.generics_of(trait_def_id);
|
||||
(
|
||||
tcx.mk_trait_ref(trait_def_id, self.substs.truncate_to(tcx, trait_generics)),
|
||||
ty::TraitRef::new(tcx, trait_def_id, self.substs.truncate_to(tcx, trait_generics)),
|
||||
&self.substs[trait_generics.count()..],
|
||||
)
|
||||
}
|
||||
@ -1240,7 +1272,7 @@ pub fn trait_ref_and_own_substs(
|
||||
/// as well.
|
||||
pub fn trait_ref(self, tcx: TyCtxt<'tcx>) -> ty::TraitRef<'tcx> {
|
||||
let def_id = self.trait_def_id(tcx);
|
||||
tcx.mk_trait_ref(def_id, self.substs.truncate_to(tcx, tcx.generics_of(def_id)))
|
||||
ty::TraitRef::new(tcx, def_id, self.substs.truncate_to(tcx, tcx.generics_of(def_id)))
|
||||
}
|
||||
|
||||
pub fn self_ty(self) -> Ty<'tcx> {
|
||||
|
@ -191,7 +191,7 @@ fn type_may_have_partial_eq_impl(&self, ty: Ty<'tcx>) -> bool {
|
||||
self.tcx(),
|
||||
ObligationCause::dummy(),
|
||||
self.param_env,
|
||||
self.tcx().mk_trait_ref(partial_eq_trait_id, [ty, ty]),
|
||||
ty::TraitRef::new(self.tcx(), partial_eq_trait_id, [ty, ty]),
|
||||
);
|
||||
|
||||
// FIXME: should this call a `predicate_must_hold` variant instead?
|
||||
|
@ -30,8 +30,12 @@ fn custom_coerce_unsize_info<'tcx>(
|
||||
source_ty: Ty<'tcx>,
|
||||
target_ty: Ty<'tcx>,
|
||||
) -> CustomCoerceUnsized {
|
||||
let trait_ref =
|
||||
ty::Binder::dummy(tcx.mk_trait_ref(LangItem::CoerceUnsized, [source_ty, target_ty]));
|
||||
let trait_ref = ty::Binder::dummy(ty::TraitRef::from_lang_item(
|
||||
tcx.tcx,
|
||||
LangItem::CoerceUnsized,
|
||||
tcx.span,
|
||||
[source_ty, target_ty],
|
||||
));
|
||||
|
||||
match tcx.codegen_select_candidate((ty::ParamEnv::reveal_all(), trait_ref)) {
|
||||
Ok(traits::ImplSource::UserDefined(traits::ImplSourceUserDefinedData {
|
||||
|
@ -127,18 +127,19 @@ fn visit_trait(&mut self, trait_ref: TraitRef<'tcx>) -> ControlFlow<V::BreakTy>
|
||||
|
||||
fn visit_projection_ty(&mut self, projection: ty::AliasTy<'tcx>) -> ControlFlow<V::BreakTy> {
|
||||
let tcx = self.def_id_visitor.tcx();
|
||||
let (trait_ref, assoc_substs) =
|
||||
if tcx.def_kind(projection.def_id) != DefKind::ImplTraitPlaceholder {
|
||||
projection.trait_ref_and_own_substs(tcx)
|
||||
} else {
|
||||
// HACK(RPITIT): Remove this when RPITITs are lowered to regular assoc tys
|
||||
let def_id = tcx.impl_trait_in_trait_parent_fn(projection.def_id);
|
||||
let trait_generics = tcx.generics_of(def_id);
|
||||
(
|
||||
tcx.mk_trait_ref(def_id, projection.substs.truncate_to(tcx, trait_generics)),
|
||||
&projection.substs[trait_generics.count()..],
|
||||
)
|
||||
};
|
||||
let (trait_ref, assoc_substs) = if tcx.def_kind(projection.def_id)
|
||||
!= DefKind::ImplTraitPlaceholder
|
||||
{
|
||||
projection.trait_ref_and_own_substs(tcx)
|
||||
} else {
|
||||
// HACK(RPITIT): Remove this when RPITITs are lowered to regular assoc tys
|
||||
let def_id = tcx.impl_trait_in_trait_parent_fn(projection.def_id);
|
||||
let trait_generics = tcx.generics_of(def_id);
|
||||
(
|
||||
ty::TraitRef::new(tcx, def_id, projection.substs.truncate_to(tcx, trait_generics)),
|
||||
&projection.substs[trait_generics.count()..],
|
||||
)
|
||||
};
|
||||
self.visit_trait(trait_ref)?;
|
||||
if self.def_id_visitor.shallow() {
|
||||
ControlFlow::Continue(())
|
||||
|
@ -66,7 +66,7 @@ fn type_implements_trait(
|
||||
params: impl IntoIterator<Item: Into<GenericArg<'tcx>>>,
|
||||
param_env: ty::ParamEnv<'tcx>,
|
||||
) -> traits::EvaluationResult {
|
||||
let trait_ref = self.tcx.mk_trait_ref(trait_def_id, params);
|
||||
let trait_ref = ty::TraitRef::new(self.tcx, trait_def_id, params);
|
||||
|
||||
let obligation = traits::Obligation {
|
||||
cause: traits::ObligationCause::dummy(),
|
||||
|
@ -274,8 +274,9 @@ fn consider_builtin_fn_trait_candidates(
|
||||
.evaluate_added_goals_and_make_canonical_response(Certainty::AMBIGUOUS);
|
||||
}
|
||||
};
|
||||
let output_is_sized_pred = tupled_inputs_and_output
|
||||
.map_bound(|(_, output)| tcx.at(DUMMY_SP).mk_trait_ref(LangItem::Sized, [output]));
|
||||
let output_is_sized_pred = tupled_inputs_and_output.map_bound(|(_, output)| {
|
||||
ty::TraitRef::from_lang_item(tcx, LangItem::Sized, DUMMY_SP, [output])
|
||||
});
|
||||
|
||||
let pred = tupled_inputs_and_output
|
||||
.map_bound(|(inputs, output)| ty::ProjectionPredicate {
|
||||
@ -333,10 +334,12 @@ fn consider_builtin_pointee_candidate(
|
||||
|
||||
ty::Alias(_, _) | ty::Param(_) | ty::Placeholder(..) => {
|
||||
// FIXME(ptr_metadata): It would also be possible to return a `Ok(Ambig)` with no constraints.
|
||||
let sized_predicate = ty::Binder::dummy(tcx.at(DUMMY_SP).mk_trait_ref(
|
||||
let sized_predicate = ty::TraitRef::from_lang_item(
|
||||
tcx,
|
||||
LangItem::Sized,
|
||||
DUMMY_SP,
|
||||
[ty::GenericArg::from(goal.predicate.self_ty())],
|
||||
));
|
||||
);
|
||||
ecx.add_goal(goal.with(tcx, sized_predicate));
|
||||
tcx.types.unit
|
||||
}
|
||||
|
@ -272,12 +272,13 @@ fn consider_builtin_fn_trait_candidates(
|
||||
.evaluate_added_goals_and_make_canonical_response(Certainty::AMBIGUOUS);
|
||||
}
|
||||
};
|
||||
let output_is_sized_pred = tupled_inputs_and_output
|
||||
.map_bound(|(_, output)| tcx.at(DUMMY_SP).mk_trait_ref(LangItem::Sized, [output]));
|
||||
let output_is_sized_pred = tupled_inputs_and_output.map_bound(|(_, output)| {
|
||||
ty::TraitRef::from_lang_item(tcx, LangItem::Sized, DUMMY_SP, [output])
|
||||
});
|
||||
|
||||
let pred = tupled_inputs_and_output
|
||||
.map_bound(|(inputs, _)| {
|
||||
tcx.mk_trait_ref(goal.predicate.def_id(), [goal.predicate.self_ty(), inputs])
|
||||
ty::TraitRef::new(tcx, goal.predicate.def_id(), [goal.predicate.self_ty(), inputs])
|
||||
})
|
||||
.to_predicate(tcx);
|
||||
// A built-in `Fn` impl only holds if the output is sized.
|
||||
@ -358,10 +359,8 @@ fn consider_builtin_generator_candidate(
|
||||
Self::consider_implied_clause(
|
||||
ecx,
|
||||
goal,
|
||||
ty::Binder::dummy(
|
||||
tcx.mk_trait_ref(goal.predicate.def_id(), [self_ty, generator.resume_ty()]),
|
||||
)
|
||||
.to_predicate(tcx),
|
||||
ty::TraitRef::new(tcx, goal.predicate.def_id(), [self_ty, generator.resume_ty()])
|
||||
.to_predicate(tcx),
|
||||
// Technically, we need to check that the generator types are Sized,
|
||||
// but that's already proven by the generator being WF.
|
||||
[],
|
||||
@ -410,9 +409,7 @@ fn consider_builtin_unsize_candidate(
|
||||
data.iter().map(|pred| goal.with(tcx, pred.with_self_ty(tcx, a_ty))),
|
||||
);
|
||||
// The type must be Sized to be unsized.
|
||||
ecx.add_goal(
|
||||
goal.with(tcx, ty::Binder::dummy(tcx.mk_trait_ref(sized_def_id, [a_ty]))),
|
||||
);
|
||||
ecx.add_goal(goal.with(tcx, ty::TraitRef::new(tcx, sized_def_id, [a_ty])));
|
||||
// The type must outlive the lifetime of the `dyn` we're unsizing into.
|
||||
ecx.add_goal(
|
||||
goal.with(tcx, ty::Binder::dummy(ty::OutlivesPredicate(a_ty, region))),
|
||||
@ -461,9 +458,7 @@ fn consider_builtin_unsize_candidate(
|
||||
ecx.eq(goal.param_env, unsized_a_ty, b_ty)?;
|
||||
ecx.add_goal(goal.with(
|
||||
tcx,
|
||||
ty::Binder::dummy(
|
||||
tcx.mk_trait_ref(goal.predicate.def_id(), [a_tail_ty, b_tail_ty]),
|
||||
),
|
||||
ty::TraitRef::new(tcx, goal.predicate.def_id(), [a_tail_ty, b_tail_ty]),
|
||||
));
|
||||
ecx.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)
|
||||
}
|
||||
@ -482,9 +477,7 @@ fn consider_builtin_unsize_candidate(
|
||||
// Similar to ADTs, require that the rest of the fields are equal.
|
||||
ecx.add_goal(goal.with(
|
||||
tcx,
|
||||
ty::Binder::dummy(
|
||||
tcx.mk_trait_ref(goal.predicate.def_id(), [*a_last_ty, *b_last_ty]),
|
||||
),
|
||||
ty::TraitRef::new(tcx, goal.predicate.def_id(), [*a_last_ty, *b_last_ty]),
|
||||
));
|
||||
ecx.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)
|
||||
}
|
||||
|
@ -86,7 +86,7 @@ pub fn find_auto_trait_generics<A>(
|
||||
) -> AutoTraitResult<A> {
|
||||
let tcx = self.tcx;
|
||||
|
||||
let trait_ref = tcx.mk_trait_ref(trait_did, [ty]);
|
||||
let trait_ref = ty::TraitRef::new(tcx, trait_did, [ty]);
|
||||
|
||||
let infcx = tcx.infer_ctxt().build();
|
||||
let mut selcx = SelectionContext::new(&infcx);
|
||||
@ -263,7 +263,7 @@ fn evaluate_predicates(
|
||||
let mut already_visited = FxHashSet::default();
|
||||
let mut predicates = VecDeque::new();
|
||||
predicates.push_back(ty::Binder::dummy(ty::TraitPredicate {
|
||||
trait_ref: infcx.tcx.mk_trait_ref(trait_did, [ty]),
|
||||
trait_ref: ty::TraitRef::new(infcx.tcx, trait_did, [ty]),
|
||||
|
||||
constness: ty::BoundConstness::NotConst,
|
||||
// Auto traits are positive
|
||||
|
@ -97,7 +97,7 @@ pub fn register_bound(
|
||||
def_id: DefId,
|
||||
) {
|
||||
let tcx = self.infcx.tcx;
|
||||
let trait_ref = tcx.mk_trait_ref(def_id, [ty]);
|
||||
let trait_ref = ty::TraitRef::new(tcx, def_id, [ty]);
|
||||
self.register_obligation(Obligation {
|
||||
cause,
|
||||
recursion_depth: 0,
|
||||
|
@ -87,7 +87,7 @@ pub fn recompute_applicable_impls<'tcx>(
|
||||
if let ty::PredicateKind::Clause(ty::Clause::Trait(trait_pred)) = kind.skip_binder()
|
||||
&& param_env_candidate_may_apply(kind.rebind(trait_pred))
|
||||
{
|
||||
if kind.rebind(trait_pred.trait_ref) == ty::TraitRef::identity(tcx, trait_pred.def_id()) {
|
||||
if kind.rebind(trait_pred.trait_ref) == ty::Binder::dummy(ty::TraitRef::identity(tcx, trait_pred.def_id())) {
|
||||
ambiguities.push(Ambiguity::ParamEnv(tcx.def_span(trait_pred.def_id())))
|
||||
} else {
|
||||
ambiguities.push(Ambiguity::ParamEnv(span))
|
||||
|
@ -358,7 +358,7 @@ fn type_implements_fn_trait(
|
||||
span: DUMMY_SP,
|
||||
kind: TypeVariableOriginKind::MiscVariable,
|
||||
});
|
||||
let trait_ref = self.tcx.mk_trait_ref(trait_def_id, [ty.skip_binder(), var]);
|
||||
let trait_ref = ty::TraitRef::new(self.tcx, trait_def_id, [ty.skip_binder(), var]);
|
||||
let obligation = Obligation::new(
|
||||
self.tcx,
|
||||
ObligationCause::dummy(),
|
||||
|
@ -3502,7 +3502,7 @@ fn suggest_derive(
|
||||
_ => None,
|
||||
};
|
||||
let trait_pred = trait_pred.map_bound_ref(|tr| ty::TraitPredicate {
|
||||
trait_ref: self.tcx.mk_trait_ref(
|
||||
trait_ref: ty::TraitRef::new(self.tcx,
|
||||
trait_pred.def_id(),
|
||||
[field_ty].into_iter().chain(trait_substs),
|
||||
),
|
||||
|
@ -127,7 +127,7 @@ pub fn type_known_to_meet_bound_modulo_regions<'tcx>(
|
||||
ty: Ty<'tcx>,
|
||||
def_id: DefId,
|
||||
) -> bool {
|
||||
let trait_ref = ty::Binder::dummy(infcx.tcx.mk_trait_ref(def_id, [ty]));
|
||||
let trait_ref = ty::TraitRef::new(infcx.tcx, def_id, [ty]);
|
||||
pred_known_to_hold_modulo_regions(infcx, param_env, trait_ref.without_const())
|
||||
}
|
||||
|
||||
|
@ -279,7 +279,7 @@ fn predicates_reference_self(
|
||||
trait_def_id: DefId,
|
||||
supertraits_only: bool,
|
||||
) -> SmallVec<[Span; 1]> {
|
||||
let trait_ref = ty::TraitRef::identity(tcx, trait_def_id);
|
||||
let trait_ref = ty::Binder::dummy(ty::TraitRef::identity(tcx, trait_def_id));
|
||||
let predicates = if supertraits_only {
|
||||
tcx.super_predicates_of(trait_def_id)
|
||||
} else {
|
||||
@ -661,9 +661,9 @@ fn object_ty_for_trait<'tcx>(
|
||||
let trait_ref = ty::TraitRef::identity(tcx, trait_def_id);
|
||||
debug!(?trait_ref);
|
||||
|
||||
let trait_predicate = trait_ref.map_bound(|trait_ref| {
|
||||
ty::ExistentialPredicate::Trait(ty::ExistentialTraitRef::erase_self_ty(tcx, trait_ref))
|
||||
});
|
||||
let trait_predicate = ty::Binder::dummy(ty::ExistentialPredicate::Trait(
|
||||
ty::ExistentialTraitRef::erase_self_ty(tcx, trait_ref),
|
||||
));
|
||||
debug!(?trait_predicate);
|
||||
|
||||
let pred: ty::Predicate<'tcx> = trait_ref.to_predicate(tcx);
|
||||
@ -769,11 +769,10 @@ fn receiver_is_dispatchable<'tcx>(
|
||||
let param_env = tcx.param_env(method.def_id);
|
||||
|
||||
// Self: Unsize<U>
|
||||
let unsize_predicate = ty::Binder::dummy(
|
||||
tcx.mk_trait_ref(unsize_did, [tcx.types.self_param, unsized_self_ty]),
|
||||
)
|
||||
.without_const()
|
||||
.to_predicate(tcx);
|
||||
let unsize_predicate =
|
||||
ty::TraitRef::new(tcx, unsize_did, [tcx.types.self_param, unsized_self_ty])
|
||||
.without_const()
|
||||
.to_predicate(tcx);
|
||||
|
||||
// U: Trait<Arg1, ..., ArgN>
|
||||
let trait_predicate = {
|
||||
@ -782,7 +781,7 @@ fn receiver_is_dispatchable<'tcx>(
|
||||
if param.index == 0 { unsized_self_ty.into() } else { tcx.mk_param_from_def(param) }
|
||||
});
|
||||
|
||||
ty::Binder::dummy(tcx.mk_trait_ref(trait_def_id, substs)).to_predicate(tcx)
|
||||
ty::TraitRef::new(tcx, trait_def_id, substs).to_predicate(tcx)
|
||||
};
|
||||
|
||||
let caller_bounds =
|
||||
@ -797,9 +796,8 @@ fn receiver_is_dispatchable<'tcx>(
|
||||
|
||||
// Receiver: DispatchFromDyn<Receiver[Self => U]>
|
||||
let obligation = {
|
||||
let predicate = ty::Binder::dummy(
|
||||
tcx.mk_trait_ref(dispatch_from_dyn_did, [receiver_ty, unsized_receiver_ty]),
|
||||
);
|
||||
let predicate =
|
||||
ty::TraitRef::new(tcx, dispatch_from_dyn_did, [receiver_ty, unsized_receiver_ty]);
|
||||
|
||||
Obligation::new(tcx, ObligationCause::dummy(), param_env, predicate)
|
||||
};
|
||||
@ -882,7 +880,8 @@ fn visit_ty(&mut self, t: Ty<'tcx>) -> ControlFlow<Self::BreakTy> {
|
||||
|
||||
// Compute supertraits of current trait lazily.
|
||||
if self.supertraits.is_none() {
|
||||
let trait_ref = ty::TraitRef::identity(self.tcx, self.trait_def_id);
|
||||
let trait_ref =
|
||||
ty::Binder::dummy(ty::TraitRef::identity(self.tcx, self.trait_def_id));
|
||||
self.supertraits = Some(
|
||||
traits::supertraits(self.tcx, trait_ref).map(|t| t.def_id()).collect(),
|
||||
);
|
||||
|
@ -1319,7 +1319,7 @@ fn assemble_candidate_for_impl_trait_in_trait<'cx, 'tcx>(
|
||||
let trait_substs =
|
||||
obligation.predicate.substs.truncate_to(tcx, tcx.generics_of(trait_def_id));
|
||||
// FIXME(named-returns): Binders
|
||||
let trait_predicate = ty::Binder::dummy(tcx.mk_trait_ref(trait_def_id, trait_substs));
|
||||
let trait_predicate = ty::TraitRef::new(tcx, trait_def_id, trait_substs);
|
||||
|
||||
let _ = selcx.infcx.commit_if_ok(|_| {
|
||||
match selcx.select(&obligation.with(tcx, trait_predicate)) {
|
||||
@ -1682,10 +1682,8 @@ fn assemble_candidates_from_impls<'cx, 'tcx>(
|
||||
if selcx.infcx.predicate_must_hold_modulo_regions(
|
||||
&obligation.with(
|
||||
selcx.tcx(),
|
||||
ty::Binder::dummy(
|
||||
selcx.tcx().at(obligation.cause.span()).mk_trait_ref(LangItem::Sized, [self_ty]),
|
||||
)
|
||||
.without_const(),
|
||||
ty::TraitRef::from_lang_item(selcx.tcx(), LangItem::Sized, obligation.cause.span(),[self_ty])
|
||||
.without_const(),
|
||||
),
|
||||
) =>
|
||||
{
|
||||
@ -1948,8 +1946,11 @@ fn confirm_builtin_candidate<'cx, 'tcx>(
|
||||
)
|
||||
});
|
||||
if check_is_sized {
|
||||
let sized_predicate = ty::Binder::dummy(
|
||||
tcx.at(obligation.cause.span()).mk_trait_ref(LangItem::Sized, [self_ty]),
|
||||
let sized_predicate = ty::TraitRef::from_lang_item(
|
||||
tcx,
|
||||
LangItem::Sized,
|
||||
obligation.cause.span(),
|
||||
[self_ty],
|
||||
)
|
||||
.without_const();
|
||||
obligations.push(obligation.with(tcx, sized_predicate));
|
||||
|
@ -459,7 +459,7 @@ fn reject_fn_ptr_impls(
|
||||
obligation.param_env,
|
||||
self.tcx().mk_predicate(obligation.predicate.map_bound(|mut pred| {
|
||||
pred.trait_ref =
|
||||
self.tcx().mk_trait_ref(fn_ptr_trait, [pred.trait_ref.self_ty()]);
|
||||
ty::TraitRef::new(self.tcx(), fn_ptr_trait, [pred.trait_ref.self_ty()]);
|
||||
ty::PredicateKind::Clause(ty::Clause::Trait(pred))
|
||||
})),
|
||||
);
|
||||
@ -634,7 +634,7 @@ fn need_migrate_deref_output_trait_object(
|
||||
}
|
||||
|
||||
// <ty as Deref>
|
||||
let trait_ref = tcx.mk_trait_ref(tcx.lang_items().deref_trait()?, [ty]);
|
||||
let trait_ref = ty::TraitRef::new(tcx, tcx.lang_items().deref_trait()?, [ty]);
|
||||
|
||||
let obligation =
|
||||
traits::Obligation::new(tcx, cause.clone(), param_env, ty::Binder::dummy(trait_ref));
|
||||
|
@ -646,8 +646,7 @@ fn confirm_fn_pointer_candidate(
|
||||
output_ty,
|
||||
&mut nested,
|
||||
);
|
||||
let tr =
|
||||
ty::Binder::dummy(self.tcx().at(cause.span).mk_trait_ref(LangItem::Sized, [output_ty]));
|
||||
let tr = ty::TraitRef::from_lang_item(self.tcx(), LangItem::Sized, cause.span, [output_ty]);
|
||||
nested.push(Obligation::new(self.infcx.tcx, cause, obligation.param_env, tr));
|
||||
|
||||
Ok(ImplSourceFnPointerData { fn_ty: self_ty, nested })
|
||||
@ -1050,8 +1049,7 @@ fn confirm_builtin_unsize_candidate(
|
||||
);
|
||||
|
||||
// We can only make objects from sized types.
|
||||
let tr =
|
||||
ty::Binder::dummy(tcx.at(cause.span).mk_trait_ref(LangItem::Sized, [source]));
|
||||
let tr = ty::TraitRef::from_lang_item(tcx, LangItem::Sized, cause.span, [source]);
|
||||
nested.push(predicate_to_obligation(tr.without_const().to_predicate(tcx)));
|
||||
|
||||
// If the type is `Foo + 'a`, ensure that the type
|
||||
@ -1121,7 +1119,11 @@ fn confirm_builtin_unsize_candidate(
|
||||
// Construct the nested `TailField<T>: Unsize<TailField<U>>` predicate.
|
||||
let tail_unsize_obligation = obligation.with(
|
||||
tcx,
|
||||
tcx.mk_trait_ref(obligation.predicate.def_id(), [source_tail, target_tail]),
|
||||
ty::TraitRef::new(
|
||||
tcx,
|
||||
obligation.predicate.def_id(),
|
||||
[source_tail, target_tail],
|
||||
),
|
||||
);
|
||||
nested.push(tail_unsize_obligation);
|
||||
}
|
||||
@ -1146,8 +1148,10 @@ fn confirm_builtin_unsize_candidate(
|
||||
nested.extend(obligations);
|
||||
|
||||
// Add a nested `T: Unsize<U>` predicate.
|
||||
let last_unsize_obligation = obligation
|
||||
.with(tcx, tcx.mk_trait_ref(obligation.predicate.def_id(), [a_last, b_last]));
|
||||
let last_unsize_obligation = obligation.with(
|
||||
tcx,
|
||||
ty::TraitRef::new(tcx, obligation.predicate.def_id(), [a_last, b_last]),
|
||||
);
|
||||
nested.push(last_unsize_obligation);
|
||||
}
|
||||
|
||||
@ -1271,10 +1275,12 @@ fn confirm_const_destruct_candidate(
|
||||
cause.clone(),
|
||||
obligation.recursion_depth + 1,
|
||||
self_ty.rebind(ty::TraitPredicate {
|
||||
trait_ref: self
|
||||
.tcx()
|
||||
.at(cause.span)
|
||||
.mk_trait_ref(LangItem::Destruct, [nested_ty]),
|
||||
trait_ref: ty::TraitRef::from_lang_item(
|
||||
self.tcx(),
|
||||
LangItem::Destruct,
|
||||
cause.span,
|
||||
[nested_ty],
|
||||
),
|
||||
constness: ty::BoundConstness::ConstIfConst,
|
||||
polarity: ty::ImplPolarity::Positive,
|
||||
}),
|
||||
@ -1295,10 +1301,12 @@ fn confirm_const_destruct_candidate(
|
||||
// or it's an ADT (and we need to check for a custom impl during selection)
|
||||
_ => {
|
||||
let predicate = self_ty.rebind(ty::TraitPredicate {
|
||||
trait_ref: self
|
||||
.tcx()
|
||||
.at(cause.span)
|
||||
.mk_trait_ref(LangItem::Destruct, [nested_ty]),
|
||||
trait_ref: ty::TraitRef::from_lang_item(
|
||||
self.tcx(),
|
||||
LangItem::Destruct,
|
||||
cause.span,
|
||||
[nested_ty],
|
||||
),
|
||||
constness: ty::BoundConstness::ConstIfConst,
|
||||
polarity: ty::ImplPolarity::Positive,
|
||||
});
|
||||
|
@ -2413,7 +2413,7 @@ fn collect_predicates_for_types(
|
||||
self.tcx(),
|
||||
cause.clone(),
|
||||
param_env,
|
||||
self.tcx().mk_trait_ref(trait_def_id, [normalized_ty]),
|
||||
ty::TraitRef::new(self.tcx(), trait_def_id, [normalized_ty]),
|
||||
);
|
||||
obligations.push(obligation);
|
||||
obligations
|
||||
|
@ -262,7 +262,7 @@ pub fn closure_trait_ref_and_return_type<'tcx>(
|
||||
TupleArgumentsFlag::No => sig.skip_binder().inputs()[0],
|
||||
TupleArgumentsFlag::Yes => tcx.mk_tup(sig.skip_binder().inputs()),
|
||||
};
|
||||
let trait_ref = tcx.mk_trait_ref(fn_trait_def_id, [self_ty, arguments_tuple]);
|
||||
let trait_ref = ty::TraitRef::new(tcx, fn_trait_def_id, [self_ty, arguments_tuple]);
|
||||
sig.map_bound(|sig| (trait_ref, sig.output()))
|
||||
}
|
||||
|
||||
@ -273,7 +273,7 @@ pub fn generator_trait_ref_and_outputs<'tcx>(
|
||||
sig: ty::PolyGenSig<'tcx>,
|
||||
) -> ty::Binder<'tcx, (ty::TraitRef<'tcx>, Ty<'tcx>, Ty<'tcx>)> {
|
||||
assert!(!self_ty.has_escaping_bound_vars());
|
||||
let trait_ref = tcx.mk_trait_ref(fn_trait_def_id, [self_ty, sig.skip_binder().resume_ty]);
|
||||
let trait_ref = ty::TraitRef::new(tcx, fn_trait_def_id, [self_ty, sig.skip_binder().resume_ty]);
|
||||
sig.map_bound(|sig| (trait_ref, sig.yield_ty, sig.return_ty))
|
||||
}
|
||||
|
||||
@ -284,7 +284,7 @@ pub fn future_trait_ref_and_outputs<'tcx>(
|
||||
sig: ty::PolyGenSig<'tcx>,
|
||||
) -> ty::Binder<'tcx, (ty::TraitRef<'tcx>, Ty<'tcx>)> {
|
||||
assert!(!self_ty.has_escaping_bound_vars());
|
||||
let trait_ref = tcx.mk_trait_ref(fn_trait_def_id, [self_ty]);
|
||||
let trait_ref = ty::TraitRef::new(tcx, fn_trait_def_id, [self_ty]);
|
||||
sig.map_bound(|sig| (trait_ref, sig.return_ty))
|
||||
}
|
||||
|
||||
|
@ -359,7 +359,7 @@ pub(crate) fn vtable_trait_upcasting_coercion_new_vptr_slot<'tcx>(
|
||||
// this has been typecked-before, so diagnostics is not really needed.
|
||||
let unsize_trait_did = tcx.require_lang_item(LangItem::Unsize, None);
|
||||
|
||||
let trait_ref = tcx.mk_trait_ref(unsize_trait_did, [source, target]);
|
||||
let trait_ref = ty::TraitRef::new(tcx, unsize_trait_did, [source, target]);
|
||||
|
||||
match tcx.codegen_select_candidate((ty::ParamEnv::reveal_all(), ty::Binder::dummy(trait_ref))) {
|
||||
Ok(ImplSource::TraitUpcasting(implsrc_traitcasting)) => {
|
||||
|
@ -463,7 +463,8 @@ fn compute_projection(&mut self, data: ty::AliasTy<'tcx>) {
|
||||
fn require_sized(&mut self, subty: Ty<'tcx>, cause: traits::ObligationCauseCode<'tcx>) {
|
||||
if !subty.has_escaping_bound_vars() {
|
||||
let cause = self.cause(cause);
|
||||
let trait_ref = self.tcx.at(cause.span).mk_trait_ref(LangItem::Sized, [subty]);
|
||||
let trait_ref =
|
||||
ty::TraitRef::from_lang_item(self.tcx, LangItem::Sized, cause.span, [subty]);
|
||||
self.out.push(traits::Obligation::with_depth(
|
||||
self.tcx,
|
||||
cause,
|
||||
|
@ -62,9 +62,8 @@ fn sized_constraint_for_ty<'tcx>(
|
||||
// it on the impl.
|
||||
|
||||
let Some(sized_trait) = tcx.lang_items().sized_trait() else { return vec![ty] };
|
||||
let sized_predicate = ty::Binder::dummy(tcx.mk_trait_ref(sized_trait, [ty]))
|
||||
.without_const()
|
||||
.to_predicate(tcx);
|
||||
let sized_predicate =
|
||||
ty::TraitRef::new(tcx, sized_trait, [ty]).without_const().to_predicate(tcx);
|
||||
let predicates = tcx.predicates_of(adtdef.did()).predicates;
|
||||
if predicates.iter().any(|(p, _)| *p == sized_predicate) { vec![] } else { vec![ty] }
|
||||
}
|
||||
|
@ -44,7 +44,7 @@ fn generate_for_trait(
|
||||
discard_positive_impl: bool,
|
||||
) -> Option<Item> {
|
||||
let tcx = self.cx.tcx;
|
||||
let trait_ref = ty::Binder::dummy(tcx.mk_trait_ref(trait_def_id, [ty]));
|
||||
let trait_ref = ty::Binder::dummy(ty::TraitRef::new(tcx, trait_def_id, [ty]));
|
||||
if !self.cx.generated_synthetics.insert((ty, trait_def_id)) {
|
||||
debug!("get_auto_trait_impl_for({:?}): already generated, aborting", trait_ref);
|
||||
return None;
|
||||
|
@ -131,7 +131,7 @@ fn clean_generic_bound<'tcx>(
|
||||
hir::GenericBound::LangItemTrait(lang_item, span, _, generic_args) => {
|
||||
let def_id = cx.tcx.require_lang_item(lang_item, Some(span));
|
||||
|
||||
let trait_ref = ty::TraitRef::identity(cx.tcx, def_id);
|
||||
let trait_ref = ty::Binder::dummy(ty::TraitRef::identity(cx.tcx, def_id));
|
||||
|
||||
let generic_args = clean_generic_args(generic_args, cx);
|
||||
let GenericArgs::AngleBracketed { bindings, .. } = generic_args
|
||||
|
@ -517,7 +517,7 @@ fn param_env_for_derived_eq(tcx: TyCtxt<'_>, did: DefId, eq_trait_id: DefId) ->
|
||||
tcx.mk_predicates_from_iter(ty_predicates.iter().map(|&(p, _)| p).chain(
|
||||
params.iter().filter(|&&(_, needs_eq)| needs_eq).map(|&(param, _)| {
|
||||
tcx.mk_predicate(Binder::dummy(PredicateKind::Clause(Clause::Trait(TraitPredicate {
|
||||
trait_ref: tcx.mk_trait_ref(eq_trait_id, [tcx.mk_param_from_def(param)]),
|
||||
trait_ref: ty::TraitRef::new(tcx, eq_trait_id, [tcx.mk_param_from_def(param)]),
|
||||
constness: BoundConstness::NotConst,
|
||||
polarity: ImplPolarity::Positive,
|
||||
}))))
|
||||
|
@ -94,8 +94,7 @@ fn check_fn(
|
||||
if trait_item.kind == (AssocItemKind::Fn { has_self: true }) {
|
||||
trait_self_ty = Some(
|
||||
TraitRef::identity(cx.tcx, trait_item.id.owner_id.to_def_id())
|
||||
.self_ty()
|
||||
.skip_binder(),
|
||||
.self_ty(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -3476,8 +3476,7 @@ fn check_trait_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx TraitItem<'_>
|
||||
let first_arg_span = first_arg_ty.span;
|
||||
let first_arg_ty = hir_ty_to_ty(cx.tcx, first_arg_ty);
|
||||
let self_ty = TraitRef::identity(cx.tcx, item.owner_id.to_def_id())
|
||||
.self_ty()
|
||||
.skip_binder();
|
||||
.self_ty();
|
||||
wrong_self_convention::check(
|
||||
cx,
|
||||
item.ident.name.as_str(),
|
||||
@ -3495,8 +3494,7 @@ fn check_trait_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx TraitItem<'_>
|
||||
if let TraitItemKind::Fn(_, _) = item.kind;
|
||||
let ret_ty = return_ty(cx, item.owner_id);
|
||||
let self_ty = TraitRef::identity(cx.tcx, item.owner_id.to_def_id())
|
||||
.self_ty()
|
||||
.skip_binder();
|
||||
.self_ty();
|
||||
if !ret_ty.contains(self_ty);
|
||||
|
||||
then {
|
||||
|
Loading…
Reference in New Issue
Block a user