about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEsteban Küber <esteban@kuber.com.ar>2020-05-29 19:46:22 -0700
committerEsteban Küber <esteban@kuber.com.ar>2020-06-15 09:06:57 -0700
commite75588934c01d6bc9abb02979eb61168a7b5c598 (patch)
tree361b03ebf5188f39cfcdf136f674c923bdacc8c7
parent921f35fe73e8749dee8531f7fbaf2cb4958fa799 (diff)
downloadrust-e75588934c01d6bc9abb02979eb61168a7b5c598.tar.gz
rust-e75588934c01d6bc9abb02979eb61168a7b5c598.zip
Move overlapping span to a note
-rw-r--r--src/librustc_infer/infer/error_reporting/nice_region_error/static_impl_trait.rs31
-rw-r--r--src/test/ui/impl-trait/must_outlive_least_region_or_bound.stderr44
-rw-r--r--src/test/ui/issues/issue-16922.stderr10
-rw-r--r--src/test/ui/regions/region-object-lifetime-in-coercion.stderr30
-rw-r--r--src/test/ui/regions/regions-close-object-into-object-2.stderr10
-rw-r--r--src/test/ui/regions/regions-close-object-into-object-4.stderr10
-rw-r--r--src/test/ui/regions/regions-proc-bound-capture.stderr10
7 files changed, 99 insertions, 46 deletions
diff --git a/src/librustc_infer/infer/error_reporting/nice_region_error/static_impl_trait.rs b/src/librustc_infer/infer/error_reporting/nice_region_error/static_impl_trait.rs
index e9f165d309f..cc95441b68a 100644
--- a/src/librustc_infer/infer/error_reporting/nice_region_error/static_impl_trait.rs
+++ b/src/librustc_infer/infer/error_reporting/nice_region_error/static_impl_trait.rs
@@ -53,7 +53,36 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
 
                         // Customize the spans and labels depending on their relative order so
                         // that split sentences flow correctly.
-                        if sup_origin.span().shrink_to_hi() <= return_sp.shrink_to_lo() {
+                        if sup_origin.span().overlaps(return_sp) && sp == sup_origin.span() {
+                            // Avoid the following:
+                            //
+                            // error: cannot infer an appropriate lifetime
+                            //   --> $DIR/must_outlive_least_region_or_bound.rs:18:50
+                            //    |
+                            // LL | fn foo(x: &i32) -> Box<dyn Debug> { Box::new(x) }
+                            //    |           ----                      ---------^-
+                            //    |           |                         |        |
+                            //    |           |                         |   ...and is captured here
+                            //    |           |           ...is required to be `'static` by this...
+                            //    |           this data with the anonymous lifetime `'_`...
+                            //
+                            // and instead show:
+                            //
+                            // error: cannot infer an appropriate lifetime
+                            //   --> $DIR/must_outlive_least_region_or_bound.rs:18:50
+                            //    |
+                            // LL | fn foo(x: &i32) -> Box<dyn Debug> { Box::new(x) }
+                            //    |           ----                               ^ ...is captured here with a `'static` requirement
+                            //    |           |
+                            //    |           this data with the anonymous lifetime `'_`...
+                            //    |
+                            // note: ...is required to be `'static` by this
+                            //    |
+                            // LL | fn elided3(x: &i32) -> Box<dyn Debug> { Box::new(x) }
+                            //    |                                         ^^^^^^^^^^^
+                            err.span_label(sup_origin.span(), "...is captured here...");
+                            err.span_note(return_sp, "...and required to be `'static` by this");
+                        } else if sup_origin.span() <= return_sp {
                             err.span_label(sup_origin.span(), "...is captured here...");
                             err.span_label(return_sp, "...and required to be `'static` by this");
                         } else {
diff --git a/src/test/ui/impl-trait/must_outlive_least_region_or_bound.stderr b/src/test/ui/impl-trait/must_outlive_least_region_or_bound.stderr
index 00b6ec38323..2da49379ea8 100644
--- a/src/test/ui/impl-trait/must_outlive_least_region_or_bound.stderr
+++ b/src/test/ui/impl-trait/must_outlive_least_region_or_bound.stderr
@@ -109,12 +109,15 @@ error: cannot infer an appropriate lifetime
   --> $DIR/must_outlive_least_region_or_bound.rs:18:50
    |
 LL | fn elided3(x: &i32) -> Box<dyn Debug> { Box::new(x) }
-   |               ----                      ---------^-
-   |               |                         |        |
-   |               |                         |        ...and is captured here
-   |               |                         ...is required to be `'static` by this...
+   |               ----                               ^ ...is captured here...
+   |               |
    |               this data with the anonymous lifetime `'_`...
    |
+note: ...and required to be `'static` by this
+  --> $DIR/must_outlive_least_region_or_bound.rs:18:41
+   |
+LL | fn elided3(x: &i32) -> Box<dyn Debug> { Box::new(x) }
+   |                                         ^^^^^^^^^^^
 help: to permit non-static references in a trait object value, you can add an explicit bound for the anonymous lifetime `'_`
    |
 LL | fn elided3(x: &i32) -> Box<dyn Debug + '_> { Box::new(x) }
@@ -124,12 +127,15 @@ error: cannot infer an appropriate lifetime
   --> $DIR/must_outlive_least_region_or_bound.rs:21:59
    |
 LL | fn explicit3<'a>(x: &'a i32) -> Box<dyn Debug> { Box::new(x) }
-   |                     -------                      ---------^-
-   |                     |                            |        |
-   |                     |                            |        ...and is captured here
-   |                     |                            ...is required to be `'static` by this...
+   |                     -------                               ^ ...is captured here...
+   |                     |
    |                     this data with lifetime `'a`...
    |
+note: ...and required to be `'static` by this
+  --> $DIR/must_outlive_least_region_or_bound.rs:21:50
+   |
+LL | fn explicit3<'a>(x: &'a i32) -> Box<dyn Debug> { Box::new(x) }
+   |                                                  ^^^^^^^^^^^
 help: to permit non-static references in a trait object value, you can add an explicit bound for lifetime `'a`
    |
 LL | fn explicit3<'a>(x: &'a i32) -> Box<dyn Debug + 'a> { Box::new(x) }
