Skip to content

Commit bcf0ec0

Browse files
committed
Replace mk_foo calls with infer_foo where possible.
There are several `mk_foo`/`intern_foo` pairs, where the former takes an iterator and the latter takes a slice. (This naming convention is bad, but that's a fix for another PR.) This commit changes several `mk_foo` occurrences into `intern_foo`, avoiding the need for some `.iter()`/`.into_iter()` calls. Affected cases: - mk_type_list - mk_tup - mk_substs - mk_const_list
1 parent 9556b56 commit bcf0ec0

File tree

20 files changed

+37
-42
lines changed

20 files changed

+37
-42
lines changed

compiler/rustc_borrowck/src/type_check/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2589,7 +2589,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
25892589
DefKind::InlineConst => substs.as_inline_const().parent_substs(),
25902590
other => bug!("unexpected item {:?}", other),
25912591
};
2592-
let parent_substs = tcx.mk_substs(parent_substs.iter());
2592+
let parent_substs = tcx.intern_substs(parent_substs);
25932593

25942594
assert_eq!(typeck_root_substs.len(), parent_substs.len());
25952595
if let Err(_) = self.eq_substs(

compiler/rustc_codegen_cranelift/src/codegen_i128.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ pub(crate) fn maybe_codegen<'tcx>(
5656
Some(fx.easy_call("__multi3", &[lhs, rhs], val_ty))
5757
}
5858
} else {
59-
let out_ty = fx.tcx.mk_tup([lhs.layout().ty, fx.tcx.types.bool].iter());
59+
let out_ty = fx.tcx.intern_tup(&[lhs.layout().ty, fx.tcx.types.bool]);
6060
let oflow = CPlace::new_stack_slot(fx, fx.layout_of(fx.tcx.types.i32));
6161
let lhs = lhs.load_scalar(fx);
6262
let rhs = rhs.load_scalar(fx);
@@ -78,7 +78,7 @@ pub(crate) fn maybe_codegen<'tcx>(
7878
}
7979
BinOp::Add | BinOp::Sub | BinOp::Mul => {
8080
assert!(checked);
81-
let out_ty = fx.tcx.mk_tup([lhs.layout().ty, fx.tcx.types.bool].iter());
81+
let out_ty = fx.tcx.intern_tup(&[lhs.layout().ty, fx.tcx.types.bool]);
8282
let out_place = CPlace::new_stack_slot(fx, fx.layout_of(out_ty));
8383
let (param_types, args) = if fx.tcx.sess.target.is_like_windows {
8484
let (lhs_ptr, lhs_extra) = lhs.force_stack(fx);

compiler/rustc_codegen_cranelift/src/intrinsics/llvm_x86.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ fn llvm_add_sub<'tcx>(
191191
// carry0 | carry1 -> carry or borrow respectively
192192
let cb_out = fx.bcx.ins().bor(cb0, cb1);
193193

194-
let layout = fx.layout_of(fx.tcx.mk_tup([fx.tcx.types.u8, fx.tcx.types.u64].iter()));
194+
let layout = fx.layout_of(fx.tcx.intern_tup(&[fx.tcx.types.u8, fx.tcx.types.u64]));
195195
let val = CValue::by_val_pair(cb_out, c, layout);
196196
ret.write_cvalue(fx, val);
197197
}

compiler/rustc_codegen_cranelift/src/main_shim.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ pub(crate) fn maybe_create_entry_wrapper(
119119
tcx,
120120
ParamEnv::reveal_all(),
121121
report.def_id,
122-
tcx.mk_substs([GenericArg::from(main_ret_ty)].iter()),
122+
tcx.intern_substs(&[GenericArg::from(main_ret_ty)]),
123123
)
124124
.unwrap()
125125
.unwrap()

compiler/rustc_codegen_cranelift/src/num.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ pub(crate) fn codegen_checked_int_binop<'tcx>(
289289
_ => bug!("binop {:?} on checked int/uint lhs: {:?} rhs: {:?}", bin_op, in_lhs, in_rhs),
290290
};
291291

