Split split_inputs_and_output in two.

I think it's a little clearer and nicer that way.
This commit is contained in:
Nicholas Nethercote 2024-08-09 10:01:59 +10:00
parent 3fc5469a8d
commit 8640998869
3 changed files with 13 additions and 11 deletions

View File

@ -1955,9 +1955,12 @@ impl<'tcx> Ty<'tcx> {
}
impl<'tcx> rustc_type_ir::inherent::Tys<TyCtxt<'tcx>> for &'tcx ty::List<Ty<'tcx>> {
fn split_inputs_and_output(self) -> (&'tcx [Ty<'tcx>], Ty<'tcx>) {
let (output, inputs) = self.split_last().unwrap();
(inputs, *output)
fn inputs(self) -> &'tcx [Ty<'tcx>] {
self.split_last().unwrap().1
}
fn output(self) -> Ty<'tcx> {
*self.split_last().unwrap().0
}
}

View File

@ -203,7 +203,9 @@ pub trait Ty<I: Interner<Ty = Self>>:
pub trait Tys<I: Interner<Tys = Self>>:
Copy + Debug + Hash + Eq + SliceLike<Item = I::Ty> + TypeFoldable<I> + Default
{
fn split_inputs_and_output(self) -> (I::FnInputTys, I::Ty);
fn inputs(self) -> I::FnInputTys;
fn output(self) -> I::Ty;
}
pub trait Abi<I: Interner<Abi = Self>>: Copy + Debug + Hash + Eq + Relate<I> {

View File

@ -868,16 +868,12 @@ pub struct FnSig<I: Interner> {
}
impl<I: Interner> FnSig<I> {
pub fn split_inputs_and_output(self) -> (I::FnInputTys, I::Ty) {
self.inputs_and_output.split_inputs_and_output()
}
pub fn inputs(self) -> I::FnInputTys {
self.split_inputs_and_output().0
self.inputs_and_output.inputs()
}
pub fn output(self) -> I::Ty {
self.split_inputs_and_output().1
self.inputs_and_output.output()
}
pub fn is_fn_trait_compatible(self) -> bool {
@ -935,7 +931,7 @@ impl<I: Interner> fmt::Debug for FnSig<I> {
}
write!(f, "fn(")?;
let (inputs, output) = sig.split_inputs_and_output();
let inputs = sig.inputs();
for (i, ty) in inputs.iter().enumerate() {
if i > 0 {
write!(f, ", ")?;
@ -951,6 +947,7 @@ impl<I: Interner> fmt::Debug for FnSig<I> {
}
write!(f, ")")?;
let output = sig.output();
match output.kind() {
Tuple(list) if list.is_empty() => Ok(()),
_ => write!(f, " -> {:?}", sig.output()),