Switch ty::TraitRef::from_lang_item
from using TyCtxtAt
to TyCtxt
and a Span
This commit is contained in:
parent
071f737a57
commit
4f2532fb53
@ -539,7 +539,7 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> {
|
|||||||
if let PlaceContext::NonMutatingUse(NonMutatingUseContext::Copy) = context {
|
if let PlaceContext::NonMutatingUse(NonMutatingUseContext::Copy) = context {
|
||||||
let tcx = self.tcx();
|
let tcx = self.tcx();
|
||||||
let trait_ref =
|
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
|
// To have a `Copy` operand, the type `T` of the
|
||||||
// value must be `Copy`. Note that we prove that `T: Copy`,
|
// 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);
|
self.check_rvalue(body, rv, location);
|
||||||
if !self.unsized_feature_enabled() {
|
if !self.unsized_feature_enabled() {
|
||||||
let trait_ref = ty::TraitRef::from_lang_item(
|
let trait_ref = ty::TraitRef::from_lang_item(
|
||||||
tcx.at(self.last_span),
|
tcx,
|
||||||
LangItem::Sized,
|
LangItem::Sized,
|
||||||
|
self.last_span,
|
||||||
[place_ty],
|
[place_ty],
|
||||||
);
|
);
|
||||||
self.prove_trait_ref(
|
self.prove_trait_ref(
|
||||||
@ -1815,7 +1816,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
|||||||
// Make sure that repeated elements implement `Copy`.
|
// Make sure that repeated elements implement `Copy`.
|
||||||
let ty = place.ty(body, tcx).ty;
|
let ty = place.ty(body, tcx).ty;
|
||||||
let trait_ref =
|
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(
|
self.prove_trait_ref(
|
||||||
trait_ref,
|
trait_ref,
|
||||||
@ -1828,7 +1829,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
&Rvalue::NullaryOp(NullOp::SizeOf | NullOp::AlignOf, ty) => {
|
&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(
|
self.prove_trait_ref(
|
||||||
trait_ref,
|
trait_ref,
|
||||||
@ -1840,7 +1841,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
|||||||
Rvalue::ShallowInitBox(operand, ty) => {
|
Rvalue::ShallowInitBox(operand, ty) => {
|
||||||
self.check_operand(operand, location);
|
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(
|
self.prove_trait_ref(
|
||||||
trait_ref,
|
trait_ref,
|
||||||
@ -1938,8 +1939,9 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
|||||||
CastKind::Pointer(PointerCast::Unsize) => {
|
CastKind::Pointer(PointerCast::Unsize) => {
|
||||||
let &ty = ty;
|
let &ty = ty;
|
||||||
let trait_ref = ty::TraitRef::from_lang_item(
|
let trait_ref = ty::TraitRef::from_lang_item(
|
||||||
tcx.at(span),
|
tcx,
|
||||||
LangItem::CoerceUnsized,
|
LangItem::CoerceUnsized,
|
||||||
|
span,
|
||||||
[op.ty(body, tcx), ty],
|
[op.ty(body, tcx), ty],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -158,8 +158,9 @@ impl Qualif for NeedsNonConstDrop {
|
|||||||
ObligationCause::dummy_with_span(cx.body.span),
|
ObligationCause::dummy_with_span(cx.body.span),
|
||||||
cx.param_env,
|
cx.param_env,
|
||||||
ty::Binder::dummy(ty::TraitRef::from_lang_item(
|
ty::Binder::dummy(ty::TraitRef::from_lang_item(
|
||||||
cx.tcx.at(cx.body.span),
|
cx.tcx,
|
||||||
LangItem::Destruct,
|
LangItem::Destruct,
|
||||||
|
cx.body.span,
|
||||||
[ty],
|
[ty],
|
||||||
))
|
))
|
||||||
.with_constness(ty::BoundConstness::ConstIfConst),
|
.with_constness(ty::BoundConstness::ConstIfConst),
|
||||||
|
@ -765,8 +765,9 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
|
|||||||
self.cause.clone(),
|
self.cause.clone(),
|
||||||
self.param_env,
|
self.param_env,
|
||||||
ty::TraitRef::from_lang_item(
|
ty::TraitRef::from_lang_item(
|
||||||
self.tcx.at(self.cause.span),
|
self.tcx,
|
||||||
hir::LangItem::PointerLike,
|
hir::LangItem::PointerLike,
|
||||||
|
self.cause.span,
|
||||||
[a],
|
[a],
|
||||||
),
|
),
|
||||||
));
|
));
|
||||||
|
@ -3,7 +3,6 @@
|
|||||||
#![allow(rustc::usage_of_ty_tykind)]
|
#![allow(rustc::usage_of_ty_tykind)]
|
||||||
|
|
||||||
use crate::infer::canonical::Canonical;
|
use crate::infer::canonical::Canonical;
|
||||||
use crate::ty::query::TyCtxtAt;
|
|
||||||
use crate::ty::subst::{GenericArg, InternalSubsts, SubstsRef};
|
use crate::ty::subst::{GenericArg, InternalSubsts, SubstsRef};
|
||||||
use crate::ty::visit::ValidateBoundVars;
|
use crate::ty::visit::ValidateBoundVars;
|
||||||
use crate::ty::InferTy::*;
|
use crate::ty::InferTy::*;
|
||||||
@ -836,12 +835,13 @@ impl<'tcx> TraitRef<'tcx> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn from_lang_item(
|
pub fn from_lang_item(
|
||||||
tcx: TyCtxtAt<'tcx>,
|
tcx: TyCtxt<'tcx>,
|
||||||
trait_lang_item: LangItem,
|
trait_lang_item: LangItem,
|
||||||
|
span: Span,
|
||||||
substs: impl IntoIterator<Item: Into<ty::GenericArg<'tcx>>>,
|
substs: impl IntoIterator<Item: Into<ty::GenericArg<'tcx>>>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let trait_def_id = tcx.require_lang_item(trait_lang_item, Some(tcx.span));
|
let trait_def_id = tcx.require_lang_item(trait_lang_item, Some(span));
|
||||||
Self::new(tcx.tcx, trait_def_id, substs)
|
Self::new(tcx, trait_def_id, substs)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn from_method(
|
pub fn from_method(
|
||||||
|
@ -31,8 +31,9 @@ fn custom_coerce_unsize_info<'tcx>(
|
|||||||
target_ty: Ty<'tcx>,
|
target_ty: Ty<'tcx>,
|
||||||
) -> CustomCoerceUnsized {
|
) -> CustomCoerceUnsized {
|
||||||
let trait_ref = ty::Binder::dummy(ty::TraitRef::from_lang_item(
|
let trait_ref = ty::Binder::dummy(ty::TraitRef::from_lang_item(
|
||||||
tcx,
|
tcx.tcx,
|
||||||
LangItem::CoerceUnsized,
|
LangItem::CoerceUnsized,
|
||||||
|
tcx.span,
|
||||||
[source_ty, target_ty],
|
[source_ty, target_ty],
|
||||||
));
|
));
|
||||||
|
|
||||||
|
@ -275,7 +275,7 @@ impl<'tcx> assembly::GoalKind<'tcx> for ProjectionPredicate<'tcx> {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
let output_is_sized_pred = tupled_inputs_and_output.map_bound(|(_, output)| {
|
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
|
let pred = tupled_inputs_and_output
|
||||||
@ -335,8 +335,9 @@ impl<'tcx> assembly::GoalKind<'tcx> for ProjectionPredicate<'tcx> {
|
|||||||
ty::Alias(_, _) | ty::Param(_) | ty::Placeholder(..) => {
|
ty::Alias(_, _) | ty::Param(_) | ty::Placeholder(..) => {
|
||||||
// FIXME(ptr_metadata): It would also be possible to return a `Ok(Ambig)` with no constraints.
|
// FIXME(ptr_metadata): It would also be possible to return a `Ok(Ambig)` with no constraints.
|
||||||
let sized_predicate = ty::TraitRef::from_lang_item(
|
let sized_predicate = ty::TraitRef::from_lang_item(
|
||||||
tcx.at(DUMMY_SP),
|
tcx,
|
||||||
LangItem::Sized,
|
LangItem::Sized,
|
||||||
|
DUMMY_SP,
|
||||||
[ty::GenericArg::from(goal.predicate.self_ty())],
|
[ty::GenericArg::from(goal.predicate.self_ty())],
|
||||||
);
|
);
|
||||||
ecx.add_goal(goal.with(tcx, sized_predicate));
|
ecx.add_goal(goal.with(tcx, sized_predicate));
|
||||||
|
@ -243,7 +243,7 @@ impl<'tcx> assembly::GoalKind<'tcx> for TraitPredicate<'tcx> {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
let output_is_sized_pred = tupled_inputs_and_output.map_bound(|(_, output)| {
|
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
|
let pred = tupled_inputs_and_output
|
||||||
|
@ -1683,7 +1683,7 @@ fn assemble_candidates_from_impls<'cx, 'tcx>(
|
|||||||
&obligation.with(
|
&obligation.with(
|
||||||
selcx.tcx(),
|
selcx.tcx(),
|
||||||
ty::Binder::dummy(
|
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(),
|
.without_const(),
|
||||||
),
|
),
|
||||||
@ -1949,8 +1949,9 @@ fn confirm_builtin_candidate<'cx, 'tcx>(
|
|||||||
});
|
});
|
||||||
if check_is_sized {
|
if check_is_sized {
|
||||||
let sized_predicate = ty::Binder::dummy(ty::TraitRef::from_lang_item(
|
let sized_predicate = ty::Binder::dummy(ty::TraitRef::from_lang_item(
|
||||||
tcx.at(obligation.cause.span()),
|
tcx,
|
||||||
LangItem::Sized,
|
LangItem::Sized,
|
||||||
|
obligation.cause.span(),
|
||||||
[self_ty],
|
[self_ty],
|
||||||
))
|
))
|
||||||
.without_const();
|
.without_const();
|
||||||
|
@ -646,8 +646,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
|||||||
output_ty,
|
output_ty,
|
||||||
&mut nested,
|
&mut nested,
|
||||||
);
|
);
|
||||||
let tr =
|
let tr = ty::TraitRef::from_lang_item(self.tcx(), LangItem::Sized, cause.span, [output_ty]);
|
||||||
ty::TraitRef::from_lang_item(self.tcx().at(cause.span), LangItem::Sized, [output_ty]);
|
|
||||||
nested.push(Obligation::new(self.infcx.tcx, cause, obligation.param_env, tr));
|
nested.push(Obligation::new(self.infcx.tcx, cause, obligation.param_env, tr));
|
||||||
|
|
||||||
Ok(ImplSourceFnPointerData { fn_ty: self_ty, nested })
|
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.
|
// We can only make objects from sized types.
|
||||||
let tr = ty::Binder::dummy(ty::TraitRef::from_lang_item(
|
let tr = ty::Binder::dummy(ty::TraitRef::from_lang_item(
|
||||||
tcx.at(cause.span),
|
tcx,
|
||||||
LangItem::Sized,
|
LangItem::Sized,
|
||||||
|
cause.span,
|
||||||
[source],
|
[source],
|
||||||
));
|
));
|
||||||
nested.push(predicate_to_obligation(tr.without_const().to_predicate(tcx)));
|
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,
|
obligation.recursion_depth + 1,
|
||||||
self_ty.rebind(ty::TraitPredicate {
|
self_ty.rebind(ty::TraitPredicate {
|
||||||
trait_ref: ty::TraitRef::from_lang_item(
|
trait_ref: ty::TraitRef::from_lang_item(
|
||||||
self.tcx().at(cause.span),
|
self.tcx(),
|
||||||
LangItem::Destruct,
|
LangItem::Destruct,
|
||||||
|
cause.span,
|
||||||
[nested_ty],
|
[nested_ty],
|
||||||
),
|
),
|
||||||
constness: ty::BoundConstness::ConstIfConst,
|
constness: ty::BoundConstness::ConstIfConst,
|
||||||
@ -1306,8 +1307,9 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
|||||||
_ => {
|
_ => {
|
||||||
let predicate = self_ty.rebind(ty::TraitPredicate {
|
let predicate = self_ty.rebind(ty::TraitPredicate {
|
||||||
trait_ref: ty::TraitRef::from_lang_item(
|
trait_ref: ty::TraitRef::from_lang_item(
|
||||||
self.tcx().at(cause.span),
|
self.tcx(),
|
||||||
LangItem::Destruct,
|
LangItem::Destruct,
|
||||||
|
cause.span,
|
||||||
[nested_ty],
|
[nested_ty],
|
||||||
),
|
),
|
||||||
constness: ty::BoundConstness::ConstIfConst,
|
constness: ty::BoundConstness::ConstIfConst,
|
||||||
|
@ -449,7 +449,7 @@ impl<'tcx> WfPredicates<'tcx> {
|
|||||||
if !subty.has_escaping_bound_vars() {
|
if !subty.has_escaping_bound_vars() {
|
||||||
let cause = self.cause(cause);
|
let cause = self.cause(cause);
|
||||||
let trait_ref =
|
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.out.push(traits::Obligation::with_depth(
|
||||||
self.tcx,
|
self.tcx,
|
||||||
cause,
|
cause,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user