Stop passing the self-type as a separate argument.
This commit is contained in:
parent
a4da3f8863
commit
7658e0fccf
38 changed files with 113 additions and 164 deletions
|
@ -122,7 +122,7 @@ impl<'a, 'tcx> Autoderef<'a, '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 = tcx.mk_trait_ref(tcx.lang_items().deref_trait()?, [ty]);
|
||||
|
||||
let cause = traits::ObligationCause::misc(self.span, self.body_id);
|
||||
|
||||
|
|
|
@ -7,9 +7,8 @@ use rustc_infer::traits::ObligationCause;
|
|||
use rustc_middle::arena::ArenaAllocatable;
|
||||
use rustc_middle::infer::canonical::{Canonical, CanonicalizedQueryResponse, QueryResponse};
|
||||
use rustc_middle::traits::query::Fallible;
|
||||
use rustc_middle::ty::subst::SubstsRef;
|
||||
use rustc_middle::ty::ToPredicate;
|
||||
use rustc_middle::ty::{self, Ty, TypeFoldable, TypeVisitable};
|
||||
use rustc_middle::ty::{GenericArg, ToPredicate};
|
||||
use rustc_span::{Span, DUMMY_SP};
|
||||
|
||||
use std::fmt::Debug;
|
||||
|
@ -44,8 +43,7 @@ pub trait InferCtxtExt<'tcx> {
|
|||
/// The inputs are:
|
||||
///
|
||||
/// - the def-id of the trait
|
||||
/// - the self type
|
||||
/// - the *other* type parameters of the trait, excluding the self-type
|
||||
/// - the type parameters of the trait, including the self-type
|
||||
/// - the parameter environment
|
||||
///
|
||||
/// Invokes `evaluate_obligation`, so in the event that evaluating
|
||||
|
@ -54,8 +52,7 @@ pub trait InferCtxtExt<'tcx> {
|
|||
fn type_implements_trait(
|
||||
&self,
|
||||
trait_def_id: DefId,
|
||||
ty: Ty<'tcx>,
|
||||
params: SubstsRef<'tcx>,
|
||||
params: impl IntoIterator<Item = impl Into<GenericArg<'tcx>>>,
|
||||
param_env: ty::ParamEnv<'tcx>,
|
||||
) -> traits::EvaluationResult;
|
||||
}
|
||||
|
@ -109,15 +106,14 @@ impl<'tcx> InferCtxtExt<'tcx> for InferCtxt<'tcx> {
|
|||
InferOk { value, obligations }
|
||||
}
|
||||
|
||||
#[instrument(level = "debug", skip(self), ret)]
|
||||
#[instrument(level = "debug", skip(self, params), ret)]
|
||||
fn type_implements_trait(
|
||||
&self,
|
||||
trait_def_id: DefId,
|
||||
self_ty: Ty<'tcx>,
|
||||
params: SubstsRef<'tcx>,
|
||||
params: impl IntoIterator<Item = impl Into<GenericArg<'tcx>>>,
|
||||
param_env: ty::ParamEnv<'tcx>,
|
||||
) -> traits::EvaluationResult {
|
||||
let trait_ref = self.tcx.mk_trait_ref(trait_def_id, self_ty, params);
|
||||
let trait_ref = self.tcx.mk_trait_ref(trait_def_id, params);
|
||||
|
||||
let obligation = traits::Obligation {
|
||||
cause: traits::ObligationCause::dummy(),
|
||||
|
|
|
@ -86,7 +86,7 @@ impl<'tcx> AutoTraitFinder<'tcx> {
|
|||
) -> AutoTraitResult<A> {
|
||||
let tcx = self.tcx;
|
||||
|
||||
let trait_ref = tcx.mk_trait_ref(trait_did, ty, []);
|
||||
let trait_ref = tcx.mk_trait_ref(trait_did, [ty]);
|
||||
|
||||
let trait_pred = ty::Binder::dummy(trait_ref);
|
||||
|
||||
|
@ -260,7 +260,7 @@ impl<'tcx> AutoTraitFinder<'tcx> {
|
|||
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: infcx.tcx.mk_trait_ref(trait_did, [ty]),
|
||||
|
||||
constness: ty::BoundConstness::NotConst,
|
||||
// Auto traits are positive
|
||||
|
|
|
@ -93,7 +93,7 @@ impl<'a, 'tcx> ObligationCtxt<'a, 'tcx> {
|
|||
def_id: DefId,
|
||||
) {
|
||||
let tcx = self.infcx.tcx;
|
||||
let trait_ref = tcx.mk_trait_ref(def_id, ty, []);
|
||||
let trait_ref = tcx.mk_trait_ref(def_id, [ty]);
|
||||
self.register_obligation(Obligation {
|
||||
cause,
|
||||
recursion_depth: 0,
|
||||
|
|
|
@ -347,7 +347,7 @@ impl<'tcx> InferCtxtExt<'tcx> for InferCtxt<'tcx> {
|
|||
span: DUMMY_SP,
|
||||
kind: TypeVariableOriginKind::MiscVariable,
|
||||
});
|
||||
let trait_ref = self.tcx.mk_trait_ref(trait_def_id, ty.skip_binder(), [var.into()]);
|
||||
let trait_ref = self.tcx.mk_trait_ref(trait_def_id, [ty.skip_binder(), var]);
|
||||
let obligation = Obligation::new(
|
||||
self.tcx,
|
||||
ObligationCause::dummy(),
|
||||
|
|
|
@ -2971,8 +2971,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
|||
let self_ty = self.resolve_vars_if_possible(trait_pred.self_ty());
|
||||
let impls_future = self.type_implements_trait(
|
||||
future_trait,
|
||||
self.tcx.erase_late_bound_regions(self_ty),
|
||||
ty::List::empty(),
|
||||
[self.tcx.erase_late_bound_regions(self_ty)],
|
||||
obligation.param_env,
|
||||
);
|
||||
if !impls_future.must_apply_modulo_regions() {
|
||||
|
@ -3070,15 +3069,14 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
|||
let field_ty = field.ty(self.tcx, substs);
|
||||
let trait_substs = match diagnostic_name {
|
||||
sym::PartialEq | sym::PartialOrd => {
|
||||
Some(field_ty.into())
|
||||
Some(field_ty)
|
||||
}
|
||||
_ => None,
|
||||
};
|
||||
let trait_pred = trait_pred.map_bound_ref(|tr| ty::TraitPredicate {
|
||||
trait_ref: self.tcx.mk_trait_ref(
|
||||
trait_pred.def_id(),
|
||||
field_ty,
|
||||
trait_substs,
|
||||
[field_ty].into_iter().chain(trait_substs),
|
||||
),
|
||||
..*tr
|
||||
});
|
||||
|
|
|
@ -143,7 +143,7 @@ pub fn type_known_to_meet_bound_modulo_regions<'tcx>(
|
|||
def_id: DefId,
|
||||
span: Span,
|
||||
) -> bool {
|
||||
let trait_ref = ty::Binder::dummy(infcx.tcx.mk_trait_ref(def_id, ty, []));
|
||||
let trait_ref = ty::Binder::dummy(infcx.tcx.mk_trait_ref(def_id, [ty]));
|
||||
pred_known_to_hold_modulo_regions(infcx, param_env, trait_ref.without_const(), span)
|
||||
}
|
||||
|
||||
|
@ -903,7 +903,7 @@ pub 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.into()]);
|
||||
let trait_ref = tcx.mk_trait_ref(unsize_trait_did, [source, target]);
|
||||
|
||||
match tcx.codegen_select_candidate((ty::ParamEnv::reveal_all(), ty::Binder::dummy(trait_ref))) {
|
||||
Ok(ImplSource::TraitUpcasting(implsrc_traitcasting)) => {
|
||||
|
|
|
@ -685,11 +685,9 @@ 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.into()],
|
||||
))
|
||||
let unsize_predicate = ty::Binder::dummy(
|
||||
tcx.mk_trait_ref(unsize_did, [tcx.types.self_param, unsized_self_ty]),
|
||||
)
|
||||
.without_const()
|
||||
.to_predicate(tcx);
|
||||
|
||||
|
@ -721,11 +719,9 @@ 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.into()],
|
||||
))
|
||||
let predicate = ty::Binder::dummy(
|
||||
tcx.mk_trait_ref(dispatch_from_dyn_did, [receiver_ty, unsized_receiver_ty]),
|
||||
)
|
||||
.without_const();
|
||||
|
||||
Obligation::new(tcx, ObligationCause::dummy(), param_env, predicate)
|
||||
|
|
|
@ -1712,7 +1712,7 @@ fn assemble_candidates_from_impls<'cx, 'tcx>(
|
|||
selcx.tcx(),
|
||||
ty::Binder::dummy(selcx.tcx().at(obligation.cause.span).mk_trait_ref(
|
||||
LangItem::Sized,
|
||||
self_ty, [],
|
||||
[self_ty],
|
||||
))
|
||||
.without_const(),
|
||||
),
|
||||
|
@ -1966,11 +1966,9 @@ fn confirm_pointee_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::Binder::dummy(
|
||||
tcx.at(obligation.cause.span).mk_trait_ref(LangItem::Sized, [self_ty]),
|
||||
)
|
||||
.without_const();
|
||||
obligations.push(obligation.with(tcx, sized_predicate));
|
||||
}
|
||||
|
|
|
@ -714,7 +714,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
|||
}
|
||||
|
||||
// <ty as Deref>
|
||||
let trait_ref = tcx.mk_trait_ref(tcx.lang_items().deref_trait()?, ty, []);
|
||||
let trait_ref = tcx.mk_trait_ref(tcx.lang_items().deref_trait()?, [ty]);
|
||||
|
||||
let obligation = traits::Obligation::new(
|
||||
tcx,
|
||||
|
|
|
@ -632,11 +632,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
|||
output_ty,
|
||||
&mut nested,
|
||||
);
|
||||
let tr = ty::Binder::dummy(self.tcx().at(cause.span).mk_trait_ref(
|
||||
LangItem::Sized,
|
||||
output_ty,
|
||||
[],
|
||||
));
|
||||
let tr =
|
||||
ty::Binder::dummy(self.tcx().at(cause.span).mk_trait_ref(LangItem::Sized, [output_ty]));
|
||||
nested.push(Obligation::new(
|
||||
self.infcx.tcx,
|
||||
cause,
|
||||
|
@ -998,7 +995,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
|||
|
||||
// We can only make objects from sized types.
|
||||
let tr =
|
||||
ty::Binder::dummy(tcx.at(cause.span).mk_trait_ref(LangItem::Sized, source, []));
|
||||
ty::Binder::dummy(tcx.at(cause.span).mk_trait_ref(LangItem::Sized, [source]));
|
||||
nested.push(predicate_to_obligation(tr.without_const().to_predicate(tcx)));
|
||||
|
||||
// If the type is `Foo + 'a`, ensure that the type
|
||||
|
@ -1104,8 +1101,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
|||
obligation.cause.clone(),
|
||||
obligation.predicate.def_id(),
|
||||
obligation.recursion_depth + 1,
|
||||
source_tail,
|
||||
[target_tail.into()],
|
||||
[source_tail, target_tail],
|
||||
));
|
||||
}
|
||||
|
||||
|
@ -1135,8 +1131,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
|||
obligation.cause.clone(),
|
||||
obligation.predicate.def_id(),
|
||||
obligation.recursion_depth + 1,
|
||||
a_last,
|
||||
[b_last.into()],
|
||||
[a_last, b_last],
|
||||
)
|
||||
}));
|
||||
}
|
||||
|
@ -1252,11 +1247,10 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
|||
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: self
|
||||
.tcx()
|
||||
.at(cause.span)
|
||||
.mk_trait_ref(LangItem::Destruct, [nested_ty]),
|
||||
constness: ty::BoundConstness::ConstIfConst,
|
||||
polarity: ty::ImplPolarity::Positive,
|
||||
}),
|
||||
|
@ -1277,11 +1271,10 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
|||
// 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: self
|
||||
.tcx()
|
||||
.at(cause.span)
|
||||
.mk_trait_ref(LangItem::Destruct, [nested_ty]),
|
||||
constness: ty::BoundConstness::ConstIfConst,
|
||||
polarity: ty::ImplPolarity::Positive,
|
||||
});
|
||||
|
|
|
@ -2100,8 +2100,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
|||
cause.clone(),
|
||||
trait_def_id,
|
||||
recursion_depth,
|
||||
normalized_ty,
|
||||
[],
|
||||
[normalized_ty],
|
||||
);
|
||||
obligations.push(placeholder_obligation);
|
||||
obligations
|
||||
|
|
|
@ -238,10 +238,9 @@ pub fn predicate_for_trait_def<'tcx>(
|
|||
cause: ObligationCause<'tcx>,
|
||||
trait_def_id: DefId,
|
||||
recursion_depth: usize,
|
||||
self_ty: Ty<'tcx>,
|
||||
params: impl IntoIterator<Item = GenericArg<'tcx>, IntoIter: ExactSizeIterator>,
|
||||
params: impl IntoIterator<Item = impl Into<GenericArg<'tcx>>>,
|
||||
) -> PredicateObligation<'tcx> {
|
||||
let trait_ref = tcx.mk_trait_ref(trait_def_id, self_ty, params);
|
||||
let trait_ref = tcx.mk_trait_ref(trait_def_id, params);
|
||||
predicate_for_trait_ref(tcx, cause, param_env, trait_ref, recursion_depth)
|
||||
}
|
||||
|
||||
|
@ -304,7 +303,7 @@ pub fn closure_trait_ref_and_return_type<'tcx>(
|
|||
TupleArgumentsFlag::Yes => tcx.intern_tup(sig.skip_binder().inputs()),
|
||||
};
|
||||
debug_assert!(!self_ty.has_escaping_bound_vars());
|
||||
let trait_ref = tcx.mk_trait_ref(fn_trait_def_id, self_ty, [arguments_tuple.into()]);
|
||||
let trait_ref = tcx.mk_trait_ref(fn_trait_def_id, [self_ty, arguments_tuple]);
|
||||
sig.map_bound(|sig| (trait_ref, sig.output()))
|
||||
}
|
||||
|
||||
|
@ -315,8 +314,7 @@ pub fn generator_trait_ref_and_outputs<'tcx>(
|
|||
sig: ty::PolyGenSig<'tcx>,
|
||||
) -> ty::Binder<'tcx, (ty::TraitRef<'tcx>, Ty<'tcx>, Ty<'tcx>)> {
|
||||
debug_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.into()]);
|
||||
let trait_ref = tcx.mk_trait_ref(fn_trait_def_id, [self_ty, sig.skip_binder().resume_ty]);
|
||||
sig.map_bound(|sig| (trait_ref, sig.yield_ty, sig.return_ty))
|
||||
}
|
||||
|
||||
|
|
|
@ -421,7 +421,7 @@ impl<'tcx> WfPredicates<'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 = self.tcx.at(cause.span).mk_trait_ref(LangItem::Sized, [subty]);
|
||||
self.out.push(traits::Obligation::with_depth(
|
||||
self.tcx,
|
||||
cause,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue