]> git.lizzy.rs Git - rust.git/commitdiff
Fallback to general error handling in ICE cases.
authorDavid Wood <david@davidtw.co>
Sat, 21 Jul 2018 14:50:06 +0000 (15:50 +0100)
committerDavid Wood <david@davidtw.co>
Sun, 22 Jul 2018 11:53:55 +0000 (12:53 +0100)
src/librustc_mir/borrow_check/nll/region_infer/error_reporting/mod.rs
src/librustc_mir/borrow_check/nll/region_infer/error_reporting/var_name.rs
src/test/ui/borrowck/issue-7573.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/nll/closure-requirements/propagate-approximated-shorter-to-static-comparing-against-free.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

index a1112d5961ecadc09e3b7278ef018e4bb3418e29..c89dc889b5e392e47e5cb21fdbf93d8b27240448 100644 (file)
@@ -247,7 +247,7 @@ pub(super) fn report_error(
         match category {
             ConstraintCategory::AssignmentToUpvar |
             ConstraintCategory::CallArgumentToUpvar =>
-                self.report_closure_error(mir, infcx, fr, outlived_fr, span),
+                self.report_closure_error(mir, infcx, mir_def_id, fr, outlived_fr, category, span),
             _ =>
                 self.report_general_error(mir, infcx, mir_def_id, fr, outlived_fr, category, span),
         }
@@ -257,33 +257,44 @@ fn report_closure_error(
         &self,
         mir: &Mir<'tcx>,
         infcx: &InferCtxt<'_, '_, 'tcx>,
+        mir_def_id: DefId,
         fr: RegionVid,
         outlived_fr: RegionVid,
+        category: &ConstraintCategory,
         span: &Span,
     ) {
+        let fr_name_and_span  = self.get_var_name_and_span_for_region(
+            infcx.tcx, mir, fr);
+        let outlived_fr_name_and_span = self.get_var_name_and_span_for_region(
+            infcx.tcx, mir,outlived_fr);
+
+        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, outlived_fr, category,
+                                             span);
+        }
+
         let diag = &mut infcx.tcx.sess.struct_span_err(
             *span, &format!("borrowed data escapes outside of closure"),
         );
 
-        let (outlived_fr_name, outlived_fr_span) = self.get_var_name_and_span_for_region(
-            infcx.tcx, mir, outlived_fr);
-
-        if let Some(name) = outlived_fr_name {
-            diag.span_label(
-                outlived_fr_span,
-                format!("`{}` is declared here, outside of the closure body", name),
-            );
+        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),
+                );
+            }
         }
 
-        let (fr_name, fr_span) = self.get_var_name_and_span_for_region(infcx.tcx, mir, fr);
+        if let Some((fr_name, fr_span)) = fr_name_and_span {
+            if let Some(name) = fr_name {
+                diag.span_label(
+                    fr_span,
+                    format!("`{}` is a reference that is only valid in the closure body", name),
+                );
 
-        if let Some(name) = fr_name {
-            diag.span_label(
-                fr_span,
-                format!("`{}` is a reference that is only valid in the closure body", name),
-            );
-
-            diag.span_label(*span, format!("`{}` escapes the closure body here", name));
+                diag.span_label(*span, format!("`{}` escapes the closure body here", name));
+            }
         }
 
         diag.emit();
index ba572de0de7efd69542acd12529cd4217cfcaa2e..f1c3a7489ee8f1f2ead6a6f2c65473741b63f08b 100644 (file)
@@ -22,7 +22,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
         tcx: TyCtxt<'_, '_, 'tcx>,
         mir: &Mir<'tcx>,
         fr: RegionVid,
-    ) -> (Option<Symbol>, Span) {
+    ) -> Option<(Option<Symbol>, Span)> {
         debug!("get_var_name_and_span_for_region(fr={:?})", fr);
         assert!(self.universal_regions.is_universal_region(fr));
 
@@ -37,7 +37,6 @@ impl<'tcx> RegionInferenceContext<'tcx> {
                 self.get_argument_index_for_region(tcx, fr)
                     .map(|index| self.get_argument_name_and_span_for_region(mir, index))
             })
-            .unwrap_or_else(|| span_bug!(mir.span, "can't find var name for free region {:?}", fr))
     }
 
     /// Search the upvars (if any) to find one that references fr. Return its index.
index 5904e98753694a894369ed34ec88fae166766fb8..b0fbcd3ad9f39e53d7c0a36c1b6b60b14f9ebcfc 100644 (file)
@@ -4,17 +4,17 @@ warning: not reporting region error due to nll
 LL |     let mut lines_to_use: Vec<&CrateId> = Vec::new();
    |                               ^
 
-error: unsatisfied lifetime constraints
+error: borrowed data escapes outside of closure
   --> $DIR/issue-7573.rs:32:9
    |
 LL |     let mut lines_to_use: Vec<&CrateId> = Vec::new();
