]> git.lizzy.rs Git - rust.git/commitdiff
Don't claim that locals in a function are declared outside of the
authorMatthew Jasper <mjjasper1@gmail.com>
Sat, 15 Sep 2018 17:28:52 +0000 (18:28 +0100)
committerMatthew Jasper <mjjasper1@gmail.com>
Wed, 19 Sep 2018 18:52:55 +0000 (19:52 +0100)
function body

src/librustc_mir/borrow_check/nll/region_infer/error_reporting/mod.rs
src/test/ui/regions/regions-infer-paramd-indirect.nll.stderr

index dfed41cb1defd5de4bcf145a0f116dc8da4bcd7d..b7000b254a7de42b2e250a300a7102afffe0d50d 100644 (file)
@@ -391,7 +391,11 @@ fn report_escaping_data_error(
 
         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() {
+        // Revert to the normal error in these cases.
+        // Assignments aren't "escapes" in function items.
+        if (fr_name_and_span.is_none() && outlived_fr_name_and_span.is_none())
+            || (category == ConstraintCategory::Assignment && escapes_from == "function")
+        {
             return self.report_general_error(mir, infcx, mir_def_id,
                                              fr, true, outlived_fr, false,
                                              category, span, errors_buffer);
index 8e29e77713ba566838679247a43980011a9c285f..7558c5caa0e24b7a37269e151efbedec6620896f 100644 (file)
@@ -1,12 +1,13 @@
-error: borrowed data escapes outside of function
+error: unsatisfied lifetime constraints
   --> $DIR/regions-infer-paramd-indirect.rs:33:9
    |
+LL | impl<'a> set_f<'a> for c<'a> {
+   |      -- lifetime `'a` defined here
+...
 LL |     fn set_f_bad(&mut self, b: Box<b>) {
-   |                  ---------  - `b` is a reference that is only valid in the function body
-   |                  |
-   |                  `self` is declared here, outside of the function body
+   |                             - has type `std::boxed::Box<std::boxed::Box<&'1 isize>>`
 LL |         self.f = b;
-   |         ^^^^^^ `b` escapes the function body here
+   |         ^^^^^^ assignment requires that `'1` must outlive `'a`
 
 error: aborting due to previous error