292-
let out_layout = fx.layout_of(fx.tcx.mk_tup([in_lhs.layout().ty, fx.tcx.types.bool].iter()));
292+
let out_layout = fx.layout_of(fx.tcx.intern_tup(&[in_lhs.layout().ty, fx.tcx.types.bool]));
293293
CValue::by_val_pair(res, has_overflow, out_layout)
294294
}
295295

compiler/rustc_const_eval/src/interpret/intrinsics/caller_location.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
9696
let loc_ty = self
9797
.tcx
9898
.type_of(self.tcx.require_lang_item(LangItem::PanicLocation, None))
99-
.subst(*self.tcx, self.tcx.mk_substs([self.tcx.lifetimes.re_erased.into()].iter()));
99+
.subst(*self.tcx, self.tcx.intern_substs(&[self.tcx.lifetimes.re_erased.into()]));
100100
let loc_layout = self.layout_of(loc_ty).unwrap();
101101
let location = self.allocate(loc_layout, MemoryKind::CallerLocation).unwrap();
102102

compiler/rustc_hir_analysis/src/check/intrinsic.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>) {
378378
(
379379
1,
380380
vec![tcx.mk_imm_ref(tcx.mk_re_late_bound(ty::INNERMOST, br), param(0))],
381-
tcx.mk_projection(discriminant_def_id, tcx.mk_substs([param(0).into()].iter())),
381+
tcx.mk_projection(discriminant_def_id, tcx.intern_substs(&[param(0).into()])),
382382
)
383383
}
384384

compiler/rustc_hir_typeck/src/upvar.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
301301

302302
// Build a tuple (U0..Un) of the final upvar types U0..Un
303303
// and unify the upvar tuple type in the closure with it:
304-
let final_tupled_upvars_type = self.tcx.mk_tup(final_upvar_tys.iter());
304+
let final_tupled_upvars_type = self.tcx.intern_tup(&final_upvar_tys);
305305
self.demand_suptype(span, substs.tupled_upvars_ty(), final_tupled_upvars_type);
306306

307307
let fake_reads = delegate
@@ -315,8 +315,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
315315
self.typeck_results.borrow_mut().closure_size_eval.insert(
316316
closure_def_id,
317317
ClosureSizeProfileData {
318-
before_feature_tys: self.tcx.mk_tup(before_feature_tys.into_iter()),
319-
after_feature_tys: self.tcx.mk_tup(after_feature_tys.into_iter()),
318+
before_feature_tys: self.tcx.intern_tup(&before_feature_tys),
319+
after_feature_tys: self.tcx.intern_tup(&after_feature_tys),
320320
},
321321
);
322322
}

compiler/rustc_metadata/src/native_libs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@ impl<'tcx> Collector<'tcx> {
502502
.subst_identity()
503503
.fn_sig(self.tcx)
504504
.inputs()
505-
.map_bound(|slice| self.tcx.mk_type_list(slice.iter())),
505+
.map_bound(|slice| self.tcx.intern_type_list(slice)),
506506
);
507507

508508
argument_types

compiler/rustc_middle/src/mir/mod.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2525,14 +2525,12 @@ impl<'tcx> ConstantKind<'tcx> {
25252525
}
25262526

