Skip to content

Commit

Permalink
Generalize same_type_modulo_infer
Browse files Browse the repository at this point in the history
  • Loading branch information
compiler-errors committed Jul 21, 2022
1 parent 8926dac commit cd89978
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 5 deletions.
37 changes: 34 additions & 3 deletions compiler/rustc_infer/src/infer/error_reporting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2670,8 +2670,18 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
/// Float types, respectively). When comparing two ADTs, these rules apply recursively.
pub fn same_type_modulo_infer(&self, a: Ty<'tcx>, b: Ty<'tcx>) -> bool {
let (a, b) = self.resolve_vars_if_possible((a, b));
match (&a.kind(), &b.kind()) {
(&ty::Adt(did_a, substs_a), &ty::Adt(did_b, substs_b)) => {
match (a.kind(), b.kind()) {
(&ty::Adt(def_a, substs_a), &ty::Adt(def_b, substs_b)) => {
if def_a != def_b {
return false;
}

substs_a
.types()
.zip(substs_b.types())
.all(|(a, b)| self.same_type_modulo_infer(a, b))
}
(&ty::FnDef(did_a, substs_a), &ty::FnDef(did_b, substs_b)) => {
if did_a != did_b {
return false;
}
Expand All @@ -2694,7 +2704,28 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
| (&ty::Infer(ty::InferTy::TyVar(_)), _)
| (_, &ty::Infer(ty::InferTy::TyVar(_))) => true,
(&ty::Ref(_, ty_a, mut_a), &ty::Ref(_, ty_b, mut_b)) => {
mut_a == mut_b && self.same_type_modulo_infer(*ty_a, *ty_b)
mut_a == mut_b && self.same_type_modulo_infer(ty_a, ty_b)
}
(&ty::RawPtr(a), &ty::RawPtr(b)) => {
a.mutbl == b.mutbl && self.same_type_modulo_infer(a.ty, b.ty)
}
(&ty::Slice(a), &ty::Slice(b)) => self.same_type_modulo_infer(a, b),
(&ty::Array(a_ty, a_ct), &ty::Array(b_ty, b_ct)) => {
self.same_type_modulo_infer(a_ty, b_ty) && a_ct == b_ct
}
(&ty::Tuple(a), &ty::Tuple(b)) => {
if a.len() != b.len() {
return false;
}
std::iter::zip(a.iter(), b.iter()).all(|(a, b)| self.same_type_modulo_infer(a, b))
}
(&ty::FnPtr(a), &ty::FnPtr(b)) => {
let a = a.skip_binder().inputs_and_output;
let b = b.skip_binder().inputs_and_output;
if a.len() != b.len() {
return false;
}
std::iter::zip(a.iter(), b.iter()).all(|(a, b)| self.same_type_modulo_infer(a, b))
}
// FIXME(compiler-errors): This needs to be generalized more
_ => a == b,
Expand Down
2 changes: 0 additions & 2 deletions src/test/ui/issues/issue-59494.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ LL | let t8 = t8n(t7, t7p(f, g));
| required by a bound introduced by this call
|
= help: the trait `Fn<(_,)>` is not implemented for `impl Fn(((_, _), _))`
= note: expected a closure with arguments `(((_, _), _),)`
found a closure with arguments `(_,)`
note: required by a bound in `t8n`
--> $DIR/issue-59494.rs:5:45
|
Expand Down

0 comments on commit cd89978

Please sign in to comment.