Skip to content

Commit 1bf8024

Browse files
committed
Remove many more cases of mk_substs_trait that can now use the iterator scheme`
1 parent 0fe86aa commit 1bf8024

File tree

7 files changed

+25
-19
lines changed

7 files changed

+25
-19
lines changed

compiler/rustc_hir_typeck/src/_match.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -547,10 +547,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
547547
}
548548
ty::PredicateKind::Clause(ty::Clause::Projection(mut proj_pred)) => {
549549
assert_eq!(proj_pred.projection_ty.self_ty(), opaque_ty);
550-
proj_pred.projection_ty.substs = self.tcx.mk_substs_trait(
551-
ty,
552-
proj_pred.projection_ty.substs.iter().skip(1),
553-
);
550+
proj_pred = proj_pred.with_self_ty(self.tcx, ty);
554551
ty::PredicateKind::Clause(ty::Clause::Projection(proj_pred))
555552
}
556553
_ => continue,

compiler/rustc_lint/src/context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1258,7 +1258,7 @@ impl<'tcx> LateContext<'tcx> {
12581258
tcx.associated_items(trait_id)
12591259
.find_by_name_and_kind(tcx, Ident::from_str(name), ty::AssocKind::Type, trait_id)
12601260
.and_then(|assoc| {
1261-
let proj = tcx.mk_projection(assoc.def_id, tcx.mk_substs_trait(self_ty, []));
1261+
let proj = tcx.mk_projection(assoc.def_id, [self_ty]);
12621262
tcx.try_normalize_erasing_regions(self.param_env, proj).ok()
12631263
})
12641264
}

compiler/rustc_middle/src/ty/context.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2598,7 +2598,11 @@ impl<'tcx> TyCtxt<'tcx> {
25982598
}
25992599

26002600
#[inline]
2601-
pub fn mk_projection(self, item_def_id: DefId, substs: SubstsRef<'tcx>) -> Ty<'tcx> {
2601+
pub fn mk_projection(
2602+
self,
2603+
item_def_id: DefId,
2604+
substs: impl IntoIterator<Item = impl Into<GenericArg<'tcx>>>,
2605+
) -> Ty<'tcx> {
26022606
self.mk_ty(Alias(ty::Projection, self.mk_alias_ty(item_def_id, substs)))
26032607
}
26042608

compiler/rustc_middle/src/ty/mod.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1050,6 +1050,18 @@ impl<'tcx> PolyProjectionPredicate<'tcx> {
10501050
}
10511051
}
10521052

1053+
impl<'tcx> ProjectionPredicate<'tcx> {
1054+
pub fn with_self_ty(self, tcx: TyCtxt<'tcx>, self_ty: Ty<'tcx>) -> Self {
1055+
Self {
1056+
projection_ty: tcx.mk_alias_ty(
1057+
self.projection_ty.def_id,
1058+
[self_ty.into()].into_iter().chain(self.projection_ty.substs.iter().skip(1)),
1059+
),
1060+
..self
1061+
}
1062+
}
1063+
}
1064+
10531065
pub trait ToPolyTraitRef<'tcx> {
10541066
fn to_poly_trait_ref(&self) -> PolyTraitRef<'tcx>;
10551067
}

compiler/rustc_mir_transform/src/shim.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -336,8 +336,7 @@ impl<'tcx> CloneShimBuilder<'tcx> {
336336
// we must subst the self_ty because it's
337337
// otherwise going to be TySelf and we can't index
338338
// or access fields of a Place of type TySelf.
339-
let substs = tcx.mk_substs_trait(self_ty, []);
340-
let sig = tcx.bound_fn_sig(def_id).subst(tcx, substs);
339+
let sig = tcx.bound_fn_sig(def_id).subst(tcx, &[self_ty.into()]);
341340
let sig = tcx.erase_late_bound_regions(sig);
342341
let span = tcx.def_span(def_id);
343342

@@ -573,9 +572,8 @@ fn build_call_shim<'tcx>(
573572

574573
// Create substitutions for the `Self` and `Args` generic parameters of the shim body.
575574
let arg_tup = tcx.mk_tup(untuple_args.iter());
576-
let sig_substs = tcx.mk_substs_trait(ty, [ty::subst::GenericArg::from(arg_tup)]);
577575

578-
(Some(sig_substs), Some(untuple_args))
576+
(Some([ty.into(), arg_tup.into()]), Some(untuple_args))
579577
} else {
580578
(None, None)
581579
};
@@ -586,7 +584,7 @@ fn build_call_shim<'tcx>(
586584

587585
assert_eq!(sig_substs.is_some(), !instance.has_polymorphic_mir_body());
588586
let mut sig =
589-
if let Some(sig_substs) = sig_substs { sig.subst(tcx, sig_substs) } else { sig.0 };
587+
if let Some(sig_substs) = sig_substs { sig.subst(tcx, &sig_substs) } else { sig.0 };
590588

591589
if let CallKind::Indirect(fnty) = call_kind {
592590
// `sig` determines our local decls, and thus the callee type in the `Call` terminator. This

compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2975,7 +2975,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
29752975
self.tcx.mk_projection(
29762976
item_def_id,
29772977
// Future::Output has no substs
2978-
self.tcx.mk_substs_trait(trait_pred.self_ty(), []),
2978+
[trait_pred.self_ty()],
29792979
)
29802980
});
29812981
let InferOk { value: projection_ty, .. } =

compiler/rustc_trait_selection/src/traits/mod.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -425,13 +425,8 @@ pub fn fully_solve_bound<'tcx>(
425425
bound: DefId,
426426
) -> Vec<FulfillmentError<'tcx>> {
427427
let tcx = infcx.tcx;
428-
let trait_ref = ty::TraitRef { def_id: bound, substs: tcx.mk_substs_trait(ty, []) };
429-
let obligation = Obligation {
430-
cause,
431-
recursion_depth: 0,
432-
param_env,
433-
predicate: ty::Binder::dummy(trait_ref).without_const().to_predicate(tcx),
434-
};
428+
let trait_ref = tcx.mk_trait_ref(bound, [ty]);
429+
let obligation = Obligation::new(tcx, cause, param_env, ty::Binder::dummy(trait_ref));
435430

436431
fully_solve_obligation(infcx, obligation)
437432
}

0 commit comments

Comments
 (0)