Skip to content

Commit 028e00b

Browse files
committed
Add a test for an ICE with closure captures in erroneous code
1 parent 61807c5 commit 028e00b

2 files changed

Lines changed: 55 additions & 0 deletions

File tree

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//! Regression test for <https://github.com/rust-lang/rust/issues/119382>.
2+
//!
3+
//! The `-Wrust-2021-incompatible-closure-captures` lint used to ICE
4+
//! when applied to erroneous code.
5+
6+
//@ edition: 2018
7+
//@ compile-flags: -Wrust-2021-incompatible-closure-captures
8+
9+
struct V(&mut i32);
10+
//~^ ERROR missing lifetime specifier
11+
12+
fn nested(v: &V) {
13+
|| {
14+
V(_somename) = v;
15+
//~^ ERROR cannot find value `_somename` in this scope
16+
//~| ERROR mismatched types
17+
v.0 = 0;
18+
};
19+
}
20+
21+
fn main() {}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
error[E0106]: missing lifetime specifier
2+
--> $DIR/closure-2021-captures-lint-field-projection-ice-119382.rs:9:10
3+
|
4+
LL | struct V(&mut i32);
5+
| ^ expected named lifetime parameter
6+
|
7+
help: consider introducing a named lifetime parameter
8+
|
9+
LL | struct V<'a>(&'a mut i32);
10+
| ++++ ++
11+
12+
error[E0425]: cannot find value `_somename` in this scope
13+
--> $DIR/closure-2021-captures-lint-field-projection-ice-119382.rs:14:11
14+
|
15+
LL | V(_somename) = v;
16+
| ^^^^^^^^^ not found in this scope
17+
18+
error[E0308]: mismatched types
19+
--> $DIR/closure-2021-captures-lint-field-projection-ice-119382.rs:14:9
20+
|
21+
LL | V(_somename) = v;
22+
| ^^^^^^^^^^^^ - this expression has type `&V`
23+
| |
24+
| expected `&V`, found `V`
25+
|
26+
help: consider dereferencing to access the inner value using the `Deref` trait
27+
|
28+
LL | V(_somename) = &*v;
29+
| ++
30+
31+
error: aborting due to 3 previous errors
32+
33+
Some errors have detailed explanations: E0106, E0308, E0425.
34+
For more information about an error, try `rustc --explain E0106`.

0 commit comments

Comments
 (0)