diff --git a/tests/ui/closures/closure-2021-captures-lint-field-projection-ice-119382.rs b/tests/ui/closures/closure-2021-captures-lint-field-projection-ice-119382.rs new file mode 100644 index 000000000000..f1e3d5210e00 --- /dev/null +++ b/tests/ui/closures/closure-2021-captures-lint-field-projection-ice-119382.rs @@ -0,0 +1,21 @@ +//! Regression test for . +//! +//! The `-Wrust-2021-incompatible-closure-captures` lint used to ICE +//! when applied to erroneous code. + +//@ edition: 2018 +//@ compile-flags: -Wrust-2021-incompatible-closure-captures + +struct V(&mut i32); +//~^ ERROR missing lifetime specifier + +fn nested(v: &V) { + || { + V(_somename) = v; + //~^ ERROR cannot find value `_somename` in this scope + //~| ERROR mismatched types + v.0 = 0; + }; +} + +fn main() {} diff --git a/tests/ui/closures/closure-2021-captures-lint-field-projection-ice-119382.stderr b/tests/ui/closures/closure-2021-captures-lint-field-projection-ice-119382.stderr new file mode 100644 index 000000000000..a3e403f0e56d --- /dev/null +++ b/tests/ui/closures/closure-2021-captures-lint-field-projection-ice-119382.stderr @@ -0,0 +1,34 @@ +error[E0106]: missing lifetime specifier + --> $DIR/closure-2021-captures-lint-field-projection-ice-119382.rs:9:10 + | +LL | struct V(&mut i32); + | ^ expected named lifetime parameter + | +help: consider introducing a named lifetime parameter + | +LL | struct V<'a>(&'a mut i32); + | ++++ ++ + +error[E0425]: cannot find value `_somename` in this scope + --> $DIR/closure-2021-captures-lint-field-projection-ice-119382.rs:14:11 + | +LL | V(_somename) = v; + | ^^^^^^^^^ not found in this scope + +error[E0308]: mismatched types + --> $DIR/closure-2021-captures-lint-field-projection-ice-119382.rs:14:9 + | +LL | V(_somename) = v; + | ^^^^^^^^^^^^ - this expression has type `&V` + | | + | expected `&V`, found `V` + | +help: consider dereferencing to access the inner value using the `Deref` trait + | +LL | V(_somename) = &*v; + | ++ + +error: aborting due to 3 previous errors + +Some errors have detailed explanations: E0106, E0308, E0425. +For more information about an error, try `rustc --explain E0106`.