Use IntoIterator for mk_fn_sig.

This makes a lot of call sites nicer.
This commit is contained in:
Nicholas Nethercote 2023-02-16 16:05:08 +11:00
parent c8237db3ee
commit 2017aeff88
11 changed files with 28 additions and 35 deletions

View File

@ -27,8 +27,6 @@
use std::cell::RefCell;
use std::ffi::CString;
use std::iter;
pub mod mapgen;
const UNUSED_FUNCTION_COUNTER_ID: CounterValueReference = CounterValueReference::START;
@ -201,7 +199,7 @@ fn declare_unused_fn<'tcx>(cx: &CodegenCx<'_, 'tcx>, def_id: DefId) -> Instance<
tcx.symbol_name(instance).name,
cx.fn_abi_of_fn_ptr(
ty::Binder::dummy(tcx.mk_fn_sig(
iter::once(tcx.mk_unit()),
[tcx.mk_unit()],
tcx.mk_unit(),
false,
hir::Unsafety::Unsafe,

View File

@ -22,7 +22,6 @@
use rustc_target::spec::{HasTargetSpec, PanicStrategy};
use std::cmp::Ordering;
use std::iter;
fn get_simple_intrinsic<'ll>(
cx: &CodegenCx<'ll, '_>,
@ -798,7 +797,7 @@ fn get_rust_try_fn<'ll, 'tcx>(
let i8p = tcx.mk_mut_ptr(tcx.types.i8);
// `unsafe fn(*mut i8) -> ()`
let try_fn_ty = tcx.mk_fn_ptr(ty::Binder::dummy(tcx.mk_fn_sig(
iter::once(i8p),
[i8p],
tcx.mk_unit(),
false,
hir::Unsafety::Unsafe,
@ -806,7 +805,7 @@ fn get_rust_try_fn<'ll, 'tcx>(
)));
// `unsafe fn(*mut i8, *mut i8) -> ()`
let catch_fn_ty = tcx.mk_fn_ptr(ty::Binder::dummy(tcx.mk_fn_sig(
[i8p, i8p].iter().cloned(),
[i8p, i8p],
tcx.mk_unit(),
false,
hir::Unsafety::Unsafe,
@ -814,7 +813,7 @@ fn get_rust_try_fn<'ll, 'tcx>(
)));
// `unsafe fn(unsafe fn(*mut i8) -> (), *mut i8, unsafe fn(*mut i8, *mut i8) -> ()) -> i32`
let rust_fn_sig = ty::Binder::dummy(cx.tcx.mk_fn_sig(
[try_fn_ty, i8p, catch_fn_ty].into_iter(),
[try_fn_ty, i8p, catch_fn_ty],
tcx.types.i32,
false,
hir::Unsafety::Unsafe,

View File

@ -3109,7 +3109,7 @@ pub fn ty_of_fn(
debug!(?output_ty);
let fn_ty = tcx.mk_fn_sig(input_tys.into_iter(), output_ty, decl.c_variadic, unsafety, abi);
let fn_ty = tcx.mk_fn_sig(input_tys, output_ty, decl.c_variadic, unsafety, abi);
let bare_fn_ty = ty::Binder::bind_with_vars(fn_ty, bound_vars);
if !self.allow_ty_infer() && !(visitor.0.is_empty() && infer_replacements.is_empty()) {

View File

@ -15,8 +15,6 @@
use rustc_span::symbol::{kw, sym, Symbol};
use rustc_target::spec::abi::Abi;
use std::iter;
fn equate_intrinsic_type<'tcx>(
tcx: TyCtxt<'tcx>,
it: &hir::ForeignItem<'_>,
@ -385,14 +383,14 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>) {
kw::Try => {
let mut_u8 = tcx.mk_mut_ptr(tcx.types.u8);
let try_fn_ty = ty::Binder::dummy(tcx.mk_fn_sig(
iter::once(mut_u8),
[mut_u8],
tcx.mk_unit(),
false,
hir::Unsafety::Normal,
Abi::Rust,
));
let catch_fn_ty = ty::Binder::dummy(tcx.mk_fn_sig(
[mut_u8, mut_u8].iter().cloned(),
[mut_u8, mut_u8],
tcx.mk_unit(),
false,
hir::Unsafety::Normal,
@ -447,7 +445,7 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>) {
};
(n_tps, 0, inputs, output, unsafety)
};
let sig = tcx.mk_fn_sig(inputs.into_iter(), output, false, unsafety, Abi::RustIntrinsic);
let sig = tcx.mk_fn_sig(inputs, output, false, unsafety, Abi::RustIntrinsic);
let sig = ty::Binder::bind_with_vars(sig, bound_vars);
equate_intrinsic_type(tcx, it, n_tps, n_lts, sig)
}
@ -545,13 +543,7 @@ pub fn check_platform_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>)
}
};
let sig = tcx.mk_fn_sig(
inputs.into_iter(),
output,
false,
hir::Unsafety::Unsafe,
Abi::PlatformIntrinsic,
);
let sig = tcx.mk_fn_sig(inputs, output, false, hir::Unsafety::Unsafe, Abi::PlatformIntrinsic);
let sig = ty::Binder::dummy(sig);
equate_intrinsic_type(tcx, it, n_tps, 0, sig)
}

View File

@ -113,7 +113,6 @@
use rustc_trait_selection::traits::error_reporting::TypeErrCtxtExt as _;
use rustc_trait_selection::traits::{self, ObligationCause, ObligationCauseCode};
use std::iter;
use std::ops::Not;
use astconv::AstConv;
@ -348,7 +347,7 @@ fn main_fn_return_type_span(tcx: TyCtxt<'_>, def_id: DefId) -> Option<Span> {
}
let se_ty = tcx.mk_fn_ptr(expected_return_type.map_bound(|expected_return_type| {
tcx.mk_fn_sig(iter::empty(), expected_return_type, false, hir::Unsafety::Normal, Abi::Rust)
tcx.mk_fn_sig([], expected_return_type, false, hir::Unsafety::Normal, Abi::Rust)
}));
require_same_types(
@ -434,7 +433,7 @@ fn check_start_fn_ty(tcx: TyCtxt<'_>, start_def_id: DefId) {
}
let se_ty = tcx.mk_fn_ptr(ty::Binder::dummy(tcx.mk_fn_sig(
[tcx.types.isize, tcx.mk_imm_ptr(tcx.mk_imm_ptr(tcx.types.u8))].iter().cloned(),
[tcx.types.isize, tcx.mk_imm_ptr(tcx.mk_imm_ptr(tcx.types.u8))],
tcx.types.isize,
false,
hir::Unsafety::Normal,

View File

@ -264,7 +264,7 @@ fn check_lang_start_fn<'tcx>(
let fn_generic = generics.param_at(0, tcx);
let generic_ty = tcx.mk_ty_param(fn_generic.index, fn_generic.name);
let expected_fn_sig =
tcx.mk_fn_sig([].into_iter(), generic_ty, false, hir::Unsafety::Normal, Abi::Rust);
tcx.mk_fn_sig([], generic_ty, false, hir::Unsafety::Normal, Abi::Rust);
let expected_ty = tcx.mk_fn_ptr(Binder::dummy(expected_fn_sig));
// we emit the same error to suggest changing the arg no matter what's wrong with the arg

View File

@ -126,7 +126,7 @@ fn check_closure(
// the `closures` table.
let sig = bound_sig.map_bound(|sig| {
self.tcx.mk_fn_sig(
iter::once(self.tcx.intern_tup(sig.inputs())),
[self.tcx.intern_tup(sig.inputs())],
sig.output(),
sig.c_variadic,
sig.unsafety,
@ -326,7 +326,7 @@ fn deduce_sig_from_projection(
debug!(?ret_param_ty);
let sig = projection.rebind(self.tcx.mk_fn_sig(
input_tys.iter(),
input_tys,
ret_param_ty,
false,
hir::Unsafety::Normal,

View File

@ -1660,11 +1660,11 @@ pub fn signature_unclosure(
unsafety: hir::Unsafety,
) -> PolyFnSig<'tcx> {
sig.map_bound(|s| {
let params_iter = match s.inputs()[0].kind() {
ty::Tuple(params) => params.into_iter(),
let params = match s.inputs()[0].kind() {
ty::Tuple(params) => *params,
_ => bug!(),
};
self.mk_fn_sig(params_iter, s.output(), s.c_variadic, unsafety, abi::Abi::Rust)
self.mk_fn_sig(params, s.output(), s.c_variadic, unsafety, abi::Abi::Rust)
})
}
@ -2215,6 +2215,11 @@ pub fn intern_bound_variable_kinds(
if ts.is_empty() { List::empty() } else { self._intern_bound_variable_kinds(ts) }
}
// Unlike various other `mk_*` functions, this one uses `I: IntoIterator`
// instead of `I: Iterator`. Unlike those other functions, this one doesn't
// have a `intern_fn_sig` variant that can be used for cases where `I` is
// something like a `Vec`. That's because of the need to combine `inputs`
// and `output`.
pub fn mk_fn_sig<I, T>(
self,
inputs: I,
@ -2224,10 +2229,10 @@ pub fn mk_fn_sig<I, T>(
abi: abi::Abi,
) -> T::Output
where
I: Iterator<Item = T>,
I: IntoIterator<Item = T>,
T: CollectAndApply<Ty<'tcx>, ty::FnSig<'tcx>>,
{
T::collect_and_apply(inputs.chain(iter::once(output)), |xs| ty::FnSig {
T::collect_and_apply(inputs.into_iter().chain(iter::once(output)), |xs| ty::FnSig {
inputs_and_output: self.intern_type_list(xs),
c_variadic,
unsafety,

View File

@ -781,7 +781,7 @@ fn transform_ty<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, options: TransformTyOptio
let output = transform_ty(tcx, fn_sig.skip_binder().output(), options);
ty = tcx.mk_fn_ptr(ty::Binder::bind_with_vars(
tcx.mk_fn_sig(
parameters.into_iter(),
parameters,
output,
fn_sig.c_variadic(),
fn_sig.unsafety(),

View File

@ -2012,7 +2012,7 @@ pub(crate) fn build_fn_sig_ty<'tcx>(
let sig = match inputs.kind() {
ty::Tuple(inputs) if infcx.tcx.is_fn_trait(trait_ref.def_id()) => {
infcx.tcx.mk_fn_sig(
inputs.iter(),
*inputs,
infcx.next_ty_var(TypeVariableOrigin {
span: DUMMY_SP,
kind: TypeVariableOriginKind::MiscVariable,
@ -2023,7 +2023,7 @@ pub(crate) fn build_fn_sig_ty<'tcx>(
)
}
_ => infcx.tcx.mk_fn_sig(
std::iter::once(inputs),
[inputs],
infcx.next_ty_var(TypeVariableOrigin {
span: DUMMY_SP,
kind: TypeVariableOriginKind::MiscVariable,

View File

@ -141,7 +141,7 @@ fn fn_sig_for_fn_abi<'tcx>(
ty::Binder::bind_with_vars(
tcx.mk_fn_sig(
[env_ty, resume_ty].into_iter(),
[env_ty, resume_ty],
ret_ty,
false,
hir::Unsafety::Normal,