]> git.lizzy.rs Git - rust.git/blob - src/test/ui/borrowck/issue-45983.rs
3cd282077424b711c18bac66a3c96ecce90f836b
[rust.git] / src / test / ui / borrowck / issue-45983.rs
1 // As documented in Issue #45983, this test is evaluating the quality
2 // of our diagnostics on erroneous code using higher-ranked closures.
3
4 // revisions: migrate nll
5
6 // Since we are testing nll (and migration) explicitly as a separate
7 // revisions, don't worry about the --compare-mode=nll on this test.
8
9 // ignore-compare-mode-nll
10 // ignore-compare-mode-polonius
11
12 //[nll]compile-flags: -Z borrowck=mir
13
14 fn give_any<F: for<'r> FnOnce(&'r ())>(f: F) {
15     f(&());
16 }
17
18 fn main() {
19     let x = None;
20     give_any(|y| x = Some(y));
21     //[migrate]~^ ERROR borrowed data cannot be stored outside of its closure
22     //[nll]~^^ ERROR borrowed data escapes outside of closure
23     //[nll]~| ERROR cannot assign to `x`, as it is not declared as mutable
24 }