1
Fork 0

Add helper to create the trait ref for a lang item

This commit is contained in:
Oli Scherer 2022-11-17 14:39:19 +00:00
parent 25c4760b5d
commit ad57f88d3f
10 changed files with 51 additions and 66 deletions

View file

@ -1710,8 +1710,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().mk_trait_ref(
selcx.tcx().require_lang_item(LangItem::Sized, None),
ty::Binder::dummy(selcx.tcx().at(obligation.cause.span).mk_trait_ref(
LangItem::Sized,
self_ty, [],
))
.without_const(),
@ -1966,8 +1966,8 @@ fn confirm_pointee_candidate<'cx, 'tcx>(
)
});
if check_is_sized {
let sized_predicate = ty::Binder::dummy(tcx.mk_trait_ref(
tcx.require_lang_item(LangItem::Sized, None),
let sized_predicate = ty::Binder::dummy(tcx.at(obligation.cause.span).mk_trait_ref(
LangItem::Sized,
self_ty,
[],
))
@ -1976,7 +1976,7 @@ fn confirm_pointee_candidate<'cx, 'tcx>(
}
let substs = tcx.mk_substs([self_ty.into()].iter());
let metadata_def_id = tcx.require_lang_item(LangItem::Metadata, None);
let metadata_def_id = tcx.require_lang_item(LangItem::Metadata, Some(obligation.cause.span));
let predicate = ty::ProjectionPredicate {
projection_ty: ty::ProjectionTy { substs, item_def_id: metadata_def_id },

View file

@ -632,8 +632,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
output_ty,
&mut nested,
);
let tr = ty::Binder::dummy(self.tcx().mk_trait_ref(
self.tcx().require_lang_item(LangItem::Sized, None),
let tr = ty::Binder::dummy(self.tcx().at(cause.span).mk_trait_ref(
LangItem::Sized,
output_ty,
[],
));
@ -997,11 +997,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
);
// We can only make objects from sized types.
let tr = ty::Binder::dummy(tcx.mk_trait_ref(
tcx.require_lang_item(LangItem::Sized, None),
source,
[],
));
let tr =
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
@ -1255,8 +1252,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
cause.clone(),
obligation.recursion_depth + 1,
self_ty.rebind(ty::TraitPredicate {
trait_ref: self.tcx().mk_trait_ref(
self.tcx().require_lang_item(LangItem::Destruct, None),
trait_ref: self.tcx().at(cause.span).mk_trait_ref(
LangItem::Destruct,
nested_ty,
[],
),
@ -1280,8 +1277,8 @@ 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().mk_trait_ref(
self.tcx().require_lang_item(LangItem::Destruct, None),
trait_ref: self.tcx().at(cause.span).mk_trait_ref(
LangItem::Destruct,
nested_ty,
[],
),

View file

@ -421,8 +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.mk_trait_ref(self.tcx.require_lang_item(LangItem::Sized, None), 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,