Skip to content

Commit ecde190

Browse files
committed
Pass correct HirId to late_bound_vars in diagnostic code
1 parent f5cd2c5 commit ecde190

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -882,7 +882,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
882882
let ty = self.lowerer().lower_ty(hir_ty);
883883
debug!(?ty, "return type (lowered)");
884884
debug!(?expected, "expected type");
885-
let bound_vars = self.tcx.late_bound_vars(hir_ty.hir_id.owner.into());
885+
let bound_vars =
886+
self.tcx.late_bound_vars(self.tcx.local_def_id_to_hir_id(fn_id));
886887
let ty = Binder::bind_with_vars(ty, bound_vars);
887888
let ty = self.normalize(hir_ty.span, ty);
888889
let ty = self.tcx.instantiate_bound_regions_with_erased(ty);

tests/ui/closures/closure-return-type-mismatch.rs

+5
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,8 @@ fn main() {
1515
b
1616
};
1717
}
18+
19+
// issue: rust-lang/rust#130858
20+
static FOO: fn() = || -> bool { 1 };
21+
//~^ ERROR mismatched types
22+
//~| ERROR mismatched types

tests/ui/closures/closure-return-type-mismatch.stderr

+19-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,21 @@
1+
error[E0308]: mismatched types
2+
--> $DIR/closure-return-type-mismatch.rs:20:33
3+
|
4+
LL | static FOO: fn() = || -> bool { 1 };
5+
| ---- ^ expected `bool`, found integer
6+
| |
7+
| expected `bool` because of return type
8+
9+
error[E0308]: mismatched types
10+
--> $DIR/closure-return-type-mismatch.rs:20:20
11+
|
12+
LL | static FOO: fn() = || -> bool { 1 };
13+
| ^^^^^^^^^^^^^^^^ expected fn pointer, found closure
14+
|
15+
= note: expected fn pointer `fn()`
16+
found closure `{closure@$DIR/closure-return-type-mismatch.rs:20:20: 20:30}`
17+
= note: closure has signature: `fn() -> bool`
18+
119
error[E0308]: mismatched types
220
--> $DIR/closure-return-type-mismatch.rs:7:9
321
|
@@ -19,6 +37,6 @@ LL | if false {
1937
LL | return "hello"
2038
| ^^^^^^^ expected `bool`, found `&str`
2139

22-
error: aborting due to 2 previous errors
40+
error: aborting due to 4 previous errors
2341

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

0 commit comments

Comments
 (0)