]> git.lizzy.rs Git - rust.git/commitdiff
Fix borrowck closure span.
authorCamille GILLOT <gillot.camille@gmail.com>
Mon, 27 Jun 2022 05:33:19 +0000 (07:33 +0200)
committerCamille GILLOT <gillot.camille@gmail.com>
Thu, 7 Jul 2022 07:27:44 +0000 (09:27 +0200)
compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs
src/test/ui/borrowck/borrow-immutable-upvar-mutation.stderr
src/test/ui/borrowck/borrow-raw-address-of-mutability.stderr
src/test/ui/borrowck/mutability-errors.stderr
src/test/ui/fn/fn-closure-mutable-capture.rs
src/test/ui/fn/fn-closure-mutable-capture.stderr
src/test/ui/issues/issue-21600.stderr
src/test/ui/nll/closure-captures.stderr
src/test/ui/unboxed-closures/unboxed-closures-mutate-upvar.stderr
src/test/ui/unboxed-closures/unboxed-closures-mutated-upvar-from-fn-closure.stderr

index 1d9d2c6d8a33a64ecfe9068badb7e15c7b80736f..8134e1226628fa2aef91e132497f0b4599ce6d98 100644 (file)
@@ -903,9 +903,7 @@ fn expected_fn_found_fn_mut_call(&self, err: &mut Diagnostic, sp: Span, act: &st
                 if let Some(span) = arg {
                     err.span_label(span, "change this to accept `FnMut` instead of `Fn`");
                     err.span_label(func.span, "expects `Fn` instead of `FnMut`");
-                    if self.infcx.tcx.sess.source_map().is_multiline(self.body.span) {
-                        err.span_label(self.body.span, "in this closure");
-                    }
+                    err.span_label(self.body.span, "in this closure");
                     look_at_return = false;
                 }
             }
