about summary refs log tree commit diff
diff options
context:
space:
mode:
authorGuillaume Gomez <guillaume1.gomez@gmail.com>2021-05-13 15:54:14 +0200
committerGitHub <noreply@github.com>2021-05-13 15:54:14 +0200
commit3761ada94ebb9693190bc7924951b6035fd9c419 (patch)
tree119ea82bf2e99b2398f11bbfa50f2217e71843b1
parent16c825485fa51193cedc3dd9394c0a2f31016c42 (diff)
parentbc6330d47a7a81e25f492a837822121a3cd88158 (diff)
downloadrust-3761ada94ebb9693190bc7924951b6035fd9c419.tar.gz
rust-3761ada94ebb9693190bc7924951b6035fd9c419.zip
Rollup merge of #85240 - Aaron1011:no-suggest-static, r=davidtwco
Don't suggest adding `'static` lifetime to arguments

Fixes #69350

This is almost always the wrong this to do
-rw-r--r--compiler/rustc_infer/src/infer/error_reporting/nice_region_error/named_anon_conflict.rs16
-rw-r--r--src/test/ui/closures/closure-bounds-static-cant-capture-borrowed.nll.stderr2
-rw-r--r--src/test/ui/closures/closure-bounds-static-cant-capture-borrowed.stderr2
-rw-r--r--src/test/ui/generator/generator-region-requirements.stderr3
-rw-r--r--src/test/ui/generic-associated-types/projection-type-lifetime-mismatch.stderr6
-rw-r--r--src/test/ui/issues/issue-46983.stderr2
-rw-r--r--src/test/ui/nll/closure-requirements/region-lbr-anon-does-not-outlive-static.stderr2
-rw-r--r--src/test/ui/nll/guarantor-issue-46974.stderr3
-rw-r--r--src/test/ui/regions/regions-static-bound.migrate.nll.stderr5
-rw-r--r--src/test/ui/regions/regions-static-bound.migrate.stderr5
-rw-r--r--src/test/ui/regions/regions-static-bound.nll.stderr5
11 files changed, 10 insertions, 41 deletions
diff --git a/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/named_anon_conflict.rs b/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/named_anon_conflict.rs
index 2f3c0d6957a..0878f8550da 100644
--- a/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/named_anon_conflict.rs
+++ b/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/named_anon_conflict.rs
@@ -114,12 +114,16 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
         );
 
         diag.span_label(span, format!("lifetime `{}` required", named));
-        diag.span_suggestion(
-            new_ty_span,
-            &format!("add explicit lifetime `{}` to {}", named, span_label_var),
-            new_ty.to_string(),
-            Applicability::Unspecified,
-        );
+        // Suggesting `'static` is nearly always incorrect, and can steer users
+        // down the wrong path.
+        if *named != ty::ReStatic {
+            diag.span_suggestion(
+                new_ty_span,
+                &format!("add explicit lifetime `{}` to {}", named, span_label_var),
+                new_ty.to_string(),
+                Applicability::Unspecified,
+            );
+        }
 
         Some(diag)
     }
diff --git a/src/test/ui/closures/closure-bounds-static-cant-capture-borrowed.nll.stderr b/src/test/ui/closures/closure-bounds-static-cant-capture-borrowed.nll.stderr
index 1d12e2f585e..1b0e0902d67 100644
--- a/src/test/ui/closures/closure-bounds-static-cant-capture-borrowed.nll.stderr
+++ b/src/test/ui/closures/closure-bounds-static-cant-capture-borrowed.nll.stderr
@@ -1,8 +1,6 @@
 error[E0621]: explicit lifetime required in the type of `x`
   --> $DIR/closure-bounds-static-cant-capture-borrowed.rs:5:5
    |