@@ -139,12 +145,15 @@ error: cannot infer an appropriate lifetime
   --> $DIR/must_outlive_least_region_or_bound.rs:24:60
    |
 LL | fn elided4(x: &i32) -> Box<dyn Debug + 'static> { Box::new(x) }
-   |               ----                                ---------^-
-   |               |                                   |        |
-   |               |                                   |        ...and is captured here
-   |               |                                   ...is required to be `'static` by this...
+   |               ----                                         ^ ...is captured here...
+   |               |
    |               this data with the anonymous lifetime `'_`...
    |
+note: ...and required to be `'static` by this
+  --> $DIR/must_outlive_least_region_or_bound.rs:24:51
+   |
+LL | fn elided4(x: &i32) -> Box<dyn Debug + 'static> { Box::new(x) }
+   |                                                   ^^^^^^^^^^^
 help: consider changing the trait object's explicit `'static` bound to the anonymous lifetime `'_`
    |
 LL | fn elided4(x: &i32) -> Box<dyn Debug + '_> { Box::new(x) }
@@ -158,12 +167,13 @@ error: cannot infer an appropriate lifetime
   --> $DIR/must_outlive_least_region_or_bound.rs:27:69
    |
 LL | fn explicit4<'a>(x: &'a i32) -> Box<dyn Debug + 'static> { Box::new(x) }
-   |                     -------                                ---------^-
-   |                     |                                      |        |
-   |                     |                                      |        ...and is captured here
-   |                     |                                      ...is required to be `'static` by this...
-   |                     this data with lifetime `'a`...
+   |                     ------- this data with lifetime `'a`...         ^ ...is captured here...
    |
+note: ...and required to be `'static` by this
+  --> $DIR/must_outlive_least_region_or_bound.rs:27:60
+   |
+LL | fn explicit4<'a>(x: &'a i32) -> Box<dyn Debug + 'static> { Box::new(x) }
+   |                                                            ^^^^^^^^^^^
 help: consider changing the trait object's explicit `'static` bound to lifetime `'a`
    |
 LL | fn explicit4<'a>(x: &'a i32) -> Box<dyn Debug + 'a> { Box::new(x) }
