-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
On type error involving closure, avoid ICE
When we encounter a type error involving a closure, we try to typeck prior closure invocations to see if they influenced the current expected type. When trying to do so, ensure that the closure was defined in our current scope. Fix #116658.
- Loading branch information
Showing
3 changed files
with
69 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
tests/ui/unboxed-closures/unboxed-closures-type-mismatch-closure-from-another-scope.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
fn test() { | ||
let x = match **x { //~ ERROR | ||
Some(&a) if { panic!() } => {} | ||
}; | ||
let mut p = &x; | ||
|
||
{ | ||
let mut closure = expect_sig(|p, y| *p = y); | ||
closure(&mut p, &y); //~ ERROR | ||
//~^ ERROR | ||
} | ||
|
||
deref(p); //~ ERROR | ||
} | ||
|
||
fn expect_sig<F>(f: F) -> F | ||
where | ||
F: FnMut(&mut &i32, &i32), | ||
{ | ||
f | ||
} | ||
|
||
fn main() {} |
44 changes: 44 additions & 0 deletions
44
tests/ui/unboxed-closures/unboxed-closures-type-mismatch-closure-from-another-scope.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
error[E0425]: cannot find value `x` in this scope | ||
--> $DIR/unboxed-closures-type-mismatch-closure-from-another-scope.rs:2:21 | ||
| | ||
LL | let x = match **x { | ||
| ^ not found in this scope | ||
|
||
error[E0425]: cannot find value `y` in this scope | ||
--> $DIR/unboxed-closures-type-mismatch-closure-from-another-scope.rs:9:26 | ||
| | ||
LL | closure(&mut p, &y); | ||
| ^ help: a local variable with a similar name exists: `p` | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/unboxed-closures-type-mismatch-closure-from-another-scope.rs:9:17 | ||
| | ||
LL | closure(&mut p, &y); | ||
| ------- ^^^^^^ expected `&mut &i32`, found `&mut &()` | ||
| | | ||
| arguments to this function are incorrect | ||
| | ||
= note: expected mutable reference `&mut &i32` | ||
found mutable reference `&mut &()` | ||
note: closure parameter defined here | ||
--> $DIR/unboxed-closures-type-mismatch-closure-from-another-scope.rs:8:39 | ||
| | ||
LL | let mut closure = expect_sig(|p, y| *p = y); | ||
| ^ | ||
|
||
error[E0425]: cannot find function `deref` in this scope | ||
--> $DIR/unboxed-closures-type-mismatch-closure-from-another-scope.rs:13:5 | ||
| | ||
LL | deref(p); | ||
| ^^^^^ not found in this scope | ||
| | ||
help: use the `.` operator to call the method `Deref::deref` on `&&()` | ||
| | ||
LL - deref(p); | ||
LL + p.deref(); | ||
| | ||
|
||
error: aborting due to 4 previous errors | ||
|
||
Some errors have detailed explanations: E0308, E0425. | ||
For more information about an error, try `rustc --explain E0308`. |