Skip to content

Commit 4457679

Browse files
authored
Unrolled build for rust-lang#130879
Rollup merge of rust-lang#130879 - fmease:fix-diag-ice, r=compiler-errors Pass correct HirId to late_bound_vars in diagnostic code Fixes rust-lang#130858. Fixes rust-lang#125655. Fixes rust-lang#130391. Fixes rust-lang#130663. r? compiler-errors
2 parents 2bd1e89 + e29ff8c commit 4457679

File tree

6 files changed

+55
-10
lines changed

6 files changed

+55
-10
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/crashes/125655.rs

-8
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// We used to bind the closure return type `&'a ()` with the late-bound vars of
2+
// the owner (here `main` & `env` resp.) instead of the ones of the enclosing
3+
// function-like / closure inside diagnostic code which was incorrect.
4+
5+
#![feature(closure_lifetime_binder)]
6+
7+
// issue: rust-lang/rust#130391
8+
fn main() {
9+
let _ = for<'a> |x: &'a u8| -> &'a () { x }; //~ ERROR mismatched types
10+
}
11+
12+
// issue: rust-lang/rust#130663
13+
fn env<'r>() {
14+
let _ = for<'a> |x: &'a u8| -> &'a () { x }; //~ ERROR mismatched types
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
error[E0308]: mismatched types
2+
--> $DIR/closure-return-type-mismatch.rs:9:45
3+
|
4+
LL | let _ = for<'a> |x: &'a u8| -> &'a () { x };
5+
| ------ ^ expected `&()`, found `&u8`
6+
| |
7+
| expected `&'a ()` because of return type
8+
|
9+
= note: expected reference `&'a ()`
10+
found reference `&'a u8`
11+
12+
error[E0308]: mismatched types
13+
--> $DIR/closure-return-type-mismatch.rs:14:45
14+
|
15+
LL | let _ = for<'a> |x: &'a u8| -> &'a () { x };
16+
| ------ ^ expected `&()`, found `&u8`
17+
| |
18+
| expected `&'a ()` because of return type
19+
|
20+
= note: expected reference `&'a ()`
21+
found reference `&'a u8`
22+
23+
error: aborting due to 2 previous errors
24+
25+
For more information about this error, try `rustc --explain E0308`.

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

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

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

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
error[E0308]: mismatched types
2+
--> $DIR/closure-return-type-mismatch.rs:20:41
3+
|
4+
LL | static FOO: fn() -> bool = || -> bool { 1 };
5+
| ---- ^ expected `bool`, found integer
6+
| |
7+
| expected `bool` because of return type
8+
19
error[E0308]: mismatched types
210
--> $DIR/closure-return-type-mismatch.rs:7:9
311
|
@@ -19,6 +27,6 @@ LL | if false {
1927
LL | return "hello"
2028
| ^^^^^^^ expected `bool`, found `&str`
2129

22-
error: aborting due to 2 previous errors
30+
error: aborting due to 3 previous errors
2331

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

0 commit comments

Comments
 (0)