Switch ty::TraitRef::from_lang_item from using TyCtxtAt to TyCtxt and a Span

This commit is contained in:
Maybe Waffle 2023-04-26 10:55:11 +00:00
parent 071f737a57
commit 4f2532fb53
10 changed files with 33 additions and 24 deletions

View File

@ -539,7 +539,7 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> {
if let PlaceContext::NonMutatingUse(NonMutatingUseContext::Copy) = context {
let tcx = self.tcx();
let trait_ref =
ty::TraitRef::from_lang_item(tcx.at(self.last_span), LangItem::Copy, [place_ty.ty]);
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`,
@ -1239,8 +1239,9 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
self.check_rvalue(body, rv, location);
if !self.unsized_feature_enabled() {
let trait_ref = ty::TraitRef::from_lang_item(
tcx.at(self.last_span),
tcx,
LangItem::Sized,
self.last_span,
[place_ty],
);
self.prove_trait_ref(
@ -1815,7 +1816,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
// Make sure that repeated elements implement `Copy`.
let ty = place.ty(body, tcx).ty;
let trait_ref =
ty::TraitRef::from_lang_item(tcx.at(span), LangItem::Copy, [ty]);
ty::TraitRef::from_lang_item(tcx, LangItem::Copy, span, [ty]);
self.prove_trait_ref(
trait_ref,
@ -1828,7 +1829,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
}
&Rvalue::NullaryOp(NullOp::SizeOf | NullOp::AlignOf, ty) => {
let trait_ref = ty::TraitRef::from_lang_item(tcx.at(span), LangItem::Sized, [ty]);
let trait_ref = ty::TraitRef::from_lang_item(tcx, LangItem::Sized, span, [ty]);
self.prove_trait_ref(
trait_ref,
@ -1840,7 +1841,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
Rvalue::ShallowInitBox(operand, ty) => {
self.check_operand(operand, location);
let trait_ref = ty::TraitRef::from_lang_item(tcx.at(span), LangItem::Sized, [*ty]);
let trait_ref = ty::TraitRef::from_lang_item(tcx, LangItem::Sized, span, [*ty]);
self.prove_trait_ref(
trait_ref,
@ -1938,8 +1939,9 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
CastKind::Pointer(PointerCast::Unsize) => {
let &ty = ty;
let trait_ref = ty::TraitRef::from_lang_item(
tcx.at(span),
tcx,
LangItem::CoerceUnsized,
span,
[op.ty(body, tcx), ty],
);

View File

@ -158,8 +158,9 @@ impl Qualif for NeedsNonConstDrop {
ObligationCause::dummy_with_span(cx.body.span),
cx.param_env,
ty::Binder::dummy(ty::TraitRef::from_lang_item(
cx.tcx.at(cx.body.span),
cx.tcx,
LangItem::Destruct,
cx.body.span,
[ty],
))
.with_constness(ty::BoundConstness::ConstIfConst),

View File

@ -765,8 +765,9 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
self.cause.clone(),
self.param_env,
ty::TraitRef::from_lang_item(
self.tcx.at(self.cause.span),
self.tcx,
hir::LangItem::PointerLike,
self.cause.span,
[a],
),
));

View File

@ -3,7 +3,6 @@
#![allow(rustc::usage_of_ty_tykind)]
use crate::infer::canonical::Canonical;
use crate::ty::query::TyCtxtAt;
use crate::ty::subst::{GenericArg, InternalSubsts, SubstsRef};
use crate::ty::visit::ValidateBoundVars;
use crate::ty::InferTy::*;
@ -836,12 +835,13 @@ impl<'tcx> TraitRef<'tcx> {
}
pub fn from_lang_item(
tcx: TyCtxtAt<'tcx>,
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(tcx.span));
Self::new(tcx.tcx, trait_def_id, substs)
let trait_def_id = tcx.require_lang_item(trait_lang_item, Some(span));
Self::new(tcx, trait_def_id, substs)
}
pub fn from_method(

View File

@ -31,8 +31,9 @@ fn custom_coerce_unsize_info<'tcx>(
target_ty: Ty<'tcx>,
) -> CustomCoerceUnsized {
let trait_ref = ty::Binder::dummy(ty::TraitRef::from_lang_item(
tcx,
tcx.tcx,
LangItem::CoerceUnsized,
tcx.span,
[source_ty, target_ty],
));

View File

@ -275,7 +275,7 @@ impl<'tcx> assembly::GoalKind<'tcx> for ProjectionPredicate<'tcx> {
}
};
let output_is_sized_pred = tupled_inputs_and_output.map_bound(|(_, output)| {
ty::TraitRef::from_lang_item(tcx.at(DUMMY_SP), LangItem::Sized, [output])
ty::TraitRef::from_lang_item(tcx, LangItem::Sized, DUMMY_SP, [output])
});
let pred = tupled_inputs_and_output
@ -335,8 +335,9 @@ impl<'tcx> assembly::GoalKind<'tcx> for ProjectionPredicate<'tcx> {
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::TraitRef::from_lang_item(
tcx.at(DUMMY_SP),
tcx,
LangItem::Sized,
DUMMY_SP,
[ty::GenericArg::from(goal.predicate.self_ty())],
);
ecx.add_goal(goal.with(tcx, sized_predicate));

View File

@ -243,7 +243,7 @@ impl<'tcx> assembly::GoalKind<'tcx> for TraitPredicate<'tcx> {
}
};
let output_is_sized_pred = tupled_inputs_and_output.map_bound(|(_, output)| {
ty::TraitRef::from_lang_item(tcx.at(DUMMY_SP), LangItem::Sized, [output])
ty::TraitRef::from_lang_item(tcx, LangItem::Sized, DUMMY_SP, [output])
});
let pred = tupled_inputs_and_output

View File

@ -1683,7 +1683,7 @@ fn assemble_candidates_from_impls<'cx, 'tcx>(
&obligation.with(
selcx.tcx(),
ty::Binder::dummy(
ty::TraitRef::from_lang_item(selcx.tcx().at(obligation.cause.span()), LangItem::Sized, [self_ty]),
ty::TraitRef::from_lang_item(selcx.tcx(), LangItem::Sized, obligation.cause.span(),[self_ty]),
)
.without_const(),
),
@ -1949,8 +1949,9 @@ fn confirm_builtin_candidate<'cx, 'tcx>(
});
if check_is_sized {
let sized_predicate = ty::Binder::dummy(ty::TraitRef::from_lang_item(
tcx.at(obligation.cause.span()),
tcx,
LangItem::Sized,
obligation.cause.span(),
[self_ty],
))
.without_const();

View File

@ -646,8 +646,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
output_ty,
&mut nested,
);
let tr =
ty::TraitRef::from_lang_item(self.tcx().at(cause.span), 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 })
@ -1051,8 +1050,9 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
// We can only make objects from sized types.
let tr = ty::Binder::dummy(ty::TraitRef::from_lang_item(
tcx.at(cause.span),
tcx,
LangItem::Sized,
cause.span,
[source],
));
nested.push(predicate_to_obligation(tr.without_const().to_predicate(tcx)));
@ -1281,8 +1281,9 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
obligation.recursion_depth + 1,
self_ty.rebind(ty::TraitPredicate {
trait_ref: ty::TraitRef::from_lang_item(
self.tcx().at(cause.span),
self.tcx(),
LangItem::Destruct,
cause.span,
[nested_ty],
),
constness: ty::BoundConstness::ConstIfConst,
@ -1306,8 +1307,9 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
_ => {
let predicate = self_ty.rebind(ty::TraitPredicate {
trait_ref: ty::TraitRef::from_lang_item(
self.tcx().at(cause.span),
self.tcx(),
LangItem::Destruct,
cause.span,
[nested_ty],
),
constness: ty::BoundConstness::ConstIfConst,

View File

@ -449,7 +449,7 @@ impl<'tcx> WfPredicates<'tcx> {
if !subty.has_escaping_bound_vars() {
let cause = self.cause(cause);
let trait_ref =
ty::TraitRef::from_lang_item(self.tcx.at(cause.span), LangItem::Sized, [subty]);
ty::TraitRef::from_lang_item(self.tcx, LangItem::Sized, cause.span, [subty]);
self.out.push(traits::Obligation::with_depth(
self.tcx,
cause,