Skip to content

Commit

Permalink
Also migrate FnInputTys
Browse files Browse the repository at this point in the history
  • Loading branch information
compiler-errors committed Jun 21, 2024
1 parent 0bee86a commit 0770597
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ pub(in crate::solve) fn extract_tupled_inputs_and_output_from_callable<I: Intern
if sig.skip_binder().is_fn_trait_compatible() && !tcx.has_target_features(def_id) {
Ok(Some(
sig.instantiate(tcx, args)
.map_bound(|sig| (Ty::new_tup(tcx, &sig.inputs()), sig.output())),
.map_bound(|sig| (Ty::new_tup(tcx, sig.inputs().as_slice()), sig.output())),
))
} else {
Err(NoSolution)
Expand All @@ -267,7 +267,9 @@ pub(in crate::solve) fn extract_tupled_inputs_and_output_from_callable<I: Intern
// keep this in sync with assemble_fn_pointer_candidates until the old solver is removed.
ty::FnPtr(sig) => {
if sig.is_fn_trait_compatible() {
Ok(Some(sig.map_bound(|sig| (Ty::new_tup(tcx, &sig.inputs()), sig.output()))))
Ok(Some(
sig.map_bound(|sig| (Ty::new_tup(tcx, sig.inputs().as_slice()), sig.output())),
))
} else {
Err(NoSolution)
}
Expand All @@ -290,7 +292,9 @@ pub(in crate::solve) fn extract_tupled_inputs_and_output_from_callable<I: Intern
}
}
}
Ok(Some(closure_args.sig().map_bound(|sig| (sig.inputs()[0], sig.output()))))
Ok(Some(
closure_args.sig().map_bound(|sig| (sig.inputs().get(0).unwrap(), sig.output())),
))
}

// Coroutine-closures don't implement `Fn` traits the normal way.
Expand Down Expand Up @@ -468,7 +472,7 @@ pub(in crate::solve) fn extract_tupled_inputs_and_output_from_async_callable<I:
let future_output_ty = Ty::new_projection(tcx, future_output_def_id, [sig.output()]);
Ok((
bound_sig.rebind(AsyncCallableRelevantTypes {
tupled_inputs_ty: Ty::new_tup(tcx, &sig.inputs()),
tupled_inputs_ty: Ty::new_tup(tcx, sig.inputs().as_slice()),
output_coroutine_ty: sig.output(),
coroutine_return_ty: future_output_ty,
}),
Expand Down Expand Up @@ -519,7 +523,7 @@ pub(in crate::solve) fn extract_tupled_inputs_and_output_from_async_callable<I:
let future_output_ty = Ty::new_projection(tcx, future_output_def_id, [sig.output()]);
Ok((
bound_sig.rebind(AsyncCallableRelevantTypes {
tupled_inputs_ty: sig.inputs()[0],
tupled_inputs_ty: sig.inputs().get(0).unwrap(),
output_coroutine_ty: sig.output(),
coroutine_return_ty: future_output_ty,
}),
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_type_ir/src/interner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ pub trait Interner:
// Kinds of tys
type Ty: Ty<Self>;
type Tys: Tys<Self>;
type FnInputTys: Copy + Debug + Hash + Eq + Deref<Target = [Self::Ty]> + TypeVisitable<Self>;
type FnInputTys: Copy + Debug + Hash + Eq + SliceLike<Item = Self::Ty> + TypeVisitable<Self>;
type ParamTy: Copy + Debug + Hash + Eq + ParamLike;
type BoundTy: Copy + Debug + Hash + Eq + BoundVarLike<Self>;
type PlaceholderTy: PlaceholderLike;
Expand Down
2 changes: 0 additions & 2 deletions compiler/rustc_type_ir/src/predicate_kind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ impl std::fmt::Display for AliasRelationDirection {
}
}

// FIXME: Convert to DebugWithInfcx impl
impl<I: Interner> fmt::Debug for ClauseKind<I> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Expand All @@ -144,7 +143,6 @@ impl<I: Interner> fmt::Debug for ClauseKind<I> {
}
}

// FIXME: Convert to DebugWithInfcx impl
impl<I: Interner> fmt::Debug for PredicateKind<I> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_type_ir/src/relate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,8 @@ impl<I: Interner> Relate<I> for ty::FnSig<I> {
return Err(TypeError::ArgCount);
}

let inputs_and_output = iter::zip(a_inputs.iter(), b_inputs.iter())
.map(|(&a, &b)| ((a, b), false))
let inputs_and_output = iter::zip(a_inputs.into_iter(), b_inputs.into_iter())
.map(|(a, b)| ((a, b), false))
.chain(iter::once(((a.output(), b.output()), true)))
.map(|((a, b), is_output)| {
if is_output {
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_type_ir/src/ty_kind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1005,7 +1005,7 @@ impl<I: Interner> ty::Binder<I, FnSig<I>> {
#[inline]
#[track_caller]
pub fn input(self, index: usize) -> ty::Binder<I, I::Ty> {
self.map_bound(|fn_sig| fn_sig.inputs()[index])
self.map_bound(|fn_sig| fn_sig.inputs().get(index).unwrap())
}

pub fn inputs_and_output(self) -> ty::Binder<I, I::Tys> {
Expand Down Expand Up @@ -1046,7 +1046,7 @@ impl<I: Interner> fmt::Debug for FnSig<I> {

write!(f, "fn(")?;
let (inputs, output) = sig.split_inputs_and_output();
for (i, ty) in inputs.iter().enumerate() {
for (i, ty) in inputs.into_iter().enumerate() {
if i > 0 {
write!(f, ", ")?;
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_type_ir/src/ty_kind/closure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ impl<I: Interner> CoroutineClosureArgs<I> {
let interior = self.coroutine_witness_ty();
let ty::FnPtr(sig) = self.signature_parts_ty().kind() else { panic!() };
sig.map_bound(|sig| {
let [resume_ty, tupled_inputs_ty] = *sig.inputs() else {
let [resume_ty, tupled_inputs_ty] = *sig.inputs().as_slice() else {
panic!();
};
let [yield_ty, return_ty] = *sig.output().tuple_fields().as_slice() else { panic!() };
Expand Down

0 comments on commit 0770597

Please sign in to comment.