]> git.lizzy.rs Git - rust.git/commitdiff
Change label from closure to function where appropriate.
authorDavid Wood <david@davidtw.co>
Tue, 24 Jul 2018 14:22:41 +0000 (16:22 +0200)
committerDavid Wood <david@davidtw.co>
Fri, 27 Jul 2018 10:48:47 +0000 (12:48 +0200)
src/librustc_mir/borrow_check/nll/region_infer/error_reporting/mod.rs
src/test/ui/impl-trait/static-return-lifetime-infered.nll.stderr
src/test/ui/in-band-lifetimes/impl/dyn-trait.nll.stderr
src/test/ui/issue-16683.nll.stderr
src/test/ui/issue-17758.nll.stderr
src/test/ui/issue-52213.nll.stderr
src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-no-bound.stderr
src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-wrong-bound.stderr
src/test/ui/nll/issue-50716.stderr
src/test/ui/nll/mir_check_cast_reify.stderr
src/test/ui/nll/mir_check_cast_unsafe_fn.stderr

index cef6ab311a398e8fc4b789a5943972a2192d60f9..c88259d5e8fe34455d9ceae4ca651edd82de82e0 100644 (file)
@@ -324,8 +324,8 @@ pub(super) fn report_error(
         match (category, fr_is_local, outlived_fr_is_local) {
             (ConstraintCategory::Assignment, true, false) |
             (ConstraintCategory::CallArgument, true, false) =>
-                self.report_escapes_closure_error(mir, infcx, mir_def_id, fr, outlived_fr,
-                                                  category, span, errors_buffer),
+                self.report_escaping_data_error(mir, infcx, mir_def_id, fr, outlived_fr,
+                                                category, span, errors_buffer),
             _ =>
                 self.report_general_error(mir, infcx, mir_def_id, fr, fr_is_local,
                                           outlived_fr, outlived_fr_is_local,
@@ -333,7 +333,7 @@ pub(super) fn report_error(
         };
     }
 
-    fn report_escapes_closure_error(
+    fn report_escaping_data_error(
         &self,
         mir: &Mir<'tcx>,
         infcx: &InferCtxt<'_, '_, 'tcx>,
@@ -348,22 +348,23 @@ fn report_escapes_closure_error(
         let outlived_fr_name_and_span =
             self.get_var_name_and_span_for_region(infcx.tcx, mir, outlived_fr);
 
+        let escapes_from = if infcx.tcx.is_closure(mir_def_id) { "closure" } else { "function" };
+
         if fr_name_and_span.is_none() && outlived_fr_name_and_span.is_none() {
             return self.report_general_error(mir, infcx, mir_def_id,
                                              fr, true, outlived_fr, false,
                                              category, span, errors_buffer);
         }
 
-        let mut diag = infcx
-            .tcx
-            .sess
-            .struct_span_err(span, &format!("borrowed data escapes outside of closure"));
+        let mut diag = infcx.tcx.sess.struct_span_err(
+            span, &format!("borrowed data escapes outside of {}", escapes_from),
+        );
 
         if let Some((outlived_fr_name, outlived_fr_span)) = outlived_fr_name_and_span {
             if let Some(name) = outlived_fr_name {
                 diag.span_label(
                     outlived_fr_span,
-                    format!("`{}` is declared here, outside of the closure body", name),
+                    format!("`{}` is declared here, outside of the {} body", name, escapes_from),
                 );
             }
         }
@@ -372,13 +373,12 @@ fn report_escapes_closure_error(
             if let Some(name) = fr_name {
                 diag.span_label(
                     fr_span,
-                    format!(
-                        "`{}` is a reference that is only valid in the closure body",
-                        name
-                    ),
+                    format!("`{}` is a reference that is only valid in the {} body",
+                            name, escapes_from),
                 );
 
-                diag.span_label(span, format!("`{}` escapes the closure body here", name));
+                diag.span_label(span, format!("`{}` escapes the {} body here",
+                                               name, escapes_from));
             }
         }
 
@@ -409,12 +409,14 @@ fn report_general_error(
         let outlived_fr_name = self.give_region_a_name(
             infcx, mir, mir_def_id, outlived_fr, counter, &mut diag);
 
+        let mir_def_name = if infcx.tcx.is_closure(mir_def_id) { "closure" } else { "function" };
+
         match (category, outlived_fr_is_local, fr_is_local) {
             (ConstraintCategory::Return, true, _) => {
                 diag.span_label(span, format!(
-                    "closure was supposed to return data with lifetime `{}` but it is returning \
+                    "{} was supposed to return data with lifetime `{}` but it is returning \
                     data with lifetime `{}`",
-                    fr_name, outlived_fr_name,
+                    mir_def_name, fr_name, outlived_fr_name,
                 ));
             },
             _ => {
index c6f8d2e519ca1c7909aca8cb49c3c354cb6c6bd7..123a93636d237e36e85b3367cc78890161199025 100644 (file)
@@ -10,21 +10,19 @@ warning: not reporting region error due to nll
 LL |         self.x.iter().map(|a| a.0)
    |                ^^^^
 
-error: borrowed data escapes outside of closure
+error: unsatisfied lifetime constraints
   --> $DIR/static-return-lifetime-infered.rs:17:9
    |
 LL |     fn iter_values_anon(&self) -> impl Iterator<Item=u32> {
-   |                         ----- `self` is a reference that is only valid in the closure body
+   |                         - let's call the lifetime of this reference `'1`
 LL |         self.x.iter().map(|a| a.0)
-   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^ `self` escapes the closure body here
+   |         ^^^^^^^^^^^^^ free region requires that `'1` must outlive `'static`
 
-error: borrowed data escapes outside of closure
+error: unsatisfied lifetime constraints
   --> $DIR/static-return-lifetime-infered.rs:21:9
    |
-LL |     fn iter_values<'a>(&'a self) -> impl Iterator<Item=u32> {
-   |                        -------- `self` is a reference that is only valid in the closure body
 LL |         self.x.iter().map(|a| a.0)
-   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^ `self` escapes the closure body here
+   |         ^^^^^^^^^^^^^ free region requires that `'a` must outlive `'static`
 
 error: aborting due to 2 previous errors
 
index e26b1956d5e819632e0fb6d090636b36837f6375..f5d98e04ad804009fdef311814c7c8eaaa86076c 100644 (file)
@@ -4,13 +4,13 @@ warning: not reporting region error due to nll
 LL |     static_val(x); //~ ERROR cannot infer
    |                ^
 
-error: borrowed data escapes outside of closure
+error: borrowed data escapes outside of function
   --> $DIR/dyn-trait.rs:32:5
    |
 LL | fn with_dyn_debug_static<'a>(x: Box<dyn Debug + 'a>) {
-   |                              - `x` is a reference that is only valid in the closure body
+   |                              - `x` is a reference that is only valid in the function body
 LL |     static_val(x); //~ ERROR cannot infer
-   |     ^^^^^^^^^^^^^ `x` escapes the closure body here
+   |     ^^^^^^^^^^^^^ `x` escapes the function body here
 
 error: aborting due to previous error
 
index f9dda27da0985b36f5d022e4598a1ca6783a859a..890bb426441e2182b569952ec8dfcbaa4c1805db 100644 (file)
@@ -10,13 +10,13 @@ warning: not reporting region error due to nll
 LL |         self.a(); //~ ERROR cannot infer
    |              ^
 
-error: borrowed data escapes outside of closure
+error: borrowed data escapes outside of function
   --> $DIR/issue-16683.rs:14:9
    |
 LL |     fn b(&self) {
-   |          ----- `self` is a reference that is only valid in the closure body
+   |          ----- `self` is a reference that is only valid in the function body
 LL |         self.a(); //~ ERROR cannot infer
-   |         ^^^^^^^^ `self` escapes the closure body here
+   |         ^^^^^^^^ `self` escapes the function body here
 
 error: aborting due to previous error
 
index 5775135aefc5feb472aaed348d862134190e0f28..c51a72f885d6c83487eab1d2cbb8c07375e06403 100644 (file)
@@ -10,13 +10,13 @@ warning: not reporting region error due to nll
 LL |         self.foo();
    |              ^^^
 
-error: borrowed data escapes outside of closure
+error: borrowed data escapes outside of function
   --> $DIR/issue-17758.rs:17:9
    |
 LL |     fn bar(&self) {
-   |            ----- `self` is a reference that is only valid in the closure body
+   |            ----- `self` is a reference that is only valid in the function body
 LL |         self.foo();
-   |         ^^^^^^^^^^ `self` escapes the closure body here
+   |         ^^^^^^^^^^ `self` escapes the function body here
 
 error: aborting due to previous error
 
index fb5da7d7a19470cbf2c995230f6c4356c791174b..c288cf9ed820c8dc2f8baf8034570d49847d8214 100644 (file)
@@ -5,10 +5,10 @@ LL |     match (&t,) { //~ ERROR cannot infer an appropriate lifetime
    |           ^^^^^
 
 error: unsatisfied lifetime constraints
-  --> $DIR/issue-52213.rs:12:11
+  --> $DIR/issue-52213.rs:13:11
    |
-LL |     match (&t,) { //~ ERROR cannot infer an appropriate lifetime
-   |           ^^^^^ free region requires that `'a` must outlive `'b`
+LL |         ((u,),) => u,
+   |           ^ free region requires that `'a` must outlive `'b`
 
 error: aborting due to previous error
 
index 3177cd7c28f647991730cc80908e060b638d12d8..33e4240736f5bfdd7c8ad17cf6bb0218ac0cddaa 100644 (file)
@@ -23,18 +23,18 @@ LL | |     });
    = note: number of external vids: 2
    = note: where '_#1r: '_#0r
 
-error: borrowed data escapes outside of closure
+error: borrowed data escapes outside of function
   --> $DIR/propagate-approximated-shorter-to-static-no-bound.rs:45:5
    |
 LL |   fn supply<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) {
-   |                     ------ `cell_a` is a reference that is only valid in the closure body
+   |                     ------ `cell_a` is a reference that is only valid in the function body
 LL | /     establish_relationships(&cell_a, &cell_b, |_outlives, x, y| {
 LL | |         //~^ ERROR
 LL | |
 LL | |         // Only works if 'x: 'y:
 LL | |         demand_y(x, y, x.get()) //~ WARNING not reporting region error due to nll
 LL | |     });
-   | |______^ `cell_a` escapes the closure body here
+   | |______^ `cell_a` escapes the function body here
 
 note: No external requirements
   --> $DIR/propagate-approximated-shorter-to-static-no-bound.rs:44:1
index 089c88abcdd4aee5ae8fed1eed5a8630597668ed..5f98a0fd36d7989414fb691283e84b221add3b04 100644 (file)
@@ -23,18 +23,18 @@ LL | |     });
    = note: number of external vids: 3
    = note: where '_#1r: '_#0r
 
-error: borrowed data escapes outside of closure
+error: borrowed data escapes outside of function
   --> $DIR/propagate-approximated-shorter-to-static-wrong-bound.rs:48:5
    |
 LL |   fn supply<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) {
-   |                     ------ `cell_a` is a reference that is only valid in the closure body
+   |                     ------ `cell_a` is a reference that is only valid in the function body
 LL | /     establish_relationships(&cell_a, &cell_b, |_outlives1, _outlives2, x, y| {
 LL | |         //~^ ERROR
 LL | |         // Only works if 'x: 'y:
 LL | |         demand_y(x, y, x.get())
 LL | |         //~^ WARNING not reporting region error due to nll
 LL | |     });
-   | |______^ `cell_a` escapes the closure body here
+   | |______^ `cell_a` escapes the function body here
 
 note: No external requirements
   --> $DIR/propagate-approximated-shorter-to-static-wrong-bound.rs:47:1
index 8acf2ef51ecd2ef65b4c0ef822f3ba0085251fcd..f12ab9b4f9602f8f9f326e088a5297933ab2b9b8 100644 (file)
@@ -1,11 +1,11 @@
-error: borrowed data escapes outside of closure
+error: borrowed data escapes outside of function
   --> $DIR/issue-50716.rs:25:14
    |
 LL | fn foo<'a, T: 'static>(s: Box<<&'a T as A>::X>)
-   |                        - `s` is a reference that is only valid in the closure body
+   |                        - `s` is a reference that is only valid in the function body
 ...
 LL |     let _x = *s; //~ ERROR
-   |              ^^ `s` escapes the closure body here
+   |              ^^ `s` escapes the function body here
 
 error: aborting due to previous error
 
index 13f90e1f159d2091dc6da7692ff3983aa9853f39..d8f186a22324bbc06fc6d1d3155d3997633ca82d 100644 (file)
@@ -4,14 +4,14 @@ warning: not reporting region error due to nll
 LL |     let f: fn(_) -> _ = foo;
    |                         ^^^
 
-error: borrowed data escapes outside of closure
+error: borrowed data escapes outside of function
   --> $DIR/mir_check_cast_reify.rs:48:5
    |
 LL | fn bar<'a>(x: &'a u32) -> &'static u32 {
-   |            - `x` is a reference that is only valid in the closure body
+   |            - `x` is a reference that is only valid in the function body
 ...
 LL |     f(x)
-   |     ^^^^ `x` escapes the closure body here
+   |     ^^^^ `x` escapes the function body here
 
 error: aborting due to previous error
 
index b08c6f32e6b43bc460bac69353f59900a80c52cd..98c03e378147a7890bc55dae34df7c2f8a4903c7 100644 (file)
@@ -4,14 +4,14 @@ warning: not reporting region error due to nll
 LL |     let g: unsafe fn(_) -> _ = f;
    |                                ^
 
-error: borrowed data escapes outside of closure
+error: borrowed data escapes outside of function
   --> $DIR/mir_check_cast_unsafe_fn.rs:20:14
    |
 LL | fn bar<'a>(input: &'a u32, f: fn(&'a u32) -> &'a u32) -> &'static u32 {
-   |            ----- `input` is a reference that is only valid in the closure body
+   |            ----- `input` is a reference that is only valid in the function body
 ...
 LL |     unsafe { g(input) }
-   |              ^^^^^^^^ `input` escapes the closure body here
+   |              ^^^^^^^^ `input` escapes the function body here
 
 error: aborting due to previous error