Skip to content

Commit

Permalink
Rollup merge of #130879 - fmease:fix-diag-ice, r=compiler-errors
Browse files Browse the repository at this point in the history
Pass correct HirId to late_bound_vars in diagnostic code

Fixes #130858.
Fixes #125655.
Fixes #130391.
Fixes #130663.

r? compiler-errors
  • Loading branch information
GuillaumeGomez authored Sep 26, 2024
2 parents 18dfee0 + e29ff8c commit ed902a8
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 10 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
8 changes: 0 additions & 8 deletions tests/crashes/125655.rs

This file was deleted.

15 changes: 15 additions & 0 deletions tests/ui/closures/binder/closure-return-type-mismatch.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// We used to bind the closure return type `&'a ()` with the late-bound vars of
// the owner (here `main` & `env` resp.) instead of the ones of the enclosing
// function-like / closure inside diagnostic code which was incorrect.

#![feature(closure_lifetime_binder)]

// issue: rust-lang/rust#130391
fn main() {
let _ = for<'a> |x: &'a u8| -> &'a () { x }; //~ ERROR mismatched types
}

// issue: rust-lang/rust#130663
fn env<'r>() {
let _ = for<'a> |x: &'a u8| -> &'a () { x }; //~ ERROR mismatched types
}
25 changes: 25 additions & 0 deletions tests/ui/closures/binder/closure-return-type-mismatch.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
error[E0308]: mismatched types
--> $DIR/closure-return-type-mismatch.rs:9:45
|
LL | let _ = for<'a> |x: &'a u8| -> &'a () { x };
| ------ ^ expected `&()`, found `&u8`
| |
| expected `&'a ()` because of return type
|
= note: expected reference `&'a ()`
found reference `&'a u8`

error[E0308]: mismatched types
--> $DIR/closure-return-type-mismatch.rs:14:45
|
LL | let _ = for<'a> |x: &'a u8| -> &'a () { x };
| ------ ^ expected `&()`, found `&u8`
| |
| expected `&'a ()` because of return type
|
= note: expected reference `&'a ()`
found reference `&'a u8`

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0308`.
4 changes: 4 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,7 @@ fn main() {
b
};
}

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

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

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

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

0 comments on commit ed902a8

Please sign in to comment.