]> git.lizzy.rs Git - rust.git/blob - src/test/ui/borrowck/issue-45983.rs
Rollup merge of #53110 - Xanewok:save-analysis-remap-path, r=nrc
[rust.git] / src / test / ui / borrowck / issue-45983.rs
1 // Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 // As documented in Issue #45983, this test is evaluating the quality
12 // of our diagnostics on erroneous code using higher-ranked closures.
13 //
14 // However, as documented on Issue #53026, this test also became a
15 // prime example of our need to test the NLL migration mode
16 // *separately* from the existing test suites that focus solely on
17 // AST-borrwock and NLL.
18
19 // revisions: ast migrate nll
20
21 // Since we are testing nll (and migration) explicitly as a separate
22 // revisions, dont worry about the --compare-mode=nll on this test.
23
24 // ignore-compare-mode-nll
25
26 //[ast]compile-flags: -Z borrowck=ast
27 //[migrate]compile-flags: -Z borrowck=migrate -Z two-phase-borrows
28 //[nll]compile-flags: -Z borrowck=mir -Z two-phase-borrows
29
30 fn give_any<F: for<'r> FnOnce(&'r ())>(f: F) {
31     f(&());
32 }
33
34 fn main() {
35     let x = None;
36     give_any(|y| x = Some(y));
37     //[ast]~^ ERROR borrowed data cannot be stored outside of its closure
38     //[migrate]~^^ ERROR borrowed data cannot be stored outside of its closure
39     //[nll]~^^^ WARN not reporting region error due to nll
40     //[nll]~| ERROR borrowed data escapes outside of closure
41     //[nll]~| ERROR cannot assign to `x`, as it is not declared as mutable
42 }