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

@ -547,11 +547,7 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> {
if let PlaceContext::NonMutatingUse(NonMutatingUseContext::Copy) = context {
let tcx = self.tcx();
let trait_ref = tcx.mk_trait_ref(
tcx.require_lang_item(LangItem::Copy, Some(self.last_span)),
place_ty.ty,
[],
);
let trait_ref = tcx.at(self.last_span).mk_trait_ref(LangItem::Copy, place_ty.ty, []);
// To have a `Copy` operand, the type `T` of the
// value must be `Copy`. Note that we prove that `T: Copy`,
@ -1274,11 +1270,8 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
self.check_rvalue(body, rv, location);
if !self.unsized_feature_enabled() {
let trait_ref = tcx.mk_trait_ref(
tcx.require_lang_item(LangItem::Sized, Some(self.last_span)),
place_ty,
[],
);
let trait_ref =
tcx.at(self.last_span).mk_trait_ref(LangItem::Sized, place_ty, []);
self.prove_trait_ref(
trait_ref,
location.to_locations(),
@ -1842,6 +1835,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
#[instrument(skip(self, body), level = "debug")]
fn check_rvalue(&mut self, body: &Body<'tcx>, rvalue: &Rvalue<'tcx>, location: Location) {
let tcx = self.tcx();
let span = body.source_info(location).span;
match rvalue {
Rvalue::Aggregate(ak, ops) => {
@ -1865,13 +1859,8 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
}
Operand::Move(place) => {
// Make sure that repeated elements implement `Copy`.
let span = body.source_info(location).span;
let ty = place.ty(body, tcx).ty;
let trait_ref = tcx.mk_trait_ref(
tcx.require_lang_item(LangItem::Copy, Some(span)),
ty,
[],
);
let trait_ref = tcx.at(span).mk_trait_ref(LangItem::Copy, ty, []);
self.prove_trait_ref(
trait_ref,
@ -1884,11 +1873,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
}
&Rvalue::NullaryOp(NullOp::SizeOf | NullOp::AlignOf, ty) => {
let trait_ref = tcx.mk_trait_ref(
tcx.require_lang_item(LangItem::Sized, Some(self.last_span)),
ty,
[],
);
let trait_ref = tcx.at(span).mk_trait_ref(LangItem::Sized, ty, []);
self.prove_trait_ref(
trait_ref,
@ -1900,11 +1885,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
Rvalue::ShallowInitBox(operand, ty) => {
self.check_operand(operand, location);
let trait_ref = tcx.mk_trait_ref(
tcx.require_lang_item(LangItem::Sized, Some(self.last_span)),
*ty,
[],
);
let trait_ref = tcx.at(span).mk_trait_ref(LangItem::Sized, *ty, []);
self.prove_trait_ref(
trait_ref,
@ -2001,8 +1982,8 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
CastKind::Pointer(PointerCast::Unsize) => {
let &ty = ty;
let trait_ref = tcx.mk_trait_ref(
tcx.require_lang_item(LangItem::CoerceUnsized, Some(self.last_span)),
let trait_ref = tcx.at(span).mk_trait_ref(
LangItem::CoerceUnsized,
op.ty(body, tcx),
[ty.into()],
);