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:
Oli Scherer 2022-11-17 11:21:39 +00:00
parent d9a02b0fb7
commit 6f77c97b38
27 changed files with 153 additions and 144 deletions

View File

@ -547,10 +547,11 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> {
if let PlaceContext::NonMutatingUse(NonMutatingUseContext::Copy) = context {
let tcx = self.tcx();
let trait_ref = ty::TraitRef {
def_id: tcx.require_lang_item(LangItem::Copy, Some(self.last_span)),
substs: tcx.mk_substs_trait(place_ty.ty, &[]),
};
let trait_ref = tcx.mk_trait_ref(
tcx.require_lang_item(LangItem::Copy, Some(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`,
@ -1273,10 +1274,11 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
self.check_rvalue(body, rv, location);
if !self.unsized_feature_enabled() {
let trait_ref = ty::TraitRef {
def_id: tcx.require_lang_item(LangItem::Sized, Some(self.last_span)),
substs: tcx.mk_substs_trait(place_ty, &[]),
};
let trait_ref = tcx.mk_trait_ref(
tcx.require_lang_item(LangItem::Sized, Some(self.last_span)),
place_ty,
&[],
);
self.prove_trait_ref(
trait_ref,
location.to_locations(),
@ -1865,9 +1867,10 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
// Make sure that repeated elements implement `Copy`.
let span = body.source_info(location).span;
let ty = place.ty(body, tcx).ty;
let trait_ref = ty::TraitRef::new(
let trait_ref = tcx.mk_trait_ref(
tcx.require_lang_item(LangItem::Copy, Some(span)),
tcx.mk_substs_trait(ty, &[]),
ty,
&[],
);
self.prove_trait_ref(
@ -1881,10 +1884,11 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
}
&Rvalue::NullaryOp(NullOp::SizeOf | NullOp::AlignOf, ty) => {
let trait_ref = ty::TraitRef {
def_id: tcx.require_lang_item(LangItem::Sized, Some(self.last_span)),
substs: tcx.mk_substs_trait(ty, &[]),
};
let trait_ref = tcx.mk_trait_ref(
tcx.require_lang_item(LangItem::Sized, Some(self.last_span)),
ty,
&[],
);
self.prove_trait_ref(
trait_ref,
@ -1896,10 +1900,11 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
Rvalue::ShallowInitBox(operand, ty) => {
self.check_operand(operand, location);
let trait_ref = ty::TraitRef {
def_id: tcx.require_lang_item(LangItem::Sized, Some(self.last_span)),
substs: tcx.mk_substs_trait(*ty, &[]),
};
let trait_ref = tcx.mk_trait_ref(
tcx.require_lang_item(LangItem::Sized, Some(self.last_span)),
*ty,
&[],
);
self.prove_trait_ref(
trait_ref,
@ -1996,11 +2001,11 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
CastKind::Pointer(PointerCast::Unsize) => {
let &ty = ty;
let trait_ref = ty::TraitRef {
def_id: tcx
.require_lang_item(LangItem::CoerceUnsized, Some(self.last_span)),
substs: tcx.mk_substs_trait(op.ty(body, tcx), &[ty.into()]),
};
let trait_ref = tcx.mk_trait_ref(
tcx.require_lang_item(LangItem::CoerceUnsized, Some(self.last_span)),
op.ty(body, tcx),
&[ty.into()],
);
self.prove_trait_ref(
trait_ref,

View File

@ -160,10 +160,7 @@ impl Qualif for NeedsNonConstDrop {
ObligationCause::dummy(),
cx.param_env,
ty::Binder::dummy(ty::TraitPredicate {
trait_ref: ty::TraitRef {
def_id: destruct,
substs: cx.tcx.mk_substs_trait(ty, &[]),
},
trait_ref: cx.tcx.mk_trait_ref(destruct, ty, &[]),
constness: ty::BoundConstness::ConstIfConst,
polarity: ty::ImplPolarity::Positive,
}),

View File

@ -61,10 +61,7 @@ impl<'tcx> Bounds<'tcx> {
// If it could be sized, and is, add the `Sized` predicate.
let sized_predicate = self.implicitly_sized.and_then(|span| {
tcx.lang_items().sized_trait().map(move |sized| {
let trait_ref = ty::Binder::dummy(ty::TraitRef {
def_id: sized,
substs: tcx.mk_substs_trait(param_ty, &[]),
});
let trait_ref = ty::Binder::dummy(tcx.mk_trait_ref(sized, param_ty, &[]));
(trait_ref.without_const().to_predicate(tcx), span)
})
});

View File

@ -1782,10 +1782,7 @@ fn receiver_is_implemented<'tcx>(
receiver_ty: Ty<'tcx>,
) -> bool {
let tcx = wfcx.tcx();
let trait_ref = ty::Binder::dummy(ty::TraitRef {
def_id: receiver_trait_def_id,
substs: tcx.mk_substs_trait(receiver_ty, &[]),
});
let trait_ref = ty::Binder::dummy(tcx.mk_trait_ref(receiver_trait_def_id, receiver_ty, &[]));
let obligation = traits::Obligation::new(tcx, cause, wfcx.param_env, trait_ref.without_const());

View File

@ -1093,10 +1093,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
self.tcx,
self.misc(expr.span),
self.param_env,
ty::Binder::dummy(ty::TraitRef {
def_id: into_def_id,
substs: self.tcx.mk_substs_trait(expr_ty, &[expected_ty.into()]),
})
ty::Binder::dummy(self.tcx.mk_trait_ref(
into_def_id,
expr_ty, &[expected_ty.into()]
))
.to_poly_trait_predicate(),
))
{

View File

@ -68,7 +68,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
self.autoderef(span, ty).any(|(ty, _)| {
info!("check deref {:?} impl FnOnce", ty);
self.probe(|_| {
let fn_once_substs = tcx.mk_substs_trait(
let trait_ref = tcx.mk_trait_ref(
fn_once,
ty,
&[self
.next_ty_var(TypeVariableOrigin {
@ -77,7 +78,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
})
.into()],
);
let trait_ref = ty::TraitRef::new(fn_once, fn_once_substs);
let poly_trait_ref = ty::Binder::dummy(trait_ref);
let obligation = Obligation::misc(
tcx,

View File

@ -27,7 +27,7 @@ pub trait TraitEngine<'tcx>: 'tcx {
def_id: DefId,
cause: ObligationCause<'tcx>,
) {
let trait_ref = ty::TraitRef { def_id, substs: infcx.tcx.mk_substs_trait(ty, &[]) };
let trait_ref = infcx.tcx.mk_trait_ref(def_id, ty, &[]);
self.register_predicate_obligation(
infcx,
Obligation {

View File

@ -2532,6 +2532,11 @@ impl<'tcx> TyCtxt<'tcx> {
#[inline]
pub fn mk_fn_def(self, def_id: DefId, substs: SubstsRef<'tcx>) -> Ty<'tcx> {
debug_assert_eq!(
self.generics_of(def_id).count(),
substs.len(),
"wrong number of generic parameters for {def_id:?}: {substs:?}",
);
self.mk_ty(FnDef(def_id, substs))
}
@ -2552,6 +2557,11 @@ impl<'tcx> TyCtxt<'tcx> {
#[inline]
pub fn mk_projection(self, item_def_id: DefId, substs: SubstsRef<'tcx>) -> Ty<'tcx> {
debug_assert_eq!(
self.generics_of(item_def_id).count(),
substs.len(),
"wrong number of generic parameters for {item_def_id:?}: {substs:?}",
);
self.mk_ty(Projection(ProjectionTy { item_def_id, substs }))
}
@ -2803,6 +2813,21 @@ impl<'tcx> TyCtxt<'tcx> {
self.mk_substs(iter::once(self_ty.into()).chain(rest.iter().cloned()))
}
pub fn mk_trait_ref(
self,
trait_def_id: DefId,
self_ty: Ty<'tcx>,
rest: &[GenericArg<'tcx>],
) -> ty::TraitRef<'tcx> {
debug_assert_eq!(
self.generics_of(trait_def_id).count() - 1,
rest.len(),
"wrong number of generic parameters for {trait_def_id:?} on self type {self_ty:?}: {rest:?} \nDid you accidentally include the self-type in the params list?"
);
let substs = self.mk_substs_trait(self_ty, rest);
ty::TraitRef::new(trait_def_id, substs)
}
pub fn mk_bound_variable_kinds<
I: InternAs<[ty::BoundVariableKind], &'tcx List<ty::BoundVariableKind>>,
>(

View File

@ -719,10 +719,7 @@ impl<'tcx> PolyExistentialPredicate<'tcx> {
self.rebind(p.with_self_ty(tcx, self_ty)).to_predicate(tcx)
}
ExistentialPredicate::AutoTrait(did) => {
let trait_ref = self.rebind(ty::TraitRef {
def_id: did,
substs: tcx.mk_substs_trait(self_ty, &[]),
});
let trait_ref = self.rebind(tcx.mk_trait_ref(did, self_ty, &[]));
trait_ref.without_const().to_predicate(tcx)
}
}
@ -909,7 +906,7 @@ impl<'tcx> ExistentialTraitRef<'tcx> {
// otherwise the escaping vars would be captured by the binder
// debug_assert!(!self_ty.has_escaping_bound_vars());
ty::TraitRef { def_id: self.def_id, substs: tcx.mk_substs_trait(self_ty, self.substs) }
tcx.mk_trait_ref(self.def_id, self_ty, self.substs)
}
}

View File

@ -1,6 +1,7 @@
use rustc_errors::DelayDm;
use rustc_hir as hir;
use rustc_index::vec::Idx;
use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
use rustc_infer::infer::{InferCtxt, TyCtxtInferExt};
use rustc_middle::mir::{self, Field};
use rustc_middle::thir::{FieldPat, Pat, PatKind};
@ -226,6 +227,13 @@ impl<'tcx> ConstToPat<'tcx> {
// using `PartialEq::eq` in this scenario in the past.)
let partial_eq_trait_id =
self.tcx().require_lang_item(hir::LangItem::PartialEq, Some(self.span));
let any_ty = self
.infcx
.next_ty_var(TypeVariableOrigin {
kind: TypeVariableOriginKind::MiscVariable,
span: self.span,
})
.into();
let obligation: PredicateObligation<'_> = predicate_for_trait_def(
self.tcx(),
self.param_env,
@ -233,7 +241,7 @@ impl<'tcx> ConstToPat<'tcx> {
partial_eq_trait_id,
0,
ty,
&[],
&[any_ty],
);
// FIXME: should this call a `predicate_must_hold` variant instead?

View File

@ -29,10 +29,7 @@ fn custom_coerce_unsize_info<'tcx>(
) -> CustomCoerceUnsized {
let def_id = tcx.require_lang_item(LangItem::CoerceUnsized, None);
let trait_ref = ty::Binder::dummy(ty::TraitRef {
def_id,
substs: tcx.mk_substs_trait(source_ty, &[target_ty.into()]),
});
let trait_ref = ty::Binder::dummy(tcx.mk_trait_ref(def_id, source_ty, &[target_ty.into()]));
match tcx.codegen_select_candidate((ty::ParamEnv::reveal_all(), trait_ref)) {
Ok(traits::ImplSource::UserDefined(traits::ImplSourceUserDefinedData {

View File

@ -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);

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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
});

View File

@ -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(

View File

@ -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)) => {

View File

@ -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)

View File

@ -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));

View File

@ -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.

View File

@ -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,

View File

@ -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,
});

View File

@ -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))
}

View File

@ -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,

View File

@ -49,12 +49,9 @@ 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(ty::TraitRef {
def_id: sized_trait,
substs: tcx.mk_substs_trait(ty, &[]),
})
.without_const()
.to_predicate(tcx);
let sized_predicate = ty::Binder::dummy(tcx.mk_trait_ref(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] }
}

View File

@ -44,7 +44,7 @@ where
discard_positive_impl: bool,
) -> Option<Item> {
let tcx = self.cx.tcx;
let trait_ref = ty::TraitRef { def_id: trait_def_id, substs: tcx.mk_substs_trait(ty, &[]) };
let trait_ref = tcx.mk_trait_ref(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;