Skip to content

Commit 4f2532f

Browse files
committed
Switch ty::TraitRef::from_lang_item from using TyCtxtAt to TyCtxt and a Span
1 parent 071f737 commit 4f2532f

File tree

10 files changed

+33
-24
lines changed

10 files changed

+33
-24
lines changed

compiler/rustc_borrowck/src/type_check/mod.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,7 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> {
539539
if let PlaceContext::NonMutatingUse(NonMutatingUseContext::Copy) = context {
540540
let tcx = self.tcx();
541541
let trait_ref =
542-
ty::TraitRef::from_lang_item(tcx.at(self.last_span), LangItem::Copy, [place_ty.ty]);
542+
ty::TraitRef::from_lang_item(tcx, LangItem::Copy, self.last_span, [place_ty.ty]);
543543

544544
// To have a `Copy` operand, the type `T` of the
545545
// value must be `Copy`. Note that we prove that `T: Copy`,
@@ -1239,8 +1239,9 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
12391239
self.check_rvalue(body, rv, location);
12401240
if !self.unsized_feature_enabled() {
12411241
let trait_ref = ty::TraitRef::from_lang_item(
1242-
tcx.at(self.last_span),
1242+
tcx,
12431243
LangItem::Sized,
1244+
self.last_span,
12441245
[place_ty],
12451246
);
12461247
self.prove_trait_ref(
@@ -1815,7 +1816,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
18151816
// Make sure that repeated elements implement `Copy`.
18161817
let ty = place.ty(body, tcx).ty;
18171818
let trait_ref =
1818-
ty::TraitRef::from_lang_item(tcx.at(span), LangItem::Copy, [ty]);
1819+
ty::TraitRef::from_lang_item(tcx, LangItem::Copy, span, [ty]);
18191820

18201821
self.prove_trait_ref(
18211822
trait_ref,
@@ -1828,7 +1829,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
18281829
}
18291830

18301831
&Rvalue::NullaryOp(NullOp::SizeOf | NullOp::AlignOf, ty) => {
1831-
let trait_ref = ty::TraitRef::from_lang_item(tcx.at(span), LangItem::Sized, [ty]);
1832+
let trait_ref = ty::TraitRef::from_lang_item(tcx, LangItem::Sized, span, [ty]);
18321833

18331834
self.prove_trait_ref(
18341835
trait_ref,
@@ -1840,7 +1841,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
18401841
Rvalue::ShallowInitBox(operand, ty) => {
18411842
self.check_operand(operand, location);
18421843

1843-
let trait_ref = ty::TraitRef::from_lang_item(tcx.at(span), LangItem::Sized, [*ty]);
1844+
let trait_ref = ty::TraitRef::from_lang_item(tcx, LangItem::Sized, span, [*ty]);
18441845

18451846
self.prove_trait_ref(
18461847
trait_ref,
@@ -1938,8 +1939,9 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
19381939
CastKind::Pointer(PointerCast::Unsize) => {
19391940
let &ty = ty;
19401941
let trait_ref = ty::TraitRef::from_lang_item(
1941-
tcx.at(span),
1942+
tcx,
19421943
LangItem::CoerceUnsized,
1944+
span,
19431945
[op.ty(body, tcx), ty],
19441946
);
19451947

compiler/rustc_const_eval/src/transform/check_consts/qualifs.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,9 @@ impl Qualif for NeedsNonConstDrop {
158158
ObligationCause::dummy_with_span(cx.body.span),
159159
cx.param_env,
160160
ty::Binder::dummy(ty::TraitRef::from_lang_item(
161-
cx.tcx.at(cx.body.span),
161+
cx.tcx,
162162
LangItem::Destruct,
163+
cx.body.span,
163164
[ty],
164165
))
165166
.with_constness(ty::BoundConstness::ConstIfConst),

compiler/rustc_hir_typeck/src/coercion.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -765,8 +765,9 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
765765
self.cause.clone(),
766766
self.param_env,
767767
ty::TraitRef::from_lang_item(
768-
self.tcx.at(self.cause.span),
768+
self.tcx,
769769
hir::LangItem::PointerLike,
770+
self.cause.span,
770771
[a],
771772
),
772773
));

compiler/rustc_middle/src/ty/sty.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
#![allow(rustc::usage_of_ty_tykind)]
44

55
use crate::infer::canonical::Canonical;
6-
use crate::ty::query::TyCtxtAt;
76
use crate::ty::subst::{GenericArg, InternalSubsts, SubstsRef};
87
use crate::ty::visit::ValidateBoundVars;
98
use crate::ty::InferTy::*;
@@ -836,12 +835,13 @@ impl<'tcx> TraitRef<'tcx> {
836835
}
837836

838837
pub fn from_lang_item(
839-
tcx: TyCtxtAt<'tcx>,
838+
tcx: TyCtxt<'tcx>,
840839
trait_lang_item: LangItem,
840+
span: Span,
841841
substs: impl IntoIterator<Item: Into<ty::GenericArg<'tcx>>>,
842842
) -> Self {
843-
let trait_def_id = tcx.require_lang_item(trait_lang_item, Some(tcx.span));
844-
Self::new(tcx.tcx, trait_def_id, substs)
843+
let trait_def_id = tcx.require_lang_item(trait_lang_item, Some(span));
844+
Self::new(tcx, trait_def_id, substs)
845845
}
846846

847847
pub fn from_method(

compiler/rustc_monomorphize/src/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,9 @@ fn custom_coerce_unsize_info<'tcx>(
3131
target_ty: Ty<'tcx>,
3232
) -> CustomCoerceUnsized {
3333
let trait_ref = ty::Binder::dummy(ty::TraitRef::from_lang_item(
34-
tcx,
34+
tcx.tcx,
3535
LangItem::CoerceUnsized,
36+
tcx.span,
3637
[source_ty, target_ty],
3738
));
3839

compiler/rustc_trait_selection/src/solve/project_goals.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ impl<'tcx> assembly::GoalKind<'tcx> for ProjectionPredicate<'tcx> {
275275
}
276276
};
277277
let output_is_sized_pred = tupled_inputs_and_output.map_bound(|(_, output)| {
278-
ty::TraitRef::from_lang_item(tcx.at(DUMMY_SP), LangItem::Sized, [output])
278+
ty::TraitRef::from_lang_item(tcx, LangItem::Sized, DUMMY_SP, [output])
279279
});
280280

281281
let pred = tupled_inputs_and_output
@@ -335,8 +335,9 @@ impl<'tcx> assembly::GoalKind<'tcx> for ProjectionPredicate<'tcx> {
335335
ty::Alias(_, _) | ty::Param(_) | ty::Placeholder(..) => {
336336
// FIXME(ptr_metadata): It would also be possible to return a `Ok(Ambig)` with no constraints.
337337
let sized_predicate = ty::TraitRef::from_lang_item(
338-
tcx.at(DUMMY_SP),
338+
tcx,
339339
LangItem::Sized,
340+
DUMMY_SP,
340341
[ty::GenericArg::from(goal.predicate.self_ty())],
341342
);
342343
ecx.add_goal(goal.with(tcx, sized_predicate));

compiler/rustc_trait_selection/src/solve/trait_goals.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ impl<'tcx> assembly::GoalKind<'tcx> for TraitPredicate<'tcx> {
243243
}
244244
};
245245
let output_is_sized_pred = tupled_inputs_and_output.map_bound(|(_, output)| {
246-
ty::TraitRef::from_lang_item(tcx.at(DUMMY_SP), LangItem::Sized, [output])
246+
ty::TraitRef::from_lang_item(tcx, LangItem::Sized, DUMMY_SP, [output])
247247
});
248248

249249
let pred = tupled_inputs_and_output

compiler/rustc_trait_selection/src/traits/project.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1683,7 +1683,7 @@ fn assemble_candidates_from_impls<'cx, 'tcx>(
16831683
&obligation.with(
16841684
selcx.tcx(),
16851685
ty::Binder::dummy(
1686-
ty::TraitRef::from_lang_item(selcx.tcx().at(obligation.cause.span()), LangItem::Sized, [self_ty]),
1686+
ty::TraitRef::from_lang_item(selcx.tcx(), LangItem::Sized, obligation.cause.span(),[self_ty]),
16871687
)
16881688
.without_const(),
16891689
),
@@ -1949,8 +1949,9 @@ fn confirm_builtin_candidate<'cx, 'tcx>(
19491949
});
19501950
if check_is_sized {
19511951
let sized_predicate = ty::Binder::dummy(ty::TraitRef::from_lang_item(
1952-
tcx.at(obligation.cause.span()),
1952+
tcx,
19531953
LangItem::Sized,
1954+
obligation.cause.span(),
19541955
[self_ty],
19551956
))
19561957
.without_const();

compiler/rustc_trait_selection/src/traits/select/confirmation.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -646,8 +646,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
646646
output_ty,
647647
&mut nested,
648648
);
649-
let tr =
650-
ty::TraitRef::from_lang_item(self.tcx().at(cause.span), LangItem::Sized, [output_ty]);
649+
let tr = ty::TraitRef::from_lang_item(self.tcx(), LangItem::Sized, cause.span, [output_ty]);
651650
nested.push(Obligation::new(self.infcx.tcx, cause, obligation.param_env, tr));
652651

653652
Ok(ImplSourceFnPointerData { fn_ty: self_ty, nested })
@@ -1051,8 +1050,9 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
10511050

10521051
// We can only make objects from sized types.
10531052
let tr = ty::Binder::dummy(ty::TraitRef::from_lang_item(
1054-
tcx.at(cause.span),
1053+
tcx,
10551054
LangItem::Sized,
1055+
cause.span,
10561056
[source],
10571057
));
10581058
nested.push(predicate_to_obligation(tr.without_const().to_predicate(tcx)));
@@ -1281,8 +1281,9 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
12811281
obligation.recursion_depth + 1,
12821282
self_ty.rebind(ty::TraitPredicate {
12831283
trait_ref: ty::TraitRef::from_lang_item(
1284-
self.tcx().at(cause.span),
1284+
self.tcx(),
12851285
LangItem::Destruct,
1286+
cause.span,
12861287
[nested_ty],
12871288
),
12881289
constness: ty::BoundConstness::ConstIfConst,
@@ -1306,8 +1307,9 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
13061307
_ => {
13071308
let predicate = self_ty.rebind(ty::TraitPredicate {
13081309
trait_ref: ty::TraitRef::from_lang_item(
1309-
self.tcx().at(cause.span),
1310+
self.tcx(),
13101311
LangItem::Destruct,
1312+
cause.span,
13111313
[nested_ty],
13121314
),
13131315
constness: ty::BoundConstness::ConstIfConst,

compiler/rustc_trait_selection/src/traits/wf.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ impl<'tcx> WfPredicates<'tcx> {
449449
if !subty.has_escaping_bound_vars() {
450450
let cause = self.cause(cause);
451451
let trait_ref =
452-
ty::TraitRef::from_lang_item(self.tcx.at(cause.span), LangItem::Sized, [subty]);
452+
ty::TraitRef::from_lang_item(self.tcx, LangItem::Sized, cause.span, [subty]);
453453
self.out.push(traits::Obligation::with_depth(
454454
self.tcx,
455455
cause,

0 commit comments

Comments
 (0)