Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't suggest adding 'static lifetime to arguments #85240

Merged
merged 1 commit into from
May 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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

Expand Down
3 changes: 0 additions & 3 deletions src/test/ui/generator/generator-region-requirements.stderr
Original file line number Diff line number Diff line change
@@ -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

Expand Down
Original file line number Diff line number Diff line change
@@ -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

Expand Down
2 changes: 0 additions & 2 deletions src/test/ui/issues/issue-46983.stderr
Original file line number Diff line number Diff line change
@@ -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

Expand Down
Original file line number Diff line number Diff line change
@@ -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

Expand Down
3 changes: 0 additions & 3 deletions src/test/ui/nll/guarantor-issue-46974.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 0 additions & 5 deletions src/test/ui/regions/regions-static-bound.migrate.nll.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 0 additions & 5 deletions src/test/ui/regions/regions-static-bound.migrate.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 0 additions & 5 deletions src/test/ui/regions/regions-static-bound.nll.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down