25272527
let hir_id = tcx.hir().local_def_id_to_hir_id(def.did);
2528-
let parent_substs = if let Some(parent_hir_id) = tcx.hir().opt_parent_id(hir_id) {
2529-
if let Some(parent_did) = parent_hir_id.as_owner() {
2530-
InternalSubsts::identity_for_item(tcx, parent_did.to_def_id())
2531-
} else {
2532-
tcx.mk_substs(Vec::<GenericArg<'tcx>>::new().into_iter())
2533-
}
2528+
let parent_substs = if let Some(parent_hir_id) = tcx.hir().opt_parent_id(hir_id)
2529+
&& let Some(parent_did) = parent_hir_id.as_owner()
2530+
{
2531+
InternalSubsts::identity_for_item(tcx, parent_did.to_def_id())
25342532
} else {
2535-
tcx.mk_substs(Vec::<GenericArg<'tcx>>::new().into_iter())
2533+
tcx.intern_substs(&[])
25362534
};
25372535
debug!(?parent_substs);
25382536

compiler/rustc_middle/src/ty/context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1190,7 +1190,7 @@ impl<'tcx> TyCtxt<'tcx> {
11901190
self.mk_imm_ref(
11911191
self.lifetimes.re_static,
11921192
self.type_of(self.require_lang_item(LangItem::PanicLocation, None))
1193-
.subst(self, self.mk_substs([self.lifetimes.re_static.into()].iter())),
1193+
.subst(self, self.intern_substs(&[self.lifetimes.re_static.into()])),
11941194
)
11951195
}
11961196

compiler/rustc_middle/src/ty/layout.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -686,7 +686,7 @@ where
686686
Increase this counter if you tried to implement this but
687687
failed to do it without duplicating a lot of code from
688688
other places in the compiler: 2
689-
tcx.mk_tup(&[
689+
tcx.intern_tup(&[
690690
tcx.mk_array(tcx.types.usize, 3),
691691
tcx.mk_array(Option<fn()>),
692692
])

compiler/rustc_middle/src/ty/relate.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -673,7 +673,7 @@ pub fn super_relate_consts<'tcx, R: TypeRelation<'tcx>>(
673673
for (a_arg, b_arg) in aa.iter().zip(ba.iter()) {
674674
related_args.push(r.consts(a_arg, b_arg)?);
675675
}
676-
let related_args = tcx.mk_const_list(related_args.iter());
676+
let related_args = tcx.intern_const_list(&related_args);
677677
Expr::FunctionCall(func, related_args)
678678
}
679679
_ => return Err(TypeError::ConstMismatch(expected_found(r, a, b))),

compiler/rustc_middle/src/ty/structural_impls.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ impl<'tcx> ir::TypeFoldable<TyCtxt<'tcx>> for &'tcx ty::List<ty::PolyExistential
418418

419419
impl<'tcx> ir::TypeFoldable<TyCtxt<'tcx>> for &'tcx ty::List<ty::Const<'tcx>> {
420420
fn try_fold_with<F: FallibleTypeFolder<'tcx>>(self, folder: &mut F) -> Result<Self, F::Error> {
421-
ty::util::fold_list(self, folder, |tcx, v| tcx.mk_const_list(v.iter()))
421+
ty::util::fold_list(self, folder, |tcx, v| tcx.intern_const_list(v))
422422
}
423423
}
424424

compiler/rustc_mir_transform/src/shim.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,7 @@ fn build_call_shim<'tcx>(
597597
let untuple_args = sig.inputs();
598598

599599
// Create substitutions for the `Self` and `Args` generic parameters of the shim body.
600-
let arg_tup = tcx.mk_tup(untuple_args.iter());
600+
let arg_tup = tcx.intern_tup(untuple_args);
601601

602602
(Some([ty.into(), arg_tup.into()]), Some(untuple_args))
603603
} else {

compiler/rustc_symbol_mangling/src/typeid/typeid_itanium_cxx_abi.rs

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -813,21 +813,18 @@ fn transform_substs<'tcx>(
813813
substs: SubstsRef<'tcx>,
814814
options: TransformTyOptions,
815815
) -> SubstsRef<'tcx> {
816-
let substs: Vec<GenericArg<'tcx>> = substs
817-
.iter()
818-
.map(|subst| {
819-
if let GenericArgKind::Type(ty) = subst.unpack() {
820-
if is_c_void_ty(tcx, ty) {
821-
tcx.mk_unit().into()
822-
} else {
823-
transform_ty(tcx, ty, options).into()
824-
}
816+
let substs = substs.iter().map(|subst| {
817+
if let GenericArgKind::Type(ty) = subst.unpack() {
818+
if is_c_void_ty(tcx, ty) {
819+
tcx.mk_unit().into()
825820
} else {
826-
subst
821+
transform_ty(tcx, ty, options).into()
827822
}
828-
})
829-
.collect();
830-
tcx.mk_substs(substs.iter())
823+
} else {
824+
subst
825+
}
826+
});
827+
tcx.mk_substs(substs)
831828
}
832829

833830
/// Returns a type metadata identifier for the specified FnAbi using the Itanium C++ ABI with vendor

compiler/rustc_trait_selection/src/solve/trait_goals/structural_traits.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,10 +191,10 @@ pub(crate) fn extract_tupled_inputs_and_output_from_callable<'tcx>(
191191
ty::FnDef(def_id, substs) => Ok(Some(
192192
tcx.fn_sig(def_id)
193193
.subst(tcx, substs)
194-
.map_bound(|sig| (tcx.mk_tup(sig.inputs().iter()), sig.output())),
194+
.map_bound(|sig| (tcx.intern_tup(sig.inputs()), sig.output())),
195195
)),
196196
ty::FnPtr(sig) => {
197-
Ok(Some(sig.map_bound(|sig| (tcx.mk_tup(sig.inputs().iter()), sig.output()))))
197+
Ok(Some(sig.map_bound(|sig| (tcx.intern_tup(sig.inputs()), sig.output()))))
198198
}
199199
ty::Closure(_, substs) => {
200200
let closure_substs = substs.as_closure();

compiler/rustc_trait_selection/src/traits/project.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1923,7 +1923,7 @@ fn confirm_builtin_candidate<'cx, 'tcx>(
19231923
) -> Progress<'tcx> {
19241924
let tcx = selcx.tcx();
19251925
let self_ty = obligation.predicate.self_ty();
1926-
let substs = tcx.mk_substs([self_ty.into()].iter());
1926+
let substs = tcx.intern_substs(&[self_ty.into()]);
19271927
let lang_items = tcx.lang_items();
19281928
let item_def_id = obligation.predicate.def_id;
19291929
let trait_def_id = tcx.trait_of_item(item_def_id).unwrap();

compiler/rustc_ty_utils/src/consts.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ fn recurse_build<'tcx>(
144144
for &id in args.iter() {
145145
new_args.push(recurse_build(tcx, body, id, root_span)?);
146146
}
147-
let new_args = tcx.mk_const_list(new_args.iter());
147+
let new_args = tcx.intern_const_list(&new_args);
148148
tcx.mk_const(Expr::FunctionCall(fun, new_args), node.ty)
149149
}
150150
&ExprKind::Binary { op, lhs, rhs } if check_binop(op) => {

src/tools/clippy/clippy_lints/src/methods/needless_collect.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ fn is_contains_sig(cx: &LateContext<'_>, call_id: HirId, iter_expr: &Expr<'_>) -
173173
&& let Some(iter_item) = cx.tcx
174174
.associated_items(iter_trait)
175175
.find_by_name_and_kind(cx.tcx, Ident::with_dummy_span(Symbol::intern("Item")), AssocKind::Type, iter_trait)
176-
&& let substs = cx.tcx.mk_substs([GenericArg::from(typeck.expr_ty_adjusted(iter_expr))].into_iter())
176+
&& let substs = cx.tcx.intern_substs(&[GenericArg::from(typeck.expr_ty_adjusted(iter_expr))])
177177
&& let proj_ty = cx.tcx.mk_projection(iter_item.def_id, substs)
178178
&& let Ok(item_ty) = cx.tcx.try_normalize_erasing_regions(cx.param_env, proj_ty)
179179
{

0 commit comments

Comments
 (0)