Skip to content

Commit 2017aef

Browse files
committed
Use IntoIterator for mk_fn_sig.
This makes a lot of call sites nicer.
1 parent c8237db commit 2017aef

File tree

11 files changed

+28
-35
lines changed

11 files changed

+28
-35
lines changed

compiler/rustc_codegen_llvm/src/coverageinfo/mod.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ use rustc_middle::ty::Instance;
2727
use std::cell::RefCell;
2828
use std::ffi::CString;
2929

30-
use std::iter;
31-
3230
pub mod mapgen;
3331

3432
const UNUSED_FUNCTION_COUNTER_ID: CounterValueReference = CounterValueReference::START;
@@ -201,7 +199,7 @@ fn declare_unused_fn<'tcx>(cx: &CodegenCx<'_, 'tcx>, def_id: DefId) -> Instance<
201199
tcx.symbol_name(instance).name,
202200
cx.fn_abi_of_fn_ptr(
203201
ty::Binder::dummy(tcx.mk_fn_sig(
204-
iter::once(tcx.mk_unit()),
202+
[tcx.mk_unit()],
205203
tcx.mk_unit(),
206204
false,
207205
hir::Unsafety::Unsafe,

compiler/rustc_codegen_llvm/src/intrinsic.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ use rustc_target::abi::{self, Align, HasDataLayout, Primitive};
2222
use rustc_target::spec::{HasTargetSpec, PanicStrategy};
2323

2424
use std::cmp::Ordering;
25-
use std::iter;
2625

2726
fn get_simple_intrinsic<'ll>(
2827
cx: &CodegenCx<'ll, '_>,
@@ -798,23 +797,23 @@ fn get_rust_try_fn<'ll, 'tcx>(
798797
let i8p = tcx.mk_mut_ptr(tcx.types.i8);
799798
// `unsafe fn(*mut i8) -> ()`
800799
let try_fn_ty = tcx.mk_fn_ptr(ty::Binder::dummy(tcx.mk_fn_sig(
801-
iter::once(i8p),
800+
[i8p],
802801
tcx.mk_unit(),
803802
false,
804803
hir::Unsafety::Unsafe,
805804
Abi::Rust,
806805
)));
807806
// `unsafe fn(*mut i8, *mut i8) -> ()`
808807
let catch_fn_ty = tcx.mk_fn_ptr(ty::Binder::dummy(tcx.mk_fn_sig(
809-
[i8p, i8p].iter().cloned(),
808+
[i8p, i8p],
810809
tcx.mk_unit(),
811810
false,
812811
hir::Unsafety::Unsafe,
813812
Abi::Rust,
814813
)));
815814
// `unsafe fn(unsafe fn(*mut i8) -> (), *mut i8, unsafe fn(*mut i8, *mut i8) -> ()) -> i32`
816815
let rust_fn_sig = ty::Binder::dummy(cx.tcx.mk_fn_sig(
817-
[try_fn_ty, i8p, catch_fn_ty].into_iter(),
816+
[try_fn_ty, i8p, catch_fn_ty],
818817
tcx.types.i32,
819818
false,
820819
hir::Unsafety::Unsafe,

compiler/rustc_hir_analysis/src/astconv/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3109,7 +3109,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
31093109

31103110
debug!(?output_ty);
31113111

3112-
let fn_ty = tcx.mk_fn_sig(input_tys.into_iter(), output_ty, decl.c_variadic, unsafety, abi);
3112+
let fn_ty = tcx.mk_fn_sig(input_tys, output_ty, decl.c_variadic, unsafety, abi);
31133113
let bare_fn_ty = ty::Binder::bind_with_vars(fn_ty, bound_vars);
31143114

31153115
if !self.allow_ty_infer() && !(visitor.0.is_empty() && infer_replacements.is_empty()) {

compiler/rustc_hir_analysis/src/check/intrinsic.rs

+4-12
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ use rustc_middle::ty::{self, TyCtxt};
1515
use rustc_span::symbol::{kw, sym, Symbol};
1616
use rustc_target::spec::abi::Abi;
1717

18-
use std::iter;
19-
2018
fn equate_intrinsic_type<'tcx>(
2119
tcx: TyCtxt<'tcx>,
2220
it: &hir::ForeignItem<'_>,
@@ -385,14 +383,14 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>) {
385383
kw::Try => {
386384
let mut_u8 = tcx.mk_mut_ptr(tcx.types.u8);
387385
let try_fn_ty = ty::Binder::dummy(tcx.mk_fn_sig(
388-
iter::once(mut_u8),
386+
[mut_u8],
389387
tcx.mk_unit(),
390388
false,
391389
hir::Unsafety::Normal,
392390
Abi::Rust,
393391
));
394392
let catch_fn_ty = ty::Binder::dummy(tcx.mk_fn_sig(
395-
[mut_u8, mut_u8].iter().cloned(),
393+
[mut_u8, mut_u8],
396394
tcx.mk_unit(),
397395
false,
398396
hir::Unsafety::Normal,
@@ -447,7 +445,7 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>) {
447445
};
448446
(n_tps, 0, inputs, output, unsafety)
449447
};
450-
let sig = tcx.mk_fn_sig(inputs.into_iter(), output, false, unsafety, Abi::RustIntrinsic);
448+
let sig = tcx.mk_fn_sig(inputs, output, false, unsafety, Abi::RustIntrinsic);
451449
let sig = ty::Binder::bind_with_vars(sig, bound_vars);
452450
equate_intrinsic_type(tcx, it, n_tps, n_lts, sig)
453451
}
@@ -545,13 +543,7 @@ pub fn check_platform_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>)
545543
}
546544
};
547545

548-
let sig = tcx.mk_fn_sig(
549-
inputs.into_iter(),
550-
output,
551-
false,
552-
hir::Unsafety::Unsafe,
553-
Abi::PlatformIntrinsic,
554-
);
546+
let sig = tcx.mk_fn_sig(inputs, output, false, hir::Unsafety::Unsafe, Abi::PlatformIntrinsic);
555547
let sig = ty::Binder::dummy(sig);
556548
equate_intrinsic_type(tcx, it, n_tps, 0, sig)
557549
}

compiler/rustc_hir_analysis/src/lib.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@ use rustc_target::spec::abi::Abi;
113113
use rustc_trait_selection::traits::error_reporting::TypeErrCtxtExt as _;
114114
use rustc_trait_selection::traits::{self, ObligationCause, ObligationCauseCode};
115115

116-
use std::iter;
117116
use std::ops::Not;
118117

119118
use astconv::AstConv;
@@ -348,7 +347,7 @@ fn check_main_fn_ty(tcx: TyCtxt<'_>, main_def_id: DefId) {
348347
}
349348

350349
let se_ty = tcx.mk_fn_ptr(expected_return_type.map_bound(|expected_return_type| {
351-
tcx.mk_fn_sig(iter::empty(), expected_return_type, false, hir::Unsafety::Normal, Abi::Rust)
350+
tcx.mk_fn_sig([], expected_return_type, false, hir::Unsafety::Normal, Abi::Rust)
352351
}));
353352

354353
require_same_types(
@@ -434,7 +433,7 @@ fn check_start_fn_ty(tcx: TyCtxt<'_>, start_def_id: DefId) {
434433
}
435434

436435
let se_ty = tcx.mk_fn_ptr(ty::Binder::dummy(tcx.mk_fn_sig(
437-
[tcx.types.isize, tcx.mk_imm_ptr(tcx.mk_imm_ptr(tcx.types.u8))].iter().cloned(),
436+
[tcx.types.isize, tcx.mk_imm_ptr(tcx.mk_imm_ptr(tcx.types.u8))],
438437
tcx.types.isize,
439438
false,
440439
hir::Unsafety::Normal,

compiler/rustc_hir_typeck/src/check.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ fn check_lang_start_fn<'tcx>(
264264
let fn_generic = generics.param_at(0, tcx);
265265
let generic_ty = tcx.mk_ty_param(fn_generic.index, fn_generic.name);
266266
let expected_fn_sig =
267-
tcx.mk_fn_sig([].into_iter(), generic_ty, false, hir::Unsafety::Normal, Abi::Rust);
267+
tcx.mk_fn_sig([], generic_ty, false, hir::Unsafety::Normal, Abi::Rust);
268268
let expected_ty = tcx.mk_fn_ptr(Binder::dummy(expected_fn_sig));
269269

270270
// we emit the same error to suggest changing the arg no matter what's wrong with the arg

compiler/rustc_hir_typeck/src/closure.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
126126
// the `closures` table.
127127
let sig = bound_sig.map_bound(|sig| {
128128
self.tcx.mk_fn_sig(
129-
iter::once(self.tcx.intern_tup(sig.inputs())),
129+
[self.tcx.intern_tup(sig.inputs())],
130130
sig.output(),
131131
sig.c_variadic,
132132
sig.unsafety,
@@ -326,7 +326,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
326326
debug!(?ret_param_ty);
327327

328328
let sig = projection.rebind(self.tcx.mk_fn_sig(
329-
input_tys.iter(),
329+
input_tys,
330330
ret_param_ty,
331331
false,
332332
hir::Unsafety::Normal,

compiler/rustc_middle/src/ty/context.rs

+10-5
Original file line numberDiff line numberDiff line change
@@ -1660,11 +1660,11 @@ impl<'tcx> TyCtxt<'tcx> {
16601660
unsafety: hir::Unsafety,
16611661
) -> PolyFnSig<'tcx> {
16621662
sig.map_bound(|s| {
1663-
let params_iter = match s.inputs()[0].kind() {
1664-
ty::Tuple(params) => params.into_iter(),
1663+
let params = match s.inputs()[0].kind() {
1664+
ty::Tuple(params) => *params,
16651665
_ => bug!(),
16661666
};
1667-
self.mk_fn_sig(params_iter, s.output(), s.c_variadic, unsafety, abi::Abi::Rust)
1667+
self.mk_fn_sig(params, s.output(), s.c_variadic, unsafety, abi::Abi::Rust)
16681668
})
16691669
}
16701670

@@ -2215,6 +2215,11 @@ impl<'tcx> TyCtxt<'tcx> {
22152215
if ts.is_empty() { List::empty() } else { self._intern_bound_variable_kinds(ts) }
22162216
}
22172217

2218+
// Unlike various other `mk_*` functions, this one uses `I: IntoIterator`
2219+
// instead of `I: Iterator`. Unlike those other functions, this one doesn't
2220+
// have a `intern_fn_sig` variant that can be used for cases where `I` is
2221+
// something like a `Vec`. That's because of the need to combine `inputs`
2222+
// and `output`.
22182223
pub fn mk_fn_sig<I, T>(
22192224
self,
22202225
inputs: I,
@@ -2224,10 +2229,10 @@ impl<'tcx> TyCtxt<'tcx> {
22242229
abi: abi::Abi,
22252230
) -> T::Output
22262231
where
2227-
I: Iterator<Item = T>,
2232+
I: IntoIterator<Item = T>,
22282233
T: CollectAndApply<Ty<'tcx>, ty::FnSig<'tcx>>,
22292234
{
2230-
T::collect_and_apply(inputs.chain(iter::once(output)), |xs| ty::FnSig {
2235+
T::collect_and_apply(inputs.into_iter().chain(iter::once(output)), |xs| ty::FnSig {
22312236
inputs_and_output: self.intern_type_list(xs),
22322237
c_variadic,
22332238
unsafety,

compiler/rustc_symbol_mangling/src/typeid/typeid_itanium_cxx_abi.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -781,7 +781,7 @@ fn transform_ty<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, options: TransformTyOptio
781781
let output = transform_ty(tcx, fn_sig.skip_binder().output(), options);
782782
ty = tcx.mk_fn_ptr(ty::Binder::bind_with_vars(
783783
tcx.mk_fn_sig(
784-
parameters.into_iter(),
784+
parameters,
785785
output,
786786
fn_sig.c_variadic(),
787787
fn_sig.unsafety(),

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -2012,7 +2012,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
20122012
let sig = match inputs.kind() {
20132013
ty::Tuple(inputs) if infcx.tcx.is_fn_trait(trait_ref.def_id()) => {
20142014
infcx.tcx.mk_fn_sig(
2015-
inputs.iter(),
2015+
*inputs,
20162016
infcx.next_ty_var(TypeVariableOrigin {
20172017
span: DUMMY_SP,
20182018
kind: TypeVariableOriginKind::MiscVariable,
@@ -2023,7 +2023,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
20232023
)
20242024
}
20252025
_ => infcx.tcx.mk_fn_sig(
2026-
std::iter::once(inputs),
2026+
[inputs],
20272027
infcx.next_ty_var(TypeVariableOrigin {
20282028
span: DUMMY_SP,
20292029
kind: TypeVariableOriginKind::MiscVariable,

compiler/rustc_ty_utils/src/abi.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ fn fn_sig_for_fn_abi<'tcx>(
141141

142142
ty::Binder::bind_with_vars(
143143
tcx.mk_fn_sig(
144-
[env_ty, resume_ty].into_iter(),
144+
[env_ty, resume_ty],
145145
ret_ty,
146146
false,
147147
hir::Unsafety::Normal,

0 commit comments

Comments
 (0)