Skip to content

Commit 6f8c055

Browse files
committed
Auto merge of rust-lang#110806 - WaffleLapkin:unmkI, r=lcnr
Replace `tcx.mk_trait_ref` with `TraitRef::new` First step in implementing rust-lang/compiler-team#616 r? `@lcnr`
2 parents 129195f + 689721d commit 6f8c055

File tree

49 files changed

+245
-180
lines changed

Some content is hidden

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

49 files changed

+245
-180
lines changed

compiler/rustc_borrowck/src/diagnostics/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1120,7 +1120,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
11201120
});
11211121
}
11221122
if let Some(clone_trait) = tcx.lang_items().clone_trait()
1123-
&& let trait_ref = tcx.mk_trait_ref(clone_trait, [ty])
1123+
&& let trait_ref = ty::TraitRef::new(tcx, clone_trait, [ty])
11241124
&& let o = Obligation::new(
11251125
tcx,
11261126
ObligationCause::dummy(),

compiler/rustc_borrowck/src/type_check/mod.rs

Lines changed: 18 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, LangItem::Copy, self.last_span, [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,12 @@ 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,
1243+
LangItem::Sized,
1244+
self.last_span,
1245+
[place_ty],
1246+
);
12421247
self.prove_trait_ref(
12431248
trait_ref,
12441249
location.to_locations(),
@@ -1810,7 +1815,8 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
18101815
Operand::Move(place) => {
18111816
// Make sure that repeated elements implement `Copy`.
18121817
let ty = place.ty(body, tcx).ty;
1813-
let trait_ref = tcx.at(span).mk_trait_ref(LangItem::Copy, [ty]);
1818+
let trait_ref =
1819+
ty::TraitRef::from_lang_item(tcx, LangItem::Copy, span, [ty]);
18141820

18151821
self.prove_trait_ref(
18161822
trait_ref,
@@ -1823,7 +1829,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
18231829
}
18241830

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

18281834
self.prove_trait_ref(
18291835
trait_ref,
@@ -1835,7 +1841,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
18351841
Rvalue::ShallowInitBox(operand, ty) => {
18361842
self.check_operand(operand, location);
18371843

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

18401846
self.prove_trait_ref(
18411847
trait_ref,
@@ -1932,9 +1938,12 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
19321938

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

19391948
self.prove_trait_ref(
19401949
trait_ref,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ 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]))
160+
ty::TraitRef::from_lang_item(cx.tcx, LangItem::Destruct, cx.body.span, [ty])
161161
.with_constness(ty::BoundConstness::ConstIfConst),
162162
);
163163

compiler/rustc_hir_analysis/src/astconv/mod.rs

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

696696
let poly_trait_ref =
697-
ty::Binder::bind_with_vars(tcx.mk_trait_ref(trait_def_id, substs), bound_vars);
697+
ty::Binder::bind_with_vars(ty::TraitRef::new(tcx, trait_def_id, substs), bound_vars);
698698

699699
debug!(?poly_trait_ref, ?assoc_bindings);
700700
bounds.push_trait_bound(tcx, poly_trait_ref, span, constness, polarity);
@@ -846,7 +846,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
846846
if let Some(b) = trait_segment.args().bindings.first() {
847847
prohibit_assoc_ty_binding(self.tcx(), b.span, Some((trait_segment, span)));
848848
}
849-
self.tcx().mk_trait_ref(trait_def_id, substs)
849+
ty::TraitRef::new(self.tcx(), trait_def_id, substs)
850850
}
851851

852852
#[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
@@ -63,7 +63,7 @@ impl<'tcx> Bounds<'tcx> {
6363

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

compiler/rustc_hir_analysis/src/check/check.rs

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

compiler/rustc_hir_analysis/src/check/wfcheck.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1779,7 +1779,7 @@ fn receiver_is_implemented<'tcx>(
17791779
receiver_ty: Ty<'tcx>,
17801780
) -> bool {
17811781
let tcx = wfcx.tcx();
1782-
let trait_ref = ty::Binder::dummy(tcx.mk_trait_ref(receiver_trait_def_id, [receiver_ty]));
1782+
let trait_ref = ty::TraitRef::new(tcx, receiver_trait_def_id, [receiver_ty]);
17831783

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

compiler/rustc_hir_analysis/src/coherence/builtin.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -265,10 +265,11 @@ fn visit_implementation_of_dispatch_from_dyn(tcx: TyCtxt<'_>, impl_did: LocalDef
265265
tcx,
266266
cause.clone(),
267267
param_env,
268-
ty::Binder::dummy(tcx.mk_trait_ref(
268+
ty::TraitRef::new(
269+
tcx,
269270
dispatch_from_dyn_trait,
270271
[field.ty(tcx, substs_a), field.ty(tcx, substs_b)],
271-
)),
272+
),
272273
));
273274
}
274275
let errors = ocx.select_all_or_error();
@@ -504,8 +505,12 @@ pub fn coerce_unsized_info<'tcx>(tcx: TyCtxt<'tcx>, impl_did: LocalDefId) -> Coe
504505
// Register an obligation for `A: Trait<B>`.
505506
let ocx = ObligationCtxt::new(&infcx);
506507
let cause = traits::ObligationCause::misc(span, impl_did);
507-
let obligation =
508-
Obligation::new(tcx, cause, param_env, tcx.mk_trait_ref(trait_def_id, [source, target]));
508+
let obligation = Obligation::new(
509+
tcx,
510+
cause,
511+
param_env,
512+
ty::TraitRef::new(tcx, trait_def_id, [source, target]),
513+
);
509514
ocx.register_obligation(obligation);
510515
let errors = ocx.select_all_or_error();
511516
if !errors.is_empty() {

compiler/rustc_hir_typeck/src/coercion.rs

Lines changed: 6 additions & 3 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,8 +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]),
767+
ty::TraitRef::from_lang_item(
768+
self.tcx,
769+
hir::LangItem::PointerLike,
770+
self.cause.span,
771+
[a],
769772
),
770773
));
771774

0 commit comments

Comments
 (0)