about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEsteban Küber <esteban@kuber.com.ar>2020-05-26 17:20:08 -0700
committerEsteban Küber <esteban@kuber.com.ar>2020-05-30 10:22:26 -0700
commit731ea85f215f03fc33a92147d6cc51a01dee589f (patch)
treee17520c5a38a3477fd223f93945fbb8e6d610f88
parent65f492be121ee9901d8c4305629cf4f2ad88f6d8 (diff)
downloadrust-731ea85f215f03fc33a92147d6cc51a01dee589f.tar.gz
rust-731ea85f215f03fc33a92147d6cc51a01dee589f.zip
review comment: tweak wording and account for span overlap
-rw-r--r--src/librustc_infer/infer/error_reporting/mod.rs3
-rw-r--r--src/librustc_infer/infer/error_reporting/nice_region_error/static_impl_trait.rs19
-rw-r--r--src/test/ui/async-await/issues/issue-62097.stderr2
-rw-r--r--src/test/ui/impl-trait/must_outlive_least_region_or_bound.stderr6
-rw-r--r--src/test/ui/impl-trait/static-return-lifetime-infered.stderr4
-rw-r--r--src/test/ui/issues/issue-16922.stderr2
-rw-r--r--src/test/ui/object-lifetime/object-lifetime-default-from-box-error.stderr5
-rw-r--r--src/test/ui/regions/region-object-lifetime-in-coercion.stderr2
-rw-r--r--src/test/ui/self/arbitrary_self_types_pin_lifetime_impl_trait-async.stderr2
-rw-r--r--src/test/ui/self/arbitrary_self_types_pin_lifetime_impl_trait.stderr2
-rw-r--r--src/test/ui/suggestions/lifetimes/missing-lifetimes-in-signature.stderr6
-rw-r--r--src/test/ui/underscore-lifetime/dyn-trait-underscore.stderr10
12 files changed, 38 insertions, 25 deletions
diff --git a/src/librustc_infer/infer/error_reporting/mod.rs b/src/librustc_infer/infer/error_reporting/mod.rs
index a7b40d39215..d00c90d06e4 100644
--- a/src/librustc_infer/infer/error_reporting/mod.rs
+++ b/src/librustc_infer/infer/error_reporting/mod.rs
@@ -1806,8 +1806,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
             |err: &mut DiagnosticBuilder<'tcx>,
              type_param_span: Option<(Span, bool, bool)>,
              bound_kind: GenericKind<'tcx>| {