-LL |   fn foo(x: &()) {
-   |             --- help: add explicit lifetime `'static` to the type of `x`: `&'static ()`
 LL | /     bar(|| {
 LL | |
 LL | |         let _ = x;
diff --git a/src/test/ui/closures/closure-bounds-static-cant-capture-borrowed.stderr b/src/test/ui/closures/closure-bounds-static-cant-capture-borrowed.stderr
index f50c3e3b531..a9add6184f1 100644
--- a/src/test/ui/closures/closure-bounds-static-cant-capture-borrowed.stderr
+++ b/src/test/ui/closures/closure-bounds-static-cant-capture-borrowed.stderr
@@ -1,8 +1,6 @@
 error[E0621]: explicit lifetime required in the type of `x`
   --> $DIR/closure-bounds-static-cant-capture-borrowed.rs:5:5
    |
-LL | fn foo(x: &()) {
-   |           --- help: add explicit lifetime `'static` to the type of `x`: `&'static ()`
 LL |     bar(|| {
    |     ^^^ lifetime `'static` required
 
diff --git a/src/test/ui/generator/generator-region-requirements.stderr b/src/test/ui/generator/generator-region-requirements.stderr
index 53d48bc4f56..de90a599e76 100644
--- a/src/test/ui/generator/generator-region-requirements.stderr
+++ b/src/test/ui/generator/generator-region-requirements.stderr
@@ -1,9 +1,6 @@
 error[E0621]: explicit lifetime required in the type of `x`
   --> $DIR/generator-region-requirements.rs:12:51
    |
-LL | fn dangle(x: &mut i32) -> &'static mut i32 {
-   |              -------- help: add explicit lifetime `'static` to the type of `x`: `&'static mut i32`
-...
 LL |             GeneratorState::Complete(c) => return c,
    |                                                   ^ lifetime `'static` required
 
diff --git a/src/test/ui/generic-associated-types/projection-type-lifetime-mismatch.stderr b/src/test/ui/generic-associated-types/projection-type-lifetime-mismatch.stderr
index 13b765dfa57..aec87862566 100644
--- a/src/test/ui/generic-associated-types/projection-type-lifetime-mismatch.stderr
+++ b/src/test/ui/generic-associated-types/projection-type-lifetime-mismatch.stderr
@@ -1,24 +1,18 @@
 error[E0621]: explicit lifetime required in the type of `x`
   --> $DIR/projection-type-lifetime-mismatch.rs:18:5
    |
-LL | fn f(x: &impl for<'a> X<Y<'a> = &'a ()>) -> &'static () {
-   |         ------------------------------- help: add explicit lifetime `'static` to the type of `x`: `&'static impl for<'a> X<Y<'a> = &'a ()>`
 LL |     x.m()
    |     ^^^^^ lifetime `'static` required
 
 error[E0621]: explicit lifetime required in the type of `x`
   --> $DIR/projection-type-lifetime-mismatch.rs:23:5
    |
-LL | fn g<T: for<'a> X<Y<'a> = &'a ()>>(x: &T) -> &'static () {
-   |                                       -- help: add explicit lifetime `'static` to the type of `x`: `&'static T`
 LL |     x.m()
    |     ^^^^^ lifetime `'static` required
 
 error[E0621]: explicit lifetime required in the type of `x`
   --> $DIR/projection-type-lifetime-mismatch.rs:28:5
    |
-LL | fn h(x: &()) -> &'static () {
-   |         --- help: add explicit lifetime `'static` to the type of `x`: `&'static ()`
 LL |     x.m()
    |     ^^^^^ lifetime `'static` required
 
diff --git a/src/test/ui/issues/issue-46983.stderr b/src/test/ui/issues/issue-46983.stderr
index 8a4a6bdb39f..d328329edad 100644
--- a/src/test/ui/issues/issue-46983.stderr
+++ b/src/test/ui/issues/issue-46983.stderr
@@ -1,8 +1,6 @@
 error[E0621]: explicit lifetime required in the type of `x`
   --> $DIR/issue-46983.rs:2:5
    |
-LL | fn foo(x: &u32) -> &'static u32 {
-   |           ---- help: add explicit lifetime `'static` to the type of `x`: `&'static u32`
 LL |     &*x
    |     ^^^ lifetime `'static` required
 
diff --git a/src/test/ui/nll/closure-requirements/region-lbr-anon-does-not-outlive-static.stderr b/src/test/ui/nll/closure-requirements/region-lbr-anon-does-not-outlive-static.stderr
index e813f21e01d..4c302d935db 100644
--- a/src/test/ui/nll/closure-requirements/region-lbr-anon-does-not-outlive-static.stderr
+++ b/src/test/ui/nll/closure-requirements/region-lbr-anon-does-not-outlive-static.stderr
@@ -1,8 +1,6 @@
 error[E0621]: explicit lifetime required in the type of `x`
   --> $DIR/region-lbr-anon-does-not-outlive-static.rs:9:5
    |
-LL | fn foo(x: &u32) -> &'static u32 {
-   |           ---- help: add explicit lifetime `ReStatic` to the type of `x`: `&ReStatic u32`
 LL |     &*x
    |     ^^^ lifetime `ReStatic` required
 
diff --git a/src/test/ui/nll/guarantor-issue-46974.stderr b/src/test/ui/nll/guarantor-issue-46974.stderr
index 361466c4d54..eabc3105c02 100644
--- a/src/test/ui/nll/guarantor-issue-46974.stderr
+++ b/src/test/ui/nll/guarantor-issue-46974.stderr
@@ -12,9 +12,6 @@ LL |     *x
 error[E0621]: explicit lifetime required in the type of `s`
   --> $DIR/guarantor-issue-46974.rs:15:5
    |
-LL | fn bar(s: &Box<(i32,)>) -> &'static i32 {
-   |           ------------ help: add explicit lifetime `'static` to the type of `s`: `&'static Box<(i32,)>`
-LL |     // FIXME(#46983): error message should be better
 LL |     &s.0
    |     ^^^^ lifetime `'static` required
 
diff --git a/src/test/ui/regions/regions-static-bound.migrate.nll.stderr b/src/test/ui/regions/regions-static-bound.migrate.nll.stderr
index 6f2c75d2eba..a4c8e721145 100644
--- a/src/test/ui/regions/regions-static-bound.migrate.nll.stderr
+++ b/src/test/ui/regions/regions-static-bound.migrate.nll.stderr
@@ -11,17 +11,12 @@ LL |     t
 error[E0621]: explicit lifetime required in the type of `u`
   --> $DIR/regions-static-bound.rs:14:5
    |
-LL | fn error(u: &(), v: &()) {
-   |             --- help: add explicit lifetime `'static` to the type of `u`: `&'static ()`
 LL |     static_id(&u);
    |     ^^^^^^^^^^^^^ lifetime `'static` required
 
 error[E0621]: explicit lifetime required in the type of `v`
   --> $DIR/regions-static-bound.rs:16:5
    |
-LL | fn error(u: &(), v: &()) {
-   |                     --- help: add explicit lifetime `'static` to the type of `v`: `&'static ()`
-...
 LL |     static_id_indirect(&v);
    |     ^^^^^^^^^^^^^^^^^^^^^^ lifetime `'static` required
 
diff --git a/src/test/ui/regions/regions-static-bound.migrate.stderr b/src/test/ui/regions/regions-static-bound.migrate.stderr
index 6e631d40d45..644458e2063 100644
--- a/src/test/ui/regions/regions-static-bound.migrate.stderr
+++ b/src/test/ui/regions/regions-static-bound.migrate.stderr
@@ -14,17 +14,12 @@ LL | fn static_id_wrong_way<'a>(t: &'a ()) -> &'static () where 'static: 'a {
 error[E0621]: explicit lifetime required in the type of `u`
   --> $DIR/regions-static-bound.rs:14:5
    |
-LL | fn error(u: &(), v: &()) {
-   |             --- help: add explicit lifetime `'static` to the type of `u`: `&'static ()`
 LL |     static_id(&u);
    |     ^^^^^^^^^ lifetime `'static` required
 
 error[E0621]: explicit lifetime required in the type of `v`
   --> $DIR/regions-static-bound.rs:16:5
    |
-LL | fn error(u: &(), v: &()) {
-   |                     --- help: add explicit lifetime `'static` to the type of `v`: `&'static ()`
-...
 LL |     static_id_indirect(&v);
    |     ^^^^^^^^^^^^^^^^^^ lifetime `'static` required
 
diff --git a/src/test/ui/regions/regions-static-bound.nll.stderr b/src/test/ui/regions/regions-static-bound.nll.stderr
index 6f2c75d2eba..a4c8e721145 100644
--- a/src/test/ui/regions/regions-static-bound.nll.stderr
+++ b/src/test/ui/regions/regions-static-bound.nll.stderr
@@ -11,17 +11,12 @@ LL |     t
 error[E0621]: explicit lifetime required in the type of `u`
   --> $DIR/regions-static-bound.rs:14:5
    |
-LL | fn error(u: &(), v: &()) {
-   |             --- help: add explicit lifetime `'static` to the type of `u`: `&'static ()`
 LL |     static_id(&u);
    |     ^^^^^^^^^^^^^ lifetime `'static` required
 
 error[E0621]: explicit lifetime required in the type of `v`
   --> $DIR/regions-static-bound.rs:16:5
    |
-LL | fn error(u: &(), v: &()) {
-   |                     --- help: add explicit lifetime `'static` to the type of `v`: `&'static ()`
-...
 LL |     static_id_indirect(&v);
    |     ^^^^^^^^^^^^^^^^^^^^^^ lifetime `'static` required