Skip to content

Commit cd89978

Browse files
Generalize same_type_modulo_infer
1 parent 8926dac commit cd89978

File tree

2 files changed

+34
-5
lines changed

2 files changed

+34
-5
lines changed

compiler/rustc_infer/src/infer/error_reporting/mod.rs

+34-3
Original file line numberDiff line numberDiff line change
@@ -2670,8 +2670,18 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
26702670
/// Float types, respectively). When comparing two ADTs, these rules apply recursively.
26712671
pub fn same_type_modulo_infer(&self, a: Ty<'tcx>, b: Ty<'tcx>) -> bool {
26722672
let (a, b) = self.resolve_vars_if_possible((a, b));
2673-
match (&a.kind(), &b.kind()) {
2674-
(&ty::Adt(did_a, substs_a), &ty::Adt(did_b, substs_b)) => {
2673+
match (a.kind(), b.kind()) {
2674+
(&ty::Adt(def_a, substs_a), &ty::Adt(def_b, substs_b)) => {
2675+
if def_a != def_b {
2676+
return false;
2677+
}
2678+
2679+
substs_a
2680+
.types()
2681+
.zip(substs_b.types())
2682+
.all(|(a, b)| self.same_type_modulo_infer(a, b))
2683+
}
2684+
(&ty::FnDef(did_a, substs_a), &ty::FnDef(did_b, substs_b)) => {
26752685
if did_a != did_b {
26762686
return false;
26772687
}
@@ -2694,7 +2704,28 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
26942704
| (&ty::Infer(ty::InferTy::TyVar(_)), _)
26952705
| (_, &ty::Infer(ty::InferTy::TyVar(_))) => true,
26962706
(&ty::Ref(_, ty_a, mut_a), &ty::Ref(_, ty_b, mut_b)) => {
2697-
mut_a == mut_b && self.same_type_modulo_infer(*ty_a, *ty_b)
2707+
mut_a == mut_b && self.same_type_modulo_infer(ty_a, ty_b)
2708+
}
2709+
(&ty::RawPtr(a), &ty::RawPtr(b)) => {
2710+
a.mutbl == b.mutbl && self.same_type_modulo_infer(a.ty, b.ty)
2711+
}
2712+
(&ty::Slice(a), &ty::Slice(b)) => self.same_type_modulo_infer(a, b),
2713+
(&ty::Array(a_ty, a_ct), &ty::Array(b_ty, b_ct)) => {
2714+
self.same_type_modulo_infer(a_ty, b_ty) && a_ct == b_ct
2715+
}
2716+
(&ty::Tuple(a), &ty::Tuple(b)) => {
2717+
if a.len() != b.len() {
2718+
return false;
2719+
}
2720+
std::iter::zip(a.iter(), b.iter()).all(|(a, b)| self.same_type_modulo_infer(a, b))
2721+
}
2722+
(&ty::FnPtr(a), &ty::FnPtr(b)) => {
2723+
let a = a.skip_binder().inputs_and_output;
2724+
let b = b.skip_binder().inputs_and_output;
2725+
if a.len() != b.len() {
2726+
return false;
2727+
}
2728+
std::iter::zip(a.iter(), b.iter()).all(|(a, b)| self.same_type_modulo_infer(a, b))
26982729
}
26992730
// FIXME(compiler-errors): This needs to be generalized more
27002731
_ => a == b,

src/test/ui/issues/issue-59494.stderr

-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ LL | let t8 = t8n(t7, t7p(f, g));
77
| required by a bound introduced by this call
88
|
99
= help: the trait `Fn<(_,)>` is not implemented for `impl Fn(((_, _), _))`
10-
= note: expected a closure with arguments `(((_, _), _),)`
11-
found a closure with arguments `(_,)`
1210
note: required by a bound in `t8n`
1311
--> $DIR/issue-59494.rs:5:45
1412
|

0 commit comments

Comments
 (0)