index 3b06ed5e80580587f268b02b7c1174616d308356..093589ed0921fced630d1efa12a21bdcf80fc161 100644 (file)
@@ -5,8 +5,9 @@ LL | fn to_fn<A, F: Fn<A>>(f: F) -> F {
    |                          - change this to accept `FnMut` instead of `Fn`
 ...
 LL |         let _f = to_fn(|| x = 42);
-   |                  -----    ^^^^^^ cannot assign
-   |                  |
+   |                  ----- -- ^^^^^^ cannot assign
+   |                  |     |
+   |                  |     in this closure
    |                  expects `Fn` instead of `FnMut`
 
 error[E0596]: cannot borrow `y` as mutable, as it is a captured variable in a `Fn` closure
@@ -16,8 +17,9 @@ LL | fn to_fn<A, F: Fn<A>>(f: F) -> F {
    |                          - change this to accept `FnMut` instead of `Fn`
 ...
 LL |         let _g = to_fn(|| set(&mut y));
-   |                  -----        ^^^^^^ cannot borrow as mutable
-   |                  |
+   |                  ----- --     ^^^^^^ cannot borrow as mutable
+   |                  |     |
+   |                  |     in this closure
    |                  expects `Fn` instead of `FnMut`
 
 error[E0594]: cannot assign to `z`, as it is a captured variable in a `Fn` closure
@@ -27,8 +29,9 @@ LL | fn to_fn<A, F: Fn<A>>(f: F) -> F {
    |                          - change this to accept `FnMut` instead of `Fn`
 ...
 LL |             to_fn(|| z = 42);
-   |             -----    ^^^^^^ cannot assign
-   |             |
+   |             ----- -- ^^^^^^ cannot assign
+   |             |     |
+   |             |     in this closure
    |             expects `Fn` instead of `FnMut`
 
 error[E0594]: cannot assign to `x`, as it is a captured variable in a `Fn` closure
@@ -38,8 +41,9 @@ LL | fn to_fn<A, F: Fn<A>>(f: F) -> F {
    |                          - change this to accept `FnMut` instead of `Fn`
 ...
 LL |         let _f = to_fn(move || x = 42);
-   |                  -----         ^^^^^^ cannot assign
-   |                  |
+   |                  ----- ------- ^^^^^^ cannot assign
+   |                  |     |
+   |                  |     in this closure
    |                  expects `Fn` instead of `FnMut`
 
 error[E0596]: cannot borrow `y` as mutable, as it is a captured variable in a `Fn` closure
@@ -49,8 +53,9 @@ LL | fn to_fn<A, F: Fn<A>>(f: F) -> F {
    |                          - change this to accept `FnMut` instead of `Fn`
 ...
 LL |         let _g = to_fn(move || set(&mut y));
-   |                  -----             ^^^^^^ cannot borrow as mutable
-   |                  |
+   |                  ----- -------     ^^^^^^ cannot borrow as mutable
+   |                  |     |
+   |                  |     in this closure
    |                  expects `Fn` instead of `FnMut`
 
 error[E0594]: cannot assign to `z`, as it is a captured variable in a `Fn` closure
@@ -60,8 +65,9 @@ LL | fn to_fn<A, F: Fn<A>>(f: F) -> F {
    |                          - change this to accept `FnMut` instead of `Fn`
 ...
 LL |             to_fn(move || z = 42);
-   |             -----         ^^^^^^ cannot assign
-   |             |
+   |             ----- ------- ^^^^^^ cannot assign
+   |             |     |
+   |             |     in this closure
    |             expects `Fn` instead of `FnMut`
 
 error[E0594]: cannot assign to `x`, as it is a captured variable in a `Fn` closure
index 50513cac2c59eef05cb62c800a2f8f3e18fcff8c..869375cb2c61be2a0911f28e05e42e2c409b3cd2 100644 (file)
@@ -33,7 +33,9 @@ LL | fn make_fn<F: Fn()>(f: F) -> F { f }
    |                        - change this to accept `FnMut` instead of `Fn`
 ...
 LL |     let f = make_fn(|| {
-   |             ------- expects `Fn` instead of `FnMut`
+   |             ------- -- in this closure
+   |             |
+   |             expects `Fn` instead of `FnMut`
 LL |         let y = &raw mut x;
    |                 ^^^^^^^^^^ cannot borrow as mutable
 
@@ -44,7 +46,9 @@ LL | fn make_fn<F: Fn()>(f: F) -> F { f }
    |                        - change this to accept `FnMut` instead of `Fn`
 ...
 LL |     let f = make_fn(move || {
-   |             ------- expects `Fn` instead of `FnMut`
+   |             ------- ------- in this closure
+   |             |
+   |             expects `Fn` instead of `FnMut`
 LL |         let y = &raw mut x;
    |                 ^^^^^^^^^^ cannot borrow as mutable
 
index 86557145c3b0788961ae9a784d675412d90a0c2a..dd29ae492d604fa758dfc593df29f24f0f969942 100644 (file)
@@ -123,7 +123,9 @@ LL | fn fn_ref<F: Fn()>(f: F) -> F { f }
    |                       - change this to accept `FnMut` instead of `Fn`
 ...
 LL |     fn_ref(|| {
-   |     ------ expects `Fn` instead of `FnMut`
+   |     ------ -- in this closure
+   |     |
+   |     expects `Fn` instead of `FnMut`
 LL |         x = (1,);
    |         ^^^^^^^^ cannot assign
 
@@ -134,7 +136,9 @@ LL | fn fn_ref<F: Fn()>(f: F) -> F { f }
    |                       - change this to accept `FnMut` instead of `Fn`
 ...
 LL |     fn_ref(|| {
-   |     ------ expects `Fn` instead of `FnMut`
+   |     ------ -- in this closure
+   |     |
+   |     expects `Fn` instead of `FnMut`
 LL |         x = (1,);
 LL |         x.0 = 1;
    |         ^^^^^^^ cannot assign
@@ -146,7 +150,9 @@ LL | fn fn_ref<F: Fn()>(f: F) -> F { f }
    |                       - change this to accept `FnMut` instead of `Fn`
 ...
 LL |     fn_ref(|| {
-   |     ------ expects `Fn` instead of `FnMut`
+   |     ------ -- in this closure
+   |     |
+   |     expects `Fn` instead of `FnMut`
 ...
 LL |         &mut x;
    |         ^^^^^^ cannot borrow as mutable
@@ -158,7 +164,9 @@ LL | fn fn_ref<F: Fn()>(f: F) -> F { f }
    |                       - change this to accept `FnMut` instead of `Fn`
 ...
 LL |     fn_ref(|| {
-   |     ------ expects `Fn` instead of `FnMut`
+   |     ------ -- in this closure
+   |     |
+   |     expects `Fn` instead of `FnMut`
 ...
 LL |         &mut x.0;
    |         ^^^^^^^^ cannot borrow as mutable
@@ -170,7 +178,9 @@ LL | fn fn_ref<F: Fn()>(f: F) -> F { f }
    |                       - change this to accept `FnMut` instead of `Fn`
 ...
 LL |     fn_ref(move || {
-   |     ------ expects `Fn` instead of `FnMut`
+   |     ------ ------- in this closure
+   |     |
+   |     expects `Fn` instead of `FnMut`
 LL |         x = (1,);
    |         ^^^^^^^^ cannot assign
 
@@ -181,7 +191,9 @@ LL | fn fn_ref<F: Fn()>(f: F) -> F { f }
    |                       - change this to accept `FnMut` instead of `Fn`
 ...
 LL |     fn_ref(move || {
-   |     ------ expects `Fn` instead of `FnMut`
+   |     ------ ------- in this closure
+   |     |
+   |     expects `Fn` instead of `FnMut`
 LL |         x = (1,);
 LL |         x.0 = 1;
    |         ^^^^^^^ cannot assign
@@ -193,7 +205,9 @@ LL | fn fn_ref<F: Fn()>(f: F) -> F { f }
    |                       - change this to accept `FnMut` instead of `Fn`
 ...
 LL |     fn_ref(move || {
-   |     ------ expects `Fn` instead of `FnMut`
+   |     ------ ------- in this closure
+   |     |
+   |     expects `Fn` instead of `FnMut`
 ...
 LL |         &mut x;
    |         ^^^^^^ cannot borrow as mutable
@@ -205,7 +219,9 @@ LL | fn fn_ref<F: Fn()>(f: F) -> F { f }
    |                       - change this to accept `FnMut` instead of `Fn`
 ...
 LL |     fn_ref(move || {
-   |     ------ expects `Fn` instead of `FnMut`
+   |     ------ ------- in this closure
+   |     |
+   |     expects `Fn` instead of `FnMut`
 ...
 LL |         &mut x.0;
    |         ^^^^^^^^ cannot borrow as mutable
index 0e427b9cf318f1b5802eddd0391e7d673d524cfd..97141886fe7381a314b521b104ecf7ecc1e72002 100644 (file)
@@ -6,6 +6,7 @@ pub fn foo() {
     //~^ ERROR cannot assign to `x`, as it is a captured variable in a `Fn` closure
     //~| NOTE cannot assign
     //~| NOTE expects `Fn` instead of `FnMut`
+    //~| NOTE in this closure
 }
 
 fn main() {}
index d23c363ae1582182ab8f30b6a9df41f7d3573aaa..03e3d545a99198a3750f9ef88b7b5d6354eef400 100644 (file)
@@ -5,8 +5,9 @@ LL | pub fn bar<F: Fn()>(_f: F) {}
    |                         - change this to accept `FnMut` instead of `Fn`
 ...
 LL |     bar(move || x = 1);
-   |     ---         ^^^^^ cannot assign
-   |     |
+   |     --- ------- ^^^^^ cannot assign
+   |     |   |
+   |     |   in this closure
    |     expects `Fn` instead of `FnMut`
 
 error: aborting due to previous error
index 0c41ca3b3d67445b1bf645a11589c4cc0790f053..ea304f9367b05305991a0c267e252192e9dabf27 100644 (file)
@@ -5,8 +5,9 @@ LL | fn call_it<F>(f: F) where F: Fn() { f(); }
    |                  - change this to accept `FnMut` instead of `Fn`
 ...
 LL |         call_it(|| x.gen_mut());
-   |         -------    ^^^^^^^^^^^ cannot borrow as mutable
-   |         |
+   |         ------- -- ^^^^^^^^^^^ cannot borrow as mutable
+   |         |       |
+   |         |       in this closure
    |         expects `Fn` instead of `FnMut`
 
 error[E0596]: cannot borrow `x` as mutable, as it is a captured variable in a `Fn` closure
@@ -16,7 +17,9 @@ LL | fn call_it<F>(f: F) where F: Fn() { f(); }
    |                  - change this to accept `FnMut` instead of `Fn`
 ...
 LL |     call_it(|| {
-   |     ------- expects `Fn` instead of `FnMut`
+   |     ------- -- in this closure
+   |     |
+   |     expects `Fn` instead of `FnMut`
 LL |         call_it(|| x.gen());
 LL |         call_it(|| x.gen_mut());
    |                 ^^ - mutable borrow occurs due to use of `x` in closure
index 20bee2caaac0ee33f1279a768f8a730dd2618699..5233f0b246261378bd26cab860c12453ab1117e5 100644 (file)
@@ -41,7 +41,9 @@ LL | fn fn_ref<F: Fn()>(f: F) -> F { f }
    |                       - change this to accept `FnMut` instead of `Fn`
 ...
 LL |     fn_ref(|| {
-   |     ------ expects `Fn` instead of `FnMut`
+   |     ------ -- in this closure
+   |     |
+   |     expects `Fn` instead of `FnMut`
 LL |         ||
    |         ^^ cannot borrow as mutable
 LL |          x = 1;}
@@ -54,7 +56,9 @@ LL | fn fn_ref<F: Fn()>(f: F) -> F { f }
    |                       - change this to accept `FnMut` instead of `Fn`
 ...
 LL |     fn_ref(move || {
-   |     ------ expects `Fn` instead of `FnMut`
+   |     ------ ------- in this closure
+   |     |
+   |     expects `Fn` instead of `FnMut`
 LL |         ||
    |         ^^ cannot borrow as mutable
 LL |     x = 1;});
@@ -76,7 +80,9 @@ LL | fn fn_ref<F: Fn()>(f: F) -> F { f }
    |                       - change this to accept `FnMut` instead of `Fn`
 ...
 LL |     fn_ref(|| {
-   |     ------ expects `Fn` instead of `FnMut`
+   |     ------ -- in this closure
+   |     |
+   |     expects `Fn` instead of `FnMut`
 LL |         ||
    |         ^^ cannot borrow as mutable
 LL |          x = 1;}
@@ -98,7 +104,9 @@ LL | fn fn_ref<F: Fn()>(f: F) -> F { f }
    |                       - change this to accept `FnMut` instead of `Fn`
 ...
 LL |     fn_ref(move || {
-   |     ------ expects `Fn` instead of `FnMut`
+   |     ------ ------- in this closure
+   |     |
+   |     expects `Fn` instead of `FnMut`
 LL |         ||
    |         ^^ cannot borrow as mutable
 LL |     x = 1;});
@@ -111,7 +119,9 @@ LL | fn fn_ref<F: Fn()>(f: F) -> F { f }
    |                       - change this to accept `FnMut` instead of `Fn`
 ...
 LL |     fn_ref(|| {
-   |     ------ expects `Fn` instead of `FnMut`
+   |     ------ -- in this closure
+   |     |
+   |     expects `Fn` instead of `FnMut`
 LL |         ||
    |         ^^ cannot borrow as mutable
 LL |         *x = 1;});
@@ -124,7 +134,9 @@ LL | fn fn_ref<F: Fn()>(f: F) -> F { f }
    |                       - change this to accept `FnMut` instead of `Fn`
 ...
 LL |     fn_ref(move || {
-   |     ------ expects `Fn` instead of `FnMut`
+   |     ------ ------- in this closure
+   |     |
+   |     expects `Fn` instead of `FnMut`
 LL |         ||
    |         ^^ cannot borrow as mutable
 LL |         *x = 1;});
index 1a63af029c934cd6958f34a67ddf80ee14727217..d6e74b5b8b91413bac7326ea736a8300b4eaf411 100644 (file)
@@ -32,7 +32,9 @@ LL | fn to_fn<A,F:Fn<A>>(f: F) -> F { f }
    |                        - change this to accept `FnMut` instead of `Fn`
 ...
 LL |     let mut f = to_fn(move || {
-   |                 ----- expects `Fn` instead of `FnMut`
+   |                 ----- ------- in this closure
+   |                 |
+   |                 expects `Fn` instead of `FnMut`
 LL |         n += 1;
    |         ^^^^^^ cannot assign
 
index 91d3e609665c4e89b66565f93c245ea20bb9acea..7d15cd0c882a58edfa9845b1ff6427bae5706acf 100644 (file)
@@ -5,7 +5,9 @@ LL | fn call<F>(f: F) where F : Fn() {
    |               - change this to accept `FnMut` instead of `Fn`
 ...
 LL |     call(|| {
-   |     ---- expects `Fn` instead of `FnMut`
+   |     ---- -- in this closure
+   |     |
+   |     expects `Fn` instead of `FnMut`
 LL |         counter += 1;
    |         ^^^^^^^^^^^^ cannot assign