-                let msg = "consider introducing an explicit lifetime bound to unify the type \
-                    parameter and the output";
+                let msg = "consider introducing an explicit lifetime bound";
                 if let Some((sp, has_lifetimes, is_impl_trait)) = type_param_span {
                     let suggestion = if is_impl_trait {
                         (sp.shrink_to_hi(), format!(" + {}", new_lt))
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 1a8b7fda179..5c5c86a4fb1 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
@@ -27,8 +27,23 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
                     let return_sp = sub_origin.span();
                     let mut err =
                         self.tcx().sess.struct_span_err(sp, "cannot infer an appropriate lifetime");
-                    err.span_label(return_sp, "this evaluates to the `'static` lifetime...");
-                    err.span_label(sup_origin.span(), "...but this borrow...");
+                    if sp == sup_origin.span() && return_sp == sp {
+                        // Example: `ui/object-lifetime/object-lifetime-default-from-box-error.rs`
+                        err.span_label(
+                            sup_origin.span(),
+                            "this needs to be `'static` but the borrow...",
+                        );
+                    } else {
+                        err.span_label(return_sp, "this is `'static`...");
+                        // We try to make the output have fewer overlapping spans if possible.
+                        if sp == sup_origin.span() || !return_sp.overlaps(sup_origin.span()) {
+                            // When `sp == sup_origin` we already have overlapping spans in the
+                            // main diagnostic output, so we don't split this into its own note.
+                            err.span_label(sup_origin.span(), "...but this borrow...");
+                        } else {
+                            err.span_note(sup_origin.span(), "...but this borrow...");
+                        }
+                    }
 
                     let (lifetime, lt_sp_opt) = msg_span_from_free_region(self.tcx(), sup_r);
                     if let Some(lifetime_sp) = lt_sp_opt {
diff --git a/src/test/ui/async-await/issues/issue-62097.stderr b/src/test/ui/async-await/issues/issue-62097.stderr
index cd141b82e41..161b2565c3d 100644
--- a/src/test/ui/async-await/issues/issue-62097.stderr
+++ b/src/test/ui/async-await/issues/issue-62097.stderr
@@ -4,7 +4,7 @@ error: cannot infer an appropriate lifetime
 LL |     pub async fn run_dummy_fn(&self) {
    |                               ^^^^^ ...but this borrow...
 LL |         foo(|| self.bar()).await;
-   |         --- this evaluates to the `'static` lifetime...
+   |         --- this is `'static`...
    |
 note: ...can't outlive the lifetime `'_` as defined on the method body at 12:31
   --> $DIR/issue-62097.rs:12:31
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 42667d6ca1a..9d068d70bd4 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
@@ -4,7 +4,7 @@ error: cannot infer an appropriate lifetime
 LL | fn elided(x: &i32) -> impl Copy { x }
    |                       ---------   ^ ...but this borrow...
    |                       |
-   |                       this evaluates to the `'static` lifetime...
+   |                       this is `'static`...
    |
 note: ...can't outlive the anonymous lifetime #1 defined on the function body at 3:1
   --> $DIR/must_outlive_least_region_or_bound.rs:3:1
@@ -22,7 +22,7 @@ error: cannot infer an appropriate lifetime
 LL | fn explicit<'a>(x: &'a i32) -> impl Copy { x }
    |                                ---------   ^ ...but this borrow...
    |                                |
-   |                                this evaluates to the `'static` lifetime...
+   |                                this is `'static`...
    |
 note: ...can't outlive the lifetime `'a` as defined on the function body at 6:13
   --> $DIR/must_outlive_least_region_or_bound.rs:6:13
@@ -40,7 +40,7 @@ error: cannot infer an appropriate lifetime
 LL | fn with_bound<'a>(x: &'a i32) -> impl LifetimeTrait<'a> + 'static { x }
    |                                  --------------------------------   ^ ...but this borrow...
    |                                  |
-   |                                  this evaluates to the `'static` lifetime...
+   |                                  this is `'static`...
    |
 note: ...can't outlive the lifetime `'a` as defined on the function body at 12:15
   --> $DIR/must_outlive_least_region_or_bound.rs:12:15
diff --git a/src/test/ui/impl-trait/static-return-lifetime-infered.stderr b/src/test/ui/impl-trait/static-return-lifetime-infered.stderr
index 963de2d448d..645c7e1e195 100644
--- a/src/test/ui/impl-trait/static-return-lifetime-infered.stderr
+++ b/src/test/ui/impl-trait/static-return-lifetime-infered.stderr
@@ -2,7 +2,7 @@ error: cannot infer an appropriate lifetime
   --> $DIR/static-return-lifetime-infered.rs:7:16
    |
 LL |     fn iter_values_anon(&self) -> impl Iterator<Item=u32> {
-   |                                   ----------------------- this evaluates to the `'static` lifetime...
+   |                                   ----------------------- this is `'static`...
 LL |         self.x.iter().map(|a| a.0)
    |         ------ ^^^^
    |         |
@@ -24,7 +24,7 @@ error: cannot infer an appropriate lifetime
   --> $DIR/static-return-lifetime-infered.rs:11:16
    |
 LL |     fn iter_values<'a>(&'a self) -> impl Iterator<Item=u32> {
-   |                                     ----------------------- this evaluates to the `'static` lifetime...
+   |                                     ----------------------- this is `'static`...
 LL |         self.x.iter().map(|a| a.0)
    |         ------ ^^^^
    |         |
diff --git a/src/test/ui/issues/issue-16922.stderr b/src/test/ui/issues/issue-16922.stderr
index 8bcfe979ce1..20a6b287429 100644
--- a/src/test/ui/issues/issue-16922.stderr
+++ b/src/test/ui/issues/issue-16922.stderr
@@ -5,7 +5,7 @@ LL |     Box::new(value) as Box<dyn Any>
    |     ---------^^^^^-
    |     |        |
    |     |        ...but this borrow...
-   |     this evaluates to the `'static` lifetime...
+   |     this is `'static`...
    |
 note: ...can't outlive the anonymous lifetime #1 defined on the function body at 3:1
   --> $DIR/issue-16922.rs:3:1
diff --git a/src/test/ui/object-lifetime/object-lifetime-default-from-box-error.stderr b/src/test/ui/object-lifetime/object-lifetime-default-from-box-error.stderr
index 7981d082c80..465409c6398 100644
--- a/src/test/ui/object-lifetime/object-lifetime-default-from-box-error.stderr
+++ b/src/test/ui/object-lifetime/object-lifetime-default-from-box-error.stderr
@@ -2,10 +2,7 @@ error: cannot infer an appropriate lifetime
   --> $DIR/object-lifetime-default-from-box-error.rs:18:5
    |
 LL |     ss.r
-   |     ^^^^
-   |     |
-   |     this evaluates to the `'static` lifetime...
-   |     ...but this borrow...
+   |     ^^^^ this needs to be `'static` but the borrow...
    |
 note: ...can't outlive the anonymous lifetime #2 defined on the function body at 14:1
   --> $DIR/object-lifetime-default-from-box-error.rs:14:1
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 8048b79b015..5a414c477a6 100644
--- a/src/test/ui/regions/region-object-lifetime-in-coercion.stderr
+++ b/src/test/ui/regions/region-object-lifetime-in-coercion.stderr
@@ -21,7 +21,7 @@ LL |     Box::new(v)
    |     ---------^-
    |     |        |
    |     |        ...but this borrow...
-   |     this evaluates to the `'static` lifetime...
+   |     this is `'static`...
    |
 note: ...can't outlive the anonymous lifetime #1 defined on the function body at 17:1
   --> $DIR/region-object-lifetime-in-coercion.rs:17:1
diff --git a/src/test/ui/self/arbitrary_self_types_pin_lifetime_impl_trait-async.stderr b/src/test/ui/self/arbitrary_self_types_pin_lifetime_impl_trait-async.stderr
index fcde3bb5ca6..21775539cea 100644
--- a/src/test/ui/self/arbitrary_self_types_pin_lifetime_impl_trait-async.stderr
+++ b/src/test/ui/self/arbitrary_self_types_pin_lifetime_impl_trait-async.stderr
@@ -2,7 +2,7 @@ error: cannot infer an appropriate lifetime
   --> $DIR/arbitrary_self_types_pin_lifetime_impl_trait-async.rs:8:16
    |
 LL |     async fn f(self: Pin<&Self>) -> impl Clone { self }
-   |                ^^^^                 ---------- this evaluates to the `'static` lifetime...
+   |                ^^^^                 ---------- this is `'static`...
    |                |
    |                ...but this borrow...
    |
diff --git a/src/test/ui/self/arbitrary_self_types_pin_lifetime_impl_trait.stderr b/src/test/ui/self/arbitrary_self_types_pin_lifetime_impl_trait.stderr
index c89ee27aa8c..e931cec8a2a 100644
--- a/src/test/ui/self/arbitrary_self_types_pin_lifetime_impl_trait.stderr
+++ b/src/test/ui/self/arbitrary_self_types_pin_lifetime_impl_trait.stderr
@@ -4,7 +4,7 @@ error: cannot infer an appropriate lifetime
 LL |     fn f(self: Pin<&Self>) -> impl Clone { self }
    |                               ----------   ^^^^ ...but this borrow...
    |                               |
-   |                               this evaluates to the `'static` lifetime...
+   |                               this is `'static`...
    |
 note: ...can't outlive the anonymous lifetime #1 defined on the method body at 6:5
   --> $DIR/arbitrary_self_types_pin_lifetime_impl_trait.rs:6:5
diff --git a/src/test/ui/suggestions/lifetimes/missing-lifetimes-in-signature.stderr b/src/test/ui/suggestions/lifetimes/missing-lifetimes-in-signature.stderr
index 5a2530bdcbb..d6d2a0c4d2b 100644
--- a/src/test/ui/suggestions/lifetimes/missing-lifetimes-in-signature.stderr
+++ b/src/test/ui/suggestions/lifetimes/missing-lifetimes-in-signature.stderr
@@ -10,7 +10,7 @@ error: cannot infer an appropriate lifetime
   --> $DIR/missing-lifetimes-in-signature.rs:19:5
    |
 LL |   fn foo<G, T>(g: G, dest: &mut T) -> impl FnOnce()
-   |                                       ------------- this evaluates to the `'static` lifetime...
+   |                                       ------------- this is `'static`...
 ...
 LL | /     move || {
 LL | |         *dest = g.get();
@@ -55,7 +55,7 @@ note: ...so that the type `[closure@$DIR/missing-lifetimes-in-signature.rs:30:5:
    |
 LL | fn bar<G, T>(g: G, dest: &mut T) -> impl FnOnce() + '_
    |                                     ^^^^^^^^^^^^^^^^^^
-help: consider introducing an explicit lifetime bound to unify the type parameter and the output
+help: consider introducing an explicit lifetime bound
    |
 LL | fn bar<'a, G: 'a, T>(g: G, dest: &mut T) -> impl FnOnce() + '_ + 'a
    |        ^^^^^                                                   ^^^^
@@ -82,7 +82,7 @@ note: ...so that the type `[closure@$DIR/missing-lifetimes-in-signature.rs:52:5:
    |
 LL | fn qux<'a, G: 'a, T>(g: G, dest: &mut T) -> impl FnOnce() + '_
    |                                             ^^^^^^^^^^^^^^^^^^
-help: consider introducing an explicit lifetime bound to unify the type parameter and the output
+help: consider introducing an explicit lifetime bound
    |
 LL | fn qux<'b, 'a, G: 'b + 'a, T>(g: G, dest: &mut T) -> impl FnOnce() + '_ + 'b
    |        ^^^     ^^^^^^^                                                  ^^^^
diff --git a/src/test/ui/underscore-lifetime/dyn-trait-underscore.stderr b/src/test/ui/underscore-lifetime/dyn-trait-underscore.stderr
index 65714d16a81..bcbdec4f306 100644
--- a/src/test/ui/underscore-lifetime/dyn-trait-underscore.stderr
+++ b/src/test/ui/underscore-lifetime/dyn-trait-underscore.stderr
@@ -2,11 +2,13 @@ error: cannot infer an appropriate lifetime
   --> $DIR/dyn-trait-underscore.rs:8:20
    |
 LL |     Box::new(items.iter())
-   |     ---------------^^^^---
-   |     |        |
-   |     |        ...but this borrow...
-   |     this evaluates to the `'static` lifetime...
+   |     ---------------^^^^--- this is `'static`...
    |
+note: ...but this borrow...
+  --> $DIR/dyn-trait-underscore.rs:8:14
+   |
+LL |     Box::new(items.iter())
+   |              ^^^^^
 note: ...can't outlive the anonymous lifetime #1 defined on the function body at 6:1
   --> $DIR/dyn-trait-underscore.rs:6:1
    |