Skip to content

Commit

Permalink
Pass correct HirId to late_bound_vars in diagnostic code
Browse files Browse the repository at this point in the history
  • Loading branch information
fmease committed Sep 26, 2024
1 parent f5cd2c5 commit ecde190
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
3 changes: 2 additions & 1 deletion compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -882,7 +882,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let ty = self.lowerer().lower_ty(hir_ty);
debug!(?ty, "return type (lowered)");
debug!(?expected, "expected type");
let bound_vars = self.tcx.late_bound_vars(hir_ty.hir_id.owner.into());
let bound_vars =
self.tcx.late_bound_vars(self.tcx.local_def_id_to_hir_id(fn_id));
let ty = Binder::bind_with_vars(ty, bound_vars);
let ty = self.normalize(hir_ty.span, ty);
let ty = self.tcx.instantiate_bound_regions_with_erased(ty);
Expand Down
5 changes: 5 additions & 0 deletions tests/ui/closures/closure-return-type-mismatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,8 @@ fn main() {
b
};
}

// issue: rust-lang/rust#130858
static FOO: fn() = || -> bool { 1 };
//~^ ERROR mismatched types
//~| ERROR mismatched types
20 changes: 19 additions & 1 deletion tests/ui/closures/closure-return-type-mismatch.stderr
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
error[E0308]: mismatched types
--> $DIR/closure-return-type-mismatch.rs:20:33
|
LL | static FOO: fn() = || -> bool { 1 };
| ---- ^ expected `bool`, found integer
| |
| expected `bool` because of return type

error[E0308]: mismatched types
--> $DIR/closure-return-type-mismatch.rs:20:20
|
LL | static FOO: fn() = || -> bool { 1 };
| ^^^^^^^^^^^^^^^^ expected fn pointer, found closure
|
= note: expected fn pointer `fn()`
found closure `{closure@$DIR/closure-return-type-mismatch.rs:20:20: 20:30}`
= note: closure has signature: `fn() -> bool`

error[E0308]: mismatched types
--> $DIR/closure-return-type-mismatch.rs:7:9
|
Expand All @@ -19,6 +37,6 @@ LL | if false {
LL | return "hello"
| ^^^^^^^ expected `bool`, found `&str`

error: aborting due to 2 previous errors
error: aborting due to 4 previous errors

For more information about this error, try `rustc --explain E0308`.

0 comments on commit ecde190

Please sign in to comment.