Skip to content

Commit 46b01ab

Browse files
committed
Replace tcx.mk_trait_ref with ty::TraitRef::new
1 parent 2d8c905 commit 46b01ab

File tree

41 files changed

+193
-125
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+193
-125
lines changed

compiler/rustc_borrowck/src/diagnostics/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1111,7 +1111,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
11111111
});
11121112
}
11131113
if let Some(clone_trait) = tcx.lang_items().clone_trait()
1114-
&& let trait_ref = tcx.mk_trait_ref(clone_trait, [ty])
1114+
&& let trait_ref = ty::TraitRef::new(tcx, clone_trait, [ty])
11151115
&& let o = Obligation::new(
11161116
tcx,
11171117
ObligationCause::dummy(),

compiler/rustc_borrowck/src/type_check/mod.rs

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,8 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> {
538538

539539
if let PlaceContext::NonMutatingUse(NonMutatingUseContext::Copy) = context {
540540
let tcx = self.tcx();
541-
let trait_ref = tcx.at(self.last_span).mk_trait_ref(LangItem::Copy, [place_ty.ty]);
541+
let trait_ref =
542+
ty::TraitRef::from_lang_item(tcx.at(self.last_span), LangItem::Copy, [place_ty.ty]);
542543

543544
// To have a `Copy` operand, the type `T` of the
544545
// value must be `Copy`. Note that we prove that `T: Copy`,
@@ -1237,8 +1238,11 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
12371238

12381239
self.check_rvalue(body, rv, location);
12391240
if !self.unsized_feature_enabled() {
1240-
let trait_ref =
1241-
tcx.at(self.last_span).mk_trait_ref(LangItem::Sized, [place_ty]);
1241+
let trait_ref = ty::TraitRef::from_lang_item(
1242+
tcx.at(self.last_span),
1243+
LangItem::Sized,
1244+
[place_ty],
1245+
);
12421246
self.prove_trait_ref(
12431247
trait_ref,
12441248
location.to_locations(),
@@ -1810,7 +1814,8 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
18101814
Operand::Move(place) => {
18111815
// Make sure that repeated elements implement `Copy`.
18121816
let ty = place.ty(body, tcx).ty;
1813-
let trait_ref = tcx.at(span).mk_trait_ref(LangItem::Copy, [ty]);
1817+
let trait_ref =
1818+
ty::TraitRef::from_lang_item(tcx.at(span), LangItem::Copy, [ty]);
18141819

18151820
self.prove_trait_ref(
18161821
trait_ref,
@@ -1823,7 +1828,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
18231828
}
18241829

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

18281833
self.prove_trait_ref(
18291834
trait_ref,
@@ -1835,7 +1840,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
18351840
Rvalue::ShallowInitBox(operand, ty) => {
18361841
self.check_operand(operand, location);
18371842

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

18401845
self.prove_trait_ref(
18411846
trait_ref,
@@ -1932,9 +1937,11 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
19321937

19331938
CastKind::Pointer(PointerCast::Unsize) => {
19341939
let &ty = ty;
1935-
let trait_ref = tcx
1936-
.at(span)
1937-
.mk_trait_ref(LangItem::CoerceUnsized, [op.ty(body, tcx), ty]);
1940+
let trait_ref = ty::TraitRef::from_lang_item(
1941+
tcx.at(span),
1942+
LangItem::CoerceUnsized,
1943+
[op.ty(body, tcx), ty],
1944+
);
19381945

19391946
self.prove_trait_ref(
19401947
trait_ref,

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,12 @@ impl Qualif for NeedsNonConstDrop {
157157
cx.tcx,
158158
ObligationCause::dummy_with_span(cx.body.span),
159159
cx.param_env,
160-
ty::Binder::dummy(cx.tcx.at(cx.body.span).mk_trait_ref(LangItem::Destruct, [ty]))
161-
.with_constness(ty::BoundConstness::ConstIfConst),
160+
ty::Binder::dummy(ty::TraitRef::from_lang_item(
161+
cx.tcx.at(cx.body.span),
162+
LangItem::Destruct,
163+
[ty],
164+
))
165+
.with_constness(ty::BoundConstness::ConstIfConst),
162166
);
163167

164168
let infcx = cx.tcx.infer_ctxt().build();

compiler/rustc_hir_analysis/src/astconv/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -689,7 +689,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
689689
let assoc_bindings = self.create_assoc_bindings_for_generic_args(args);
690690

691691
let poly_trait_ref =
692-
ty::Binder::bind_with_vars(tcx.mk_trait_ref(trait_def_id, substs), bound_vars);
692+
ty::Binder::bind_with_vars(ty::TraitRef::new(tcx, trait_def_id, substs), bound_vars);
693693

694694
debug!(?poly_trait_ref, ?assoc_bindings);
695695
bounds.push_trait_bound(tcx, poly_trait_ref, span, constness);
@@ -822,7 +822,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
822822
if let Some(b) = trait_segment.args().bindings.first() {
823823
prohibit_assoc_ty_binding(self.tcx(), b.span, Some((trait_segment, span)));
824824
}
825-
self.tcx().mk_trait_ref(trait_def_id, substs)
825+
ty::TraitRef::new(self.tcx(), trait_def_id, substs)
826826
}
827827

828828
#[instrument(level = "debug", skip(self, span))]

compiler/rustc_hir_analysis/src/autoderef.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ impl<'a, 'tcx> Autoderef<'a, 'tcx> {
123123
let tcx = self.infcx.tcx;
124124

125125
// <ty as Deref>
126-
let trait_ref = tcx.mk_trait_ref(tcx.lang_items().deref_trait()?, [ty]);
126+
let trait_ref = ty::TraitRef::new(tcx, tcx.lang_items().deref_trait()?, [ty]);
127127

128128
let cause = traits::ObligationCause::misc(self.span, self.body_id);
129129

compiler/rustc_hir_analysis/src/bounds.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ impl<'tcx> Bounds<'tcx> {
5757

5858
pub fn push_sized(&mut self, tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, span: Span) {
5959
let sized_def_id = tcx.require_lang_item(LangItem::Sized, Some(span));
60-
let trait_ref = ty::Binder::dummy(tcx.mk_trait_ref(sized_def_id, [ty]));
60+
let trait_ref = ty::Binder::dummy(ty::TraitRef::new(tcx, sized_def_id, [ty]));
6161
// Preferable to put this obligation first, since we report better errors for sized ambiguity.
6262
self.predicates.insert(0, (trait_ref.without_const().to_predicate(tcx), span));
6363
}

compiler/rustc_hir_analysis/src/check/check.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,7 @@ fn check_item_type(tcx: TyCtxt<'_>, id: hir::ItemId) {
538538
tcx,
539539
assoc_item,
540540
assoc_item,
541-
tcx.mk_trait_ref(id.owner_id.to_def_id(), trait_substs),
541+
ty::TraitRef::new(tcx, id.owner_id.to_def_id(), trait_substs),
542542
);
543543
}
544544
_ => {}

compiler/rustc_hir_analysis/src/check/wfcheck.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1784,7 +1784,7 @@ fn receiver_is_implemented<'tcx>(
17841784
receiver_ty: Ty<'tcx>,
17851785
) -> bool {
17861786
let tcx = wfcx.tcx();
1787-
let trait_ref = ty::Binder::dummy(tcx.mk_trait_ref(receiver_trait_def_id, [receiver_ty]));
1787+
let trait_ref = ty::Binder::dummy(ty::TraitRef::new(tcx, receiver_trait_def_id, [receiver_ty]));
17881788

17891789
let obligation = traits::Obligation::new(tcx, cause, wfcx.param_env, trait_ref);
17901790

compiler/rustc_hir_analysis/src/coherence/builtin.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,8 @@ fn visit_implementation_of_dispatch_from_dyn(tcx: TyCtxt<'_>, impl_did: LocalDef
340340
tcx,
341341
cause.clone(),
342342
param_env,
343-
ty::Binder::dummy(tcx.mk_trait_ref(
343+
ty::Binder::dummy(ty::TraitRef::new(
344+
tcx,
344345
dispatch_from_dyn_trait,
345346
[field.ty(tcx, substs_a), field.ty(tcx, substs_b)],
346347
)),
@@ -579,8 +580,12 @@ pub fn coerce_unsized_info<'tcx>(tcx: TyCtxt<'tcx>, impl_did: LocalDefId) -> Coe
579580
// Register an obligation for `A: Trait<B>`.
580581
let ocx = ObligationCtxt::new(&infcx);
581582
let cause = traits::ObligationCause::misc(span, impl_did);
582-
let obligation =
583-
Obligation::new(tcx, cause, param_env, tcx.mk_trait_ref(trait_def_id, [source, target]));
583+
let obligation = Obligation::new(
584+
tcx,
585+
cause,
586+
param_env,
587+
ty::TraitRef::new(tcx, trait_def_id, [source, target]),
588+
);
584589
ocx.register_obligation(obligation);
585590
let errors = ocx.select_all_or_error();
586591
if !errors.is_empty() {

compiler/rustc_hir_typeck/src/coercion.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -601,7 +601,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
601601
self.tcx,
602602
cause,
603603
self.fcx.param_env,
604-
self.tcx.mk_trait_ref(coerce_unsized_did, [coerce_source, coerce_target])
604+
ty::TraitRef::new(self.tcx, coerce_unsized_did, [coerce_source, coerce_target])
605605
)];
606606

607607
let mut has_unsized_tuple_coercion = false;
@@ -764,9 +764,11 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
764764
self.tcx,
765765
self.cause.clone(),
766766
self.param_env,
767-
ty::Binder::dummy(
768-
self.tcx.at(self.cause.span).mk_trait_ref(hir::LangItem::PointerLike, [a]),
769-
),
767+
ty::Binder::dummy(ty::TraitRef::from_lang_item(
768+
self.tcx.at(self.cause.span),
769+
hir::LangItem::PointerLike,
770+
[a],
771+
)),
770772
));
771773

772774
Ok(InferOk {

0 commit comments

Comments
 (0)