Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Generalize same_type_modulo_infer
  • Loading branch information
compiler-errors committed Jul 21, 2022
commit cd89978d869587fc025286b0326116819d5b78e4
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 `(_,)`
Comment on lines -10 to -11
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting regression 🤔

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not a regression, per se. The original note was nonsense, because the reason that this impl Fn(((_, _), _)) does not implement Fn<(_,)> is unrelated to arg mismatch and has to do with some cyclical closure stuff. This was just revealed because now (((_, _), _),) and (_,) are "same type modulo infer".

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah! I see. Neat.

note: required by a bound in `t8n`
--> $DIR/issue-59494.rs:5:45
|
Expand Down