-   |         ---------------- lifetime `'2` appears in the type of `lines_to_use`
+   |         ---------------- `lines_to_use` is declared here, outside of the closure body
 LL |         //~^ NOTE cannot infer an appropriate lifetime
 LL |     let push_id = |installed_id: &CrateId| {
-   |                                  - let's call the lifetime of this reference `'1`
+   |                    ------------ `installed_id` is a reference that is only valid in the closure body
 ...
 LL |         lines_to_use.push(installed_id);
-   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ argument requires that `'1` must outlive `'2`
+   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `installed_id` escapes the closure body here
 
 error: aborting due to previous error
 
index 19e10ba6da8b99ec52b83297ab71d9998dff3dd2..e26b1956d5e819632e0fb6d090636b36837f6375 100644 (file)
@@ -4,11 +4,13 @@ warning: not reporting region error due to nll
 LL |     static_val(x); //~ ERROR cannot infer
    |                ^
 
-error: unsatisfied lifetime constraints
+error: borrowed data escapes outside of closure
   --> $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
 LL |     static_val(x); //~ ERROR cannot infer
-   |     ^^^^^^^^^^^^^ argument requires that `'a` must outlive `'static`
+   |     ^^^^^^^^^^^^^ `x` escapes the closure body here
 
 error: aborting due to previous error
 
index d789f580b2738ffbac6e6bb9827ef4d2e6afd255..f9dda27da0985b36f5d022e4598a1ca6783a859a 100644 (file)
@@ -10,13 +10,13 @@ warning: not reporting region error due to nll
 LL |         self.a(); //~ ERROR cannot infer
    |              ^
 
-error: unsatisfied lifetime constraints
+error: borrowed data escapes outside of closure
   --> $DIR/issue-16683.rs:14:9
    |
 LL |     fn b(&self) {
-   |          - let's call the lifetime of this reference `'1`
+   |          ----- `self` is a reference that is only valid in the closure body
 LL |         self.a(); //~ ERROR cannot infer
-   |         ^^^^^^^^ argument requires that `'1` must outlive `'a`
+   |         ^^^^^^^^ `self` escapes the closure body here
 
 error: aborting due to previous error
 
index 124fc6f0b3998cc51b3e7eb43d8e0b4f03a2f530..5775135aefc5feb472aaed348d862134190e0f28 100644 (file)
@@ -10,13 +10,13 @@ warning: not reporting region error due to nll
 LL |         self.foo();
    |              ^^^
 
-error: unsatisfied lifetime constraints
+error: borrowed data escapes outside of closure
   --> $DIR/issue-17758.rs:17:9
    |
 LL |     fn bar(&self) {
-   |            - let's call the lifetime of this reference `'1`
+   |            ----- `self` is a reference that is only valid in the closure body
 LL |         self.foo();
-   |         ^^^^^^^^^^ argument requires that `'1` must outlive `'a`
+   |         ^^^^^^^^^^ `self` escapes the closure body here
 
 error: aborting due to previous error
 
index 8fd5e898c8d9bff140e95e3701a7118ad3d50096..d51ba8201aaa62a168151c3ab24b0bf4b3393aeb 100644 (file)
@@ -4,16 +4,16 @@ warning: not reporting region error due to nll
 LL |     foo(cell, |cell_a, cell_x| {
    |     ^^^
 
-error: unsatisfied lifetime constraints
+error: borrowed data escapes outside of closure
   --> $DIR/propagate-approximated-shorter-to-static-comparing-against-free.rs:33:20
    |
 LL |     foo(cell, |cell_a, cell_x| {
-   |                ------  ------ lifetime `'1` appears in this argument
+   |                ------  ------ `cell_x` is a reference that is only valid in the closure body
    |                |
-   |                lifetime `'2` appears in this argument
+   |                `cell_a` is declared here, outside of the closure body
 LL |         //~^ WARNING not reporting region error due to nll
 LL |         cell_a.set(cell_x.get()); // forces 'x: 'a, error in closure
-   |                    ^^^^^^^^^^^^ argument requires that `'1` must outlive `'2`
+   |                    ^^^^^^^^^^^^ `cell_x` escapes the closure body here
 
 note: No external requirements
   --> $DIR/propagate-approximated-shorter-to-static-comparing-against-free.rs:31:15
index f65e7161ca8c5e058654246bd5371a56c6d04097..3177cd7c28f647991730cc80908e060b638d12d8 100644 (file)
@@ -23,16 +23,18 @@ LL | |     });
    = note: number of external vids: 2
    = note: where '_#1r: '_#0r
 
-error: unsatisfied lifetime constraints
+error: borrowed data escapes outside of closure
   --> $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
 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 | |     });
-   | |______^ argument requires that `'a` must outlive `'static`
+   | |______^ `cell_a` escapes the closure body here
 
 note: No external requirements
   --> $DIR/propagate-approximated-shorter-to-static-no-bound.rs:44:1
index f1b2c9f198d69d4474e2d29d4fb0e2eee48748da..089c88abcdd4aee5ae8fed1eed5a8630597668ed 100644 (file)
@@ -23,16 +23,18 @@ LL | |     });
    = note: number of external vids: 3
    = note: where '_#1r: '_#0r
 
-error: unsatisfied lifetime constraints
+error: borrowed data escapes outside of closure
   --> $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
 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 | |     });
-   | |______^ argument requires that `'a` must outlive `'static`
+   | |______^ `cell_a` escapes the closure body here
 
 note: No external requirements
   --> $DIR/propagate-approximated-shorter-to-static-wrong-bound.rs:47:1
index 48862166f897f6507e7af8ba33814339002d15c0..8acf2ef51ecd2ef65b4c0ef822f3ba0085251fcd 100644 (file)
@@ -1,8 +1,11 @@
-error: unsatisfied lifetime constraints
+error: borrowed data escapes outside of closure
   --> $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
+...
 LL |     let _x = *s; //~ ERROR
-   |              ^^ assignment requires that `'a` must outlive `'static`
+   |              ^^ `s` escapes the closure body here
 
 error: aborting due to previous error