diff --git a/src/test/ui/issues/issue-16922.stderr b/src/test/ui/issues/issue-16922.stderr
index c533a72dfc0..6c0b26a86b6 100644
--- a/src/test/ui/issues/issue-16922.stderr
+++ b/src/test/ui/issues/issue-16922.stderr
@@ -4,11 +4,13 @@ error: cannot infer an appropriate lifetime
 LL | fn foo<T: Any>(value: &T) -> Box<dyn Any> {
    |                       -- this data with the anonymous lifetime `'_`...
 LL |     Box::new(value) as Box<dyn Any>
-   |     ---------^^^^^-
-   |     |        |
-   |     |        ...and is captured here
-   |     ...is required to be `'static` by this...
+   |              ^^^^^ ...is captured here...
    |
+note: ...and required to be `'static` by this
+  --> $DIR/issue-16922.rs:4:5
+   |
+LL |     Box::new(value) as Box<dyn Any>
+   |     ^^^^^^^^^^^^^^^
 help: to permit non-static references in a trait object value, you can add an explicit bound for the anonymous lifetime `'_`
    |
 LL | fn foo<T: Any>(value: &T) -> Box<dyn Any + '_> {
diff --git a/src/test/ui/regions/region-object-lifetime-in-coercion.stderr b/src/test/ui/regions/region-object-lifetime-in-coercion.stderr
index 4b08c4bff2e..b333c314c57 100644
--- a/src/test/ui/regions/region-object-lifetime-in-coercion.stderr
+++ b/src/test/ui/regions/region-object-lifetime-in-coercion.stderr
@@ -4,11 +4,13 @@ error: cannot infer an appropriate lifetime
 LL | fn a(v: &[u8]) -> Box<dyn Foo + 'static> {
    |         ----- this data with the anonymous lifetime `'_`...
 LL |     let x: Box<dyn Foo + 'static> = Box::new(v);
-   |                                     ---------^-
-   |                                     |        |
-   |                                     |        ...and is captured here
-   |                                     ...is required to be `'static` by this...
+   |                                              ^ ...is captured here...
    |
+note: ...and required to be `'static` by this
+  --> $DIR/region-object-lifetime-in-coercion.rs:8:37
+   |
+LL |     let x: Box<dyn Foo + 'static> = Box::new(v);
+   |                                     ^^^^^^^^^^^
 help: consider changing the trait object's explicit `'static` bound to the anonymous lifetime `'_`
    |
 LL | fn a(v: &[u8]) -> Box<dyn Foo + '_> {
@@ -24,11 +26,13 @@ error: cannot infer an appropriate lifetime
 LL | fn b(v: &[u8]) -> Box<dyn Foo + 'static> {
    |         ----- this data with the anonymous lifetime `'_`...
 LL |     Box::new(v)
-   |     ---------^-
-   |     |        |
-   |     |        ...and is captured here
-   |     ...is required to be `'static` by this...
+   |              ^ ...is captured here...
    |
+note: ...and required to be `'static` by this
+  --> $DIR/region-object-lifetime-in-coercion.rs:13:5
+   |
+LL |     Box::new(v)
+   |     ^^^^^^^^^^^
 help: consider changing the trait object's explicit `'static` bound to the anonymous lifetime `'_`
    |
 LL | fn b(v: &[u8]) -> Box<dyn Foo + '_> {
@@ -45,11 +49,13 @@ LL | fn c(v: &[u8]) -> Box<dyn Foo> {
    |         ----- this data with the anonymous lifetime `'_`...
 ...
 LL |     Box::new(v)
-   |     ---------^-
-   |     |        |
-   |     |        ...and is captured here
-   |     ...is required to be `'static` by this...
+   |              ^ ...is captured here...
+   |
+note: ...and required to be `'static` by this
+  --> $DIR/region-object-lifetime-in-coercion.rs:19:5
    |
+LL |     Box::new(v)
+   |     ^^^^^^^^^^^
 help: to permit non-static references in a trait object value, you can add an explicit bound for the anonymous lifetime `'_`
    |
 LL | fn c(v: &[u8]) -> Box<dyn Foo + '_> {
diff --git a/src/test/ui/regions/regions-close-object-into-object-2.stderr b/src/test/ui/regions/regions-close-object-into-object-2.stderr
index 894be310fd1..3127ae65ace 100644
--- a/src/test/ui/regions/regions-close-object-into-object-2.stderr
+++ b/src/test/ui/regions/regions-close-object-into-object-2.stderr
@@ -4,11 +4,13 @@ error: cannot infer an appropriate lifetime
 LL | fn g<'a, T: 'static>(v: Box<dyn A<T> + 'a>) -> Box<dyn X + 'static> {
    |                         ------------------ this data with lifetime `'a`...
 LL |     box B(&*v) as Box<dyn X>
-   |     ------^^^---------------
-   |     |     |
-   |     |     ...and is captured here
-   |     ...is required to be `'static` by this...
+   |           ^^^ ...is captured here...
    |
+note: ...and required to be `'static` by this
+  --> $DIR/regions-close-object-into-object-2.rs:10:5
+   |
+LL |     box B(&*v) as Box<dyn X>
+   |     ^^^^^^^^^^^^^^^^^^^^^^^^
 help: consider changing the trait object's explicit `'static` bound to lifetime `'a`
    |
 LL | fn g<'a, T: 'static>(v: Box<dyn A<T> + 'a>) -> Box<dyn X + 'a> {
diff --git a/src/test/ui/regions/regions-close-object-into-object-4.stderr b/src/test/ui/regions/regions-close-object-into-object-4.stderr
index ce261d78c29..b18c61f1376 100644
--- a/src/test/ui/regions/regions-close-object-into-object-4.stderr
+++ b/src/test/ui/regions/regions-close-object-into-object-4.stderr
@@ -4,11 +4,13 @@ error: cannot infer an appropriate lifetime
 LL | fn i<'a, T, U>(v: Box<dyn A<U>+'a>) -> Box<dyn X + 'static> {
    |                   ---------------- this data with lifetime `'a`...
 LL |     box B(&*v) as Box<dyn X>
-   |     ------^^^---------------
-   |     |     |
-   |     |     ...and is captured here
-   |     ...is required to be `'static` by this...
+   |           ^^^ ...is captured here...
    |
+note: ...and required to be `'static` by this
+  --> $DIR/regions-close-object-into-object-4.rs:10:5
+   |
+LL |     box B(&*v) as Box<dyn X>
+   |     ^^^^^^^^^^^^^^^^^^^^^^^^
 help: consider changing the trait object's explicit `'static` bound to lifetime `'a`
    |
 LL | fn i<'a, T, U>(v: Box<dyn A<U>+'a>) -> Box<dyn X + 'a> {
diff --git a/src/test/ui/regions/regions-proc-bound-capture.stderr b/src/test/ui/regions/regions-proc-bound-capture.stderr
index a0df1815247..5cb9506afd3 100644
--- a/src/test/ui/regions/regions-proc-bound-capture.stderr
+++ b/src/test/ui/regions/regions-proc-bound-capture.stderr
@@ -5,11 +5,13 @@ LL | fn static_proc(x: &isize) -> Box<dyn FnMut() -> (isize) + 'static> {
    |                   ------ this data with the anonymous lifetime `'_`...
 LL |     // This is illegal, because the region bound on `proc` is 'static.
 LL |     Box::new(move || { *x })
-   |     ---------^^^^^^^^^^^^^^-
-   |     |        |
-   |     |        ...and is captured here
-   |     ...is required to be `'static` by this...
+   |              ^^^^^^^^^^^^^^ ...is captured here...
    |
+note: ...and required to be `'static` by this
+  --> $DIR/regions-proc-bound-capture.rs:9:5
+   |
+LL |     Box::new(move || { *x })
+   |     ^^^^^^^^^^^^^^^^^^^^^^^^
 help: consider changing the trait object's explicit `'static` bound to the anonymous lifetime `'_`
    |
 LL | fn static_proc(x: &isize) -> Box<dyn FnMut() -> (isize) + '_> {