Assert that various types have the right amount of generic args and fix the sites that used the wrong amount
This commit is contained in:
parent
d9a02b0fb7
commit
6f77c97b38
27 changed files with 153 additions and 144 deletions
|
@ -4,7 +4,7 @@ use crate::traits::{self, TraitEngine, TraitEngineExt};
|
|||
use rustc_hir as hir;
|
||||
use rustc_infer::infer::InferCtxt;
|
||||
use rustc_middle::ty::TypeVisitable;
|
||||
use rustc_middle::ty::{self, TraitRef, Ty, TyCtxt};
|
||||
use rustc_middle::ty::{self, Ty, TyCtxt};
|
||||
use rustc_session::Limit;
|
||||
use rustc_span::def_id::LOCAL_CRATE;
|
||||
use rustc_span::Span;
|
||||
|
@ -122,10 +122,7 @@ impl<'a, 'tcx> Autoderef<'a, 'tcx> {
|
|||
let tcx = self.infcx.tcx;
|
||||
|
||||
// <ty as Deref>
|
||||
let trait_ref = TraitRef {
|
||||
def_id: tcx.lang_items().deref_trait()?,
|
||||
substs: tcx.mk_substs_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);
|
||||
|
||||
|
|
|
@ -117,10 +117,7 @@ impl<'tcx> InferCtxtExt<'tcx> for InferCtxt<'tcx> {
|
|||
params: SubstsRef<'tcx>,
|
||||
param_env: ty::ParamEnv<'tcx>,
|
||||
) -> traits::EvaluationResult {
|
||||
let trait_ref = ty::TraitRef {
|
||||
def_id: trait_def_id,
|
||||
substs: self.tcx.mk_substs_trait(self_ty, params),
|
||||
};
|
||||
let trait_ref = self.tcx.mk_trait_ref(trait_def_id, self_ty, params);
|
||||
|
||||
debug_assert_eq!(
|
||||
self.tcx.generics_of(trait_def_id).count() - 1,
|
||||
|
|
|
@ -86,7 +86,7 @@ impl<'tcx> AutoTraitFinder<'tcx> {
|
|||
) -> AutoTraitResult<A> {
|
||||
let tcx = self.tcx;
|
||||
|
||||
let trait_ref = ty::TraitRef { def_id: trait_did, substs: tcx.mk_substs_trait(ty, &[]) };
|
||||
let trait_ref = tcx.mk_trait_ref(trait_did, ty, &[]);
|
||||
|
||||
let trait_pred = ty::Binder::dummy(trait_ref);
|
||||
|
||||
|
@ -260,10 +260,8 @@ 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: ty::TraitRef {
|
||||
def_id: trait_did,
|
||||
substs: infcx.tcx.mk_substs_trait(ty, &[]),
|
||||
},
|
||||
trait_ref: infcx.tcx.mk_trait_ref(trait_did, ty, &[]),
|
||||
|
||||
constness: ty::BoundConstness::NotConst,
|
||||
// Auto traits are positive
|
||||
polarity: ty::ImplPolarity::Positive,
|
||||
|
|
|
@ -93,7 +93,7 @@ impl<'a, 'tcx> ObligationCtxt<'a, 'tcx> {
|
|||
def_id: DefId,
|
||||
) {
|
||||
let tcx = self.infcx.tcx;
|
||||
let trait_ref = ty::TraitRef { def_id, substs: tcx.mk_substs_trait(ty, &[]) };
|
||||
let trait_ref = tcx.mk_trait_ref(def_id, ty, &[]);
|
||||
self.register_obligation(Obligation {
|
||||
cause,
|
||||
recursion_depth: 0,
|
||||
|
|
|
@ -347,16 +347,13 @@ impl<'tcx> InferCtxtExt<'tcx> for InferCtxt<'tcx> {
|
|||
span: DUMMY_SP,
|
||||
kind: TypeVariableOriginKind::MiscVariable,
|
||||
});
|
||||
let substs = self.tcx.mk_substs_trait(ty.skip_binder(), &[var.into()]);
|
||||
let trait_ref =
|
||||
self.tcx.mk_trait_ref(trait_def_id, ty.skip_binder(), &[var.into()]);
|
||||
let obligation = Obligation::new(
|
||||
self.tcx,
|
||||
ObligationCause::dummy(),
|
||||
param_env,
|
||||
ty.rebind(ty::TraitPredicate {
|
||||
trait_ref: ty::TraitRef::new(trait_def_id, substs),
|
||||
constness,
|
||||
polarity,
|
||||
}),
|
||||
ty.rebind(ty::TraitPredicate { trait_ref, constness, polarity }),
|
||||
);
|
||||
let mut fulfill_cx = <dyn TraitEngine<'tcx>>::new_in_snapshot(self.tcx);
|
||||
fulfill_cx.register_predicate_obligation(self, obligation);
|
||||
|
@ -1002,7 +999,8 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
|||
&& self.fallback_has_occurred
|
||||
{
|
||||
let predicate = trait_predicate.map_bound(|mut trait_pred| {
|
||||
trait_pred.trait_ref.substs = self.tcx.mk_substs_trait(
|
||||
trait_pred.trait_ref = self.tcx.mk_trait_ref(
|
||||
trait_pred.trait_ref.def_id,
|
||||
self.tcx.mk_unit(),
|
||||
&trait_pred.trait_ref.substs[1..],
|
||||
);
|
||||
|
@ -2029,10 +2027,11 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
|||
trait_ref_and_ty: ty::Binder<'tcx, (ty::TraitPredicate<'tcx>, Ty<'tcx>)>,
|
||||
) -> PredicateObligation<'tcx> {
|
||||
let trait_pred = trait_ref_and_ty.map_bound_ref(|(tr, new_self_ty)| ty::TraitPredicate {
|
||||
trait_ref: ty::TraitRef {
|
||||
substs: self.tcx.mk_substs_trait(*new_self_ty, &tr.trait_ref.substs[1..]),
|
||||
..tr.trait_ref
|
||||
},
|
||||
trait_ref: self.tcx.mk_trait_ref(
|
||||
tr.trait_ref.def_id,
|
||||
*new_self_ty,
|
||||
&tr.trait_ref.substs[1..],
|
||||
),
|
||||
..*tr
|
||||
});
|
||||
|
||||
|
|
|
@ -3068,17 +3068,20 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
|||
// Ensure all fields impl the trait.
|
||||
adt.all_fields().all(|field| {
|
||||
let field_ty = field.ty(self.tcx, substs);
|
||||
let trait_substs = match diagnostic_name {
|
||||
let trait_substs;
|
||||
let trait_substs: &[_] = match diagnostic_name {
|
||||
sym::PartialEq | sym::PartialOrd => {
|
||||
self.tcx.mk_substs_trait(field_ty, &[field_ty.into()])
|
||||
trait_substs = [field_ty.into()];
|
||||
&trait_substs
|
||||
}
|
||||
_ => self.tcx.mk_substs_trait(field_ty, &[]),
|
||||
_ => &[],
|
||||
};
|
||||
let trait_pred = trait_pred.map_bound_ref(|tr| ty::TraitPredicate {
|
||||
trait_ref: ty::TraitRef {
|
||||
substs: trait_substs,
|
||||
..trait_pred.skip_binder().trait_ref
|
||||
},
|
||||
trait_ref: self.tcx.mk_trait_ref(
|
||||
trait_pred.def_id(),
|
||||
field_ty,
|
||||
trait_substs,
|
||||
),
|
||||
..*tr
|
||||
});
|
||||
let field_obl = Obligation::new(
|
||||
|
|
|
@ -143,8 +143,7 @@ pub fn type_known_to_meet_bound_modulo_regions<'tcx>(
|
|||
def_id: DefId,
|
||||
span: Span,
|
||||
) -> bool {
|
||||
let trait_ref =
|
||||
ty::Binder::dummy(ty::TraitRef { def_id, substs: infcx.tcx.mk_substs_trait(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,10 +902,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 = ty::TraitRef {
|
||||
def_id: unsize_trait_did,
|
||||
substs: tcx.mk_substs_trait(source, &[target.into()]),
|
||||
};
|
||||
let trait_ref = tcx.mk_trait_ref(unsize_trait_did, source, &[target.into()]);
|
||||
|
||||
match tcx.codegen_select_candidate((ty::ParamEnv::reveal_all(), ty::Binder::dummy(trait_ref))) {
|
||||
Ok(ImplSource::TraitUpcasting(implsrc_traitcasting)) => {
|
||||
|
|
|
@ -685,10 +685,11 @@ fn receiver_is_dispatchable<'tcx>(
|
|||
let param_env = tcx.param_env(method.def_id);
|
||||
|
||||
// Self: Unsize<U>
|
||||
let unsize_predicate = ty::Binder::dummy(ty::TraitRef {
|
||||
def_id: unsize_did,
|
||||
substs: tcx.mk_substs_trait(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.into()],
|
||||
))
|
||||
.without_const()
|
||||
.to_predicate(tcx);
|
||||
|
||||
|
@ -720,10 +721,11 @@ fn receiver_is_dispatchable<'tcx>(
|
|||
|
||||
// Receiver: DispatchFromDyn<Receiver[Self => U]>
|
||||
let obligation = {
|
||||
let predicate = ty::Binder::dummy(ty::TraitRef {
|
||||
def_id: dispatch_from_dyn_did,
|
||||
substs: tcx.mk_substs_trait(receiver_ty, &[unsized_receiver_ty.into()]),
|
||||
})
|
||||
let predicate = ty::Binder::dummy(tcx.mk_trait_ref(
|
||||
dispatch_from_dyn_did,
|
||||
receiver_ty,
|
||||
&[unsized_receiver_ty.into()],
|
||||
))
|
||||
.without_const();
|
||||
|
||||
Obligation::new(tcx, ObligationCause::dummy(), param_env, predicate)
|
||||
|
|
|
@ -1710,9 +1710,9 @@ fn assemble_candidates_from_impls<'cx, 'tcx>(
|
|||
if selcx.infcx().predicate_must_hold_modulo_regions(
|
||||
&obligation.with(
|
||||
selcx.tcx(),
|
||||
ty::Binder::dummy(ty::TraitRef::new(
|
||||
ty::Binder::dummy(selcx.tcx().mk_trait_ref(
|
||||
selcx.tcx().require_lang_item(LangItem::Sized, None),
|
||||
selcx.tcx().mk_substs_trait(self_ty, &[]),
|
||||
self_ty, &[],
|
||||
))
|
||||
.without_const(),
|
||||
),
|
||||
|
@ -1966,9 +1966,10 @@ fn confirm_pointee_candidate<'cx, 'tcx>(
|
|||
)
|
||||
});
|
||||
if check_is_sized {
|
||||
let sized_predicate = ty::Binder::dummy(ty::TraitRef::new(
|
||||
let sized_predicate = ty::Binder::dummy(tcx.mk_trait_ref(
|
||||
tcx.require_lang_item(LangItem::Sized, None),
|
||||
tcx.mk_substs_trait(self_ty, &[]),
|
||||
self_ty,
|
||||
&[],
|
||||
))
|
||||
.without_const();
|
||||
obligations.push(obligation.with(tcx, sized_predicate));
|
||||
|
|
|
@ -18,10 +18,10 @@ pub(crate) fn update<'tcx, T>(
|
|||
{
|
||||
let new_self_ty = infcx.tcx.types.unit;
|
||||
|
||||
let trait_ref = ty::TraitRef {
|
||||
substs: infcx.tcx.mk_substs_trait(new_self_ty, &tpred.trait_ref.substs[1..]),
|
||||
..tpred.trait_ref
|
||||
};
|
||||
let trait_ref = infcx.tcx.mk_trait_ref(
|
||||
tpred.trait_ref.def_id,
|
||||
new_self_ty, &tpred.trait_ref.substs[1..],
|
||||
);
|
||||
|
||||
// Then construct a new obligation with Self = () added
|
||||
// to the ParamEnv, and see if it holds.
|
||||
|
|
|
@ -714,10 +714,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
|||
}
|
||||
|
||||
// <ty as Deref>
|
||||
let trait_ref = ty::TraitRef {
|
||||
def_id: tcx.lang_items().deref_trait()?,
|
||||
substs: tcx.mk_substs_trait(ty, &[]),
|
||||
};
|
||||
let trait_ref = tcx.mk_trait_ref(tcx.lang_items().deref_trait()?, ty, &[]);
|
||||
|
||||
let obligation = traits::Obligation::new(
|
||||
tcx,
|
||||
|
|
|
@ -632,9 +632,10 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
|||
output_ty,
|
||||
&mut nested,
|
||||
);
|
||||
let tr = ty::Binder::dummy(ty::TraitRef::new(
|
||||
let tr = ty::Binder::dummy(self.tcx().mk_trait_ref(
|
||||
self.tcx().require_lang_item(LangItem::Sized, None),
|
||||
self.tcx().mk_substs_trait(output_ty, &[]),
|
||||
output_ty,
|
||||
&[],
|
||||
));
|
||||
nested.push(Obligation::new(
|
||||
self.infcx.tcx,
|
||||
|
@ -996,9 +997,10 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
|||
);
|
||||
|
||||
// We can only make objects from sized types.
|
||||
let tr = ty::Binder::dummy(ty::TraitRef::new(
|
||||
let tr = ty::Binder::dummy(tcx.mk_trait_ref(
|
||||
tcx.require_lang_item(LangItem::Sized, None),
|
||||
tcx.mk_substs_trait(source, &[]),
|
||||
source,
|
||||
&[],
|
||||
));
|
||||
nested.push(predicate_to_obligation(tr.without_const().to_predicate(tcx)));
|
||||
|
||||
|
@ -1253,10 +1255,11 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
|||
cause.clone(),
|
||||
obligation.recursion_depth + 1,
|
||||
self_ty.rebind(ty::TraitPredicate {
|
||||
trait_ref: ty::TraitRef {
|
||||
def_id: self.tcx().require_lang_item(LangItem::Destruct, None),
|
||||
substs: self.tcx().mk_substs_trait(nested_ty, &[]),
|
||||
},
|
||||
trait_ref: self.tcx().mk_trait_ref(
|
||||
self.tcx().require_lang_item(LangItem::Destruct, None),
|
||||
nested_ty,
|
||||
&[],
|
||||
),
|
||||
constness: ty::BoundConstness::ConstIfConst,
|
||||
polarity: ty::ImplPolarity::Positive,
|
||||
}),
|
||||
|
@ -1277,10 +1280,11 @@ 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: ty::TraitRef {
|
||||
def_id: self.tcx().require_lang_item(LangItem::Destruct, None),
|
||||
substs: self.tcx().mk_substs_trait(nested_ty, &[]),
|
||||
},
|
||||
trait_ref: self.tcx().mk_trait_ref(
|
||||
self.tcx().require_lang_item(LangItem::Destruct, None),
|
||||
nested_ty,
|
||||
&[],
|
||||
),
|
||||
constness: ty::BoundConstness::ConstIfConst,
|
||||
polarity: ty::ImplPolarity::Positive,
|
||||
});
|
||||
|
|
|
@ -241,8 +241,7 @@ pub fn predicate_for_trait_def<'tcx>(
|
|||
self_ty: Ty<'tcx>,
|
||||
params: &[GenericArg<'tcx>],
|
||||
) -> PredicateObligation<'tcx> {
|
||||
let trait_ref =
|
||||
ty::TraitRef { def_id: trait_def_id, substs: tcx.mk_substs_trait(self_ty, params) };
|
||||
let trait_ref = tcx.mk_trait_ref(trait_def_id, self_ty, params);
|
||||
predicate_for_trait_ref(tcx, cause, param_env, trait_ref, recursion_depth)
|
||||
}
|
||||
|
||||
|
@ -305,10 +304,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 = ty::TraitRef {
|
||||
def_id: fn_trait_def_id,
|
||||
substs: tcx.mk_substs_trait(self_ty, &[arguments_tuple.into()]),
|
||||
};
|
||||
let trait_ref = tcx.mk_trait_ref(fn_trait_def_id, self_ty, &[arguments_tuple.into()]);
|
||||
sig.map_bound(|sig| (trait_ref, sig.output()))
|
||||
}
|
||||
|
||||
|
@ -319,10 +315,8 @@ 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 = ty::TraitRef {
|
||||
def_id: fn_trait_def_id,
|
||||
substs: tcx.mk_substs_trait(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.into()]);
|
||||
sig.map_bound(|sig| (trait_ref, sig.yield_ty, sig.return_ty))
|
||||
}
|
||||
|
||||
|
|
|
@ -421,10 +421,11 @@ 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 = ty::TraitRef {
|
||||
def_id: self.tcx.require_lang_item(LangItem::Sized, None),
|
||||
substs: self.tcx.mk_substs_trait(subty, &[]),
|
||||
};
|
||||
let trait_ref = self.tcx.mk_trait_ref(
|
||||
self.tcx.require_lang_item(LangItem::Sized, None),
|
||||
subty,
|
||||
&[],
|
||||
);
|
||||
self.out.push(traits::Obligation::with_depth(
|
||||
self.tcx,
|
||||
cause,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue