about summary refs log tree commit diff
diff options
context:
space:
mode:
authorCamille GILLOT <gillot.camille@gmail.com>2022-06-27 07:33:19 +0200
committerCamille GILLOT <gillot.camille@gmail.com>2022-07-07 09:27:44 +0200
commit5edc55f99fdd850f5e3c4168c917517d6afa0e07 (patch)
tree5ef0eb2821ff79e8be598b753ede0ea76f418140
parenta950aa24bc8a63bb986c5e619cf0948969a4954a (diff)
downloadrust-5edc55f99fdd850f5e3c4168c917517d6afa0e07.tar.gz
rust-5edc55f99fdd850f5e3c4168c917517d6afa0e07.zip
Fix borrowck closure span.
-rw-r--r--compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs4
-rw-r--r--src/test/ui/borrowck/borrow-immutable-upvar-mutation.stderr30
-rw-r--r--src/test/ui/borrowck/borrow-raw-address-of-mutability.stderr8
-rw-r--r--src/test/ui/borrowck/mutability-errors.stderr32
-rw-r--r--src/test/ui/fn/fn-closure-mutable-capture.rs1
-rw-r--r--src/test/ui/fn/fn-closure-mutable-capture.stderr5
-rw-r--r--src/test/ui/issues/issue-21600.stderr9
-rw-r--r--src/test/ui/nll/closure-captures.stderr24
-rw-r--r--src/test/ui/unboxed-closures/unboxed-closures-mutate-upvar.stderr4
-rw-r--r--src/test/ui/unboxed-closures/unboxed-closures-mutated-upvar-from-fn-closure.stderr4
10 files changed, 83 insertions, 38 deletions
diff --git a/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs b/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs
index 1d9d2c6d8a3..8134e122662 100644
--- a/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs
+++ b/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs
@@ -903,9 +903,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
                 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;
                 }
             }
diff --git a/src/test/ui/borrowck/borrow-immutable-upvar-mutation.stderr b/src/test/ui/borrowck/borrow-immutable-upvar-mutation.stderr
index 3b06ed5e805..093589ed092 100644
--- a/src/test/ui/borrowck/borrow-immutable-upvar-mutation.stderr
+++ b/src/test/ui/borrowck/borrow-immutable-upvar-mutation.stderr
@@ -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
diff --git a/src/test/ui/borrowck/borrow-raw-address-of-mutability.stderr b/src/test/ui/borrowck/borrow-raw-address-of-mutability.stderr
index 50513cac2c5..869375cb2c6 100644
--- a/src/test/ui/borrowck/borrow-raw-address-of-mutability.stderr
+++ b/src/test/ui/borrowck/borrow-raw-address-of-mutability.stderr
@@ -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
 
diff --git a/src/test/ui/borrowck/mutability-errors.stderr b/src/test/ui/borrowck/mutability-errors.stderr
index 86557145c3b..dd29ae492d6 100644
--- a/src/test/ui/borrowck/mutability-errors.stderr
+++ b/src/test/ui/borrowck/mutability-errors.stderr
@@ -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
diff --git a/src/test/ui/fn/fn-closure-mutable-capture.rs b/src/test/ui/fn/fn-closure-mutable-capture.rs
index 0e427b9cf31..97141886fe7 100644
--- a/src/test/ui/fn/fn-closure-mutable-capture.rs
+++ b/src/test/ui/fn/fn-closure-mutable-capture.rs
@@ -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() {}
diff --git a/src/test/ui/fn/fn-closure-mutable-capture.stderr b/src/test/ui/fn/fn-closure-mutable-capture.stderr
index d23c363ae15..03e3d545a99 100644
--- a/src/test/ui/fn/fn-closure-mutable-capture.stderr
+++ b/src/test/ui/fn/fn-closure-mutable-capture.stderr
@@ -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
diff --git a/src/test/ui/issues/issue-21600.stderr b/src/test/ui/issues/issue-21600.stderr
index 0c41ca3b3d6..ea304f9367b 100644
--- a/src/test/ui/issues/issue-21600.stderr
+++ b/src/test/ui/issues/issue-21600.stderr
@@ -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
diff --git a/src/test/ui/nll/closure-captures.stderr b/src/test/ui/nll/closure-captures.stderr
index 20bee2caaac..5233f0b2462 100644
--- a/src/test/ui/nll/closure-captures.stderr
+++ b/src/test/ui/nll/closure-captures.stderr
@@ -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;});
diff --git a/src/test/ui/unboxed-closures/unboxed-closures-mutate-upvar.stderr b/src/test/ui/unboxed-closures/unboxed-closures-mutate-upvar.stderr
index 1a63af029c9..d6e74b5b8b9 100644
--- a/src/test/ui/unboxed-closures/unboxed-closures-mutate-upvar.stderr
+++ b/src/test/ui/unboxed-closures/unboxed-closures-mutate-upvar.stderr
@@ -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
 
diff --git a/src/test/ui/unboxed-closures/unboxed-closures-mutated-upvar-from-fn-closure.stderr b/src/test/ui/unboxed-closures/unboxed-closures-mutated-upvar-from-fn-closure.stderr
index 91d3e609665..7d15cd0c882 100644
--- a/src/test/ui/unboxed-closures/unboxed-closures-mutated-upvar-from-fn-closure.stderr
+++ b/src/test/ui/unboxed-closures/unboxed-closures-mutated-upvar-from-fn-closure.stderr
@@ -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