Skip to content

Commit bf62c6d

Browse files
authored
Rollup merge of rust-lang#89504 - Aaron1011:rpit-nll-static, r=nikomatsakis
Don't suggest replacing region with 'static in NLL Fixes rust-lang#73159 This is similar to rust-lang#69350 - if the user didn't initially write out a 'static lifetime, adding 'static in response to a lifetime error is usually the wrong thing to do.
2 parents 04314a6 + fdd8a0d commit bf62c6d

File tree

62 files changed

+25
-214
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+25
-214
lines changed

compiler/rustc_borrowck/src/diagnostics/outlives_suggestion.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -171,9 +171,7 @@ impl OutlivesSuggestionBuilder {
171171
let outlived_fr_name = self.region_vid_to_name(mbcx, errci.outlived_fr);
172172

173173
if let (Some(fr_name), Some(outlived_fr_name)) = (fr_name, outlived_fr_name) {
174-
if let RegionNameSource::Static = outlived_fr_name.source {
175-
diag.help(&format!("consider replacing `{}` with `'static`", fr_name));
176-
} else {
174+
if !matches!(outlived_fr_name.source, RegionNameSource::Static) {
177175
diag.help(&format!(
178176
"consider adding the following bound: `{}: {}`",
179177
fr_name, outlived_fr_name

src/test/ui/associated-types/cache/project-fn-ret-contravariant.transmute.nll.stderr

-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ LL | fn baz<'a,'b>(x: &'a u32) -> &'static u32 {
55
| -- lifetime `'a` defined here
66
LL | bar(foo, x)
77
| ^^^^^^^^^^^ returning this value requires that `'a` must outlive `'static`
8-
|
9-
= help: consider replacing `'a` with `'static`
108

119
error: aborting due to previous error
1210

src/test/ui/associated-types/cache/project-fn-ret-invariant.transmute.nll.stderr

-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ LL | fn baz<'a, 'b>(x: Type<'a>) -> Type<'static> {
66
...
77
LL | bar(foo, x)
88
| ^^^^^^^^^^^ returning this value requires that `'a` must outlive `'static`
9-
|
10-
= help: consider replacing `'a` with `'static`
119

1210
error: aborting due to previous error
1311

src/test/ui/closure-expected-type/expect-fn-supply-fn.nll.stderr

-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ LL | fn expect_free_supply_free_from_fn<'x>(x: &'x u32) {
1818
...
1919
LL | with_closure_expecting_fn_with_free_region(|x: fn(&'x u32), y| {});
2020
| ^ requires that `'x` must outlive `'static`
21-
|
22-
= help: consider replacing `'x` with `'static`
2321

2422
error[E0308]: mismatched types
2523
--> $DIR/expect-fn-supply-fn.rs:32:49

src/test/ui/closures/closure-expected-type/expect-region-supply-region-2.nll.stderr

-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ LL | fn expect_bound_supply_named<'x>() {
1717
...
1818
LL | closure_expecting_bound(|x: &'x u32| {
1919
| ^ requires that `'x` must outlive `'static`
20-
|
21-
= help: consider replacing `'x` with `'static`
2220

2321
error: aborting due to 2 previous errors
2422

src/test/ui/hrtb/hrtb-just-for-static.nll.stderr

-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ LL | fn give_some<'a>() {
1414
| -- lifetime `'a` defined here
1515
LL | want_hrtb::<&'a u32>()
1616
| ^^^^^^^^^^^^^^^^^^^^ requires that `'a` must outlive `'static`
17-
|
18-
= help: consider replacing `'a` with `'static`
1917

2018
error: implementation of `Foo` is not general enough
2119
--> $DIR/hrtb-just-for-static.rs:30:5

src/test/ui/hrtb/hrtb-perfect-forwarding.nll.stderr

-2
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,6 @@ LL | fn foo_hrtb_bar_not<'b, T>(mut t: T)
5454
...
5555
LL | foo_hrtb_bar_not(&mut t);
5656
| ^^^^^^^^^^^^^^^^^^^^^^^^ requires that `'b` must outlive `'static`
57-
|
58-
= help: consider replacing `'b` with `'static`
5957

6058
error: implementation of `Bar` is not general enough
6159
--> $DIR/hrtb-perfect-forwarding.rs:43:5

src/test/ui/impl-header-lifetime-elision/dyn-trait.nll.stderr

-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ LL | fn with_dyn_debug_static<'a>(x: Box<dyn Debug + 'a>) {
55
| - `x` is a reference that is only valid in the function body
66
LL | static_val(x);
77
| ^^^^^^^^^^^^^ `x` escapes the function body here
8-
|
9-
= help: consider replacing `'a` with `'static`
108

119
error: aborting due to previous error
1210

src/test/ui/impl-trait/must_outlive_least_region_or_bound.nll.stderr

-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ LL | fn explicit<'a>(x: &'a i32) -> impl Copy { x }
1919
| |
2020
| lifetime `'a` defined here
2121
|
22-
= help: consider replacing `'a` with `'static`
2322
help: to allow this `impl Trait` to capture borrowed data with lifetime `'a`, add `'a` as a bound
2423
|
2524
LL | fn explicit<'a>(x: &'a i32) -> impl Copy + 'a { x }
@@ -42,7 +41,6 @@ LL | fn explicit2<'a>(x: &'a i32) -> impl Copy + 'static { x }
4241
| -- lifetime `'a` defined here ^ returning this value requires that `'a` must outlive `'static`
4342
|
4443
= help: consider replacing `'a` with `'static`
45-
= help: consider replacing `'a` with `'static`
4644

4745
error[E0621]: explicit lifetime required in the type of `x`
4846
--> $DIR/must_outlive_least_region_or_bound.rs:11:41
@@ -67,7 +65,6 @@ LL | fn with_bound<'a>(x: &'a i32) -> impl LifetimeTrait<'a> + 'static { x }
6765
| -- lifetime `'a` defined here ^ returning this value requires that `'a` must outlive `'static`
6866
|
6967
= help: consider replacing `'a` with `'static`
70-
= help: consider replacing `'a` with `'static`
7168

7269
error: lifetime may not live long enough
7370
--> $DIR/must_outlive_least_region_or_bound.rs:32:61

src/test/ui/impl-trait/static-return-lifetime-infered.nll.stderr

-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ LL | fn iter_values<'a>(&'a self) -> impl Iterator<Item=u32> {
1919
| |
2020
| lifetime `'a` defined here
2121
|
22-
= help: consider replacing `'a` with `'static`
2322
help: to allow this `impl Trait` to capture borrowed data with lifetime `'a`, add `'a` as a bound
2423
|
2524
LL | fn iter_values<'a>(&'a self) -> impl Iterator<Item=u32> + 'a {

src/test/ui/issues/issue-10291.nll.stderr

-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ LL | fn test<'x>(x: &'x isize) {
66
LL | drop::<Box<dyn for<'z> FnMut(&'z isize) -> &'z isize>>(Box::new(|z| {
77
LL | x
88
| ^ returning this value requires that `'x` must outlive `'static`
9-
|
10-
= help: consider replacing `'x` with `'static`
119

1210
error: aborting due to previous error
1311

src/test/ui/issues/issue-26217.nll.stderr

-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ LL | fn bar<'a>() {
55
| -- lifetime `'a` defined here
66
LL | foo::<&'a i32>();
77
| ^^^^^^^^^^^^^^ requires that `'a` must outlive `'static`
8-
|
9-
= help: consider replacing `'a` with `'static`
108

119
error: aborting due to previous error
1210

src/test/ui/issues/issue-54943.nll.stderr

-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ LL | fn boo<'a>() {
66
...
77
LL | let x = foo::<&'a u32>();
88
| ^^^^^^^^^^^^^^ requires that `'a` must outlive `'static`
9-
|
10-
= help: consider replacing `'a` with `'static`
119

1210
error: aborting due to previous error
1311

src/test/ui/issues/issue-55796.nll.stderr

-4
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ LL | pub trait Graph<'a> {
66
...
77
LL | Box::new(self.out_edges(u).map(|e| e.target()))
88
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ returning this value requires that `'a` must outlive `'static`
9-
|
10-
= help: consider replacing `'a` with `'static`
119

1210
error: lifetime may not live long enough
1311
--> $DIR/issue-55796.rs:23:9
@@ -17,8 +15,6 @@ LL | pub trait Graph<'a> {
1715
...
1816
LL | Box::new(self.in_edges(u).map(|e| e.target()))
1917
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ returning this value requires that `'a` must outlive `'static`
20-
|
21-
= help: consider replacing `'a` with `'static`
2218

2319
error: aborting due to 2 previous errors
2420

src/test/ui/issues/issue-75777.nll.stderr

-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ LL | fn inject<'a, Env: 'a, A: 'a + Send>(v: A) -> Box<dyn FnOnce(&'a Env) -> Bo
66
LL | let fut: BoxFuture<'a, A> = Box::pin(future::ready(v));
77
LL | Box::new(move |_| fut)
88
| ^^^^^^^^^^^^^^^^^^^^^^ returning this value requires that `'a` must outlive `'static`
9-
|
10-
= help: consider replacing `'a` with `'static`
119

1210
error: aborting due to previous error
1311

src/test/ui/lifetimes/lifetime-bound-will-change-warning.nll.stderr

-4
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ LL | fn test2<'a>(x: &'a Box<dyn Fn() + 'a>) {
66
LL | // but ref_obj will not, so warn.
77
LL | ref_obj(x)
88
| ^^^^^^^^^^ `x` escapes the function body here
9-
|
10-
= help: consider replacing `'a` with `'static`
119

1210
error[E0521]: borrowed data escapes outside of function
1311
--> $DIR/lifetime-bound-will-change-warning.rs:39:5
@@ -17,8 +15,6 @@ LL | fn test2cc<'a>(x: &'a Box<dyn Fn() + 'a>) {
1715
LL | // same as test2, but cross crate
1816
LL | lib::ref_obj(x)
1917
| ^^^^^^^^^^^^^^^ `x` escapes the function body here
20-
|
21-
= help: consider replacing `'a` with `'static`
2218

2319
error: aborting due to 2 previous errors
2420

src/test/ui/lub-if.nll.stderr

-4
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ LL | pub fn opt_str2<'a>(maybestr: &'a Option<String>) -> &'static str {
66
...
77
LL | s
88
| ^ returning this value requires that `'a` must outlive `'static`
9-
|
10-
= help: consider replacing `'a` with `'static`
119

1210
error: lifetime may not live long enough
1311
--> $DIR/lub-if.rs:35:9
@@ -17,8 +15,6 @@ LL | pub fn opt_str3<'a>(maybestr: &'a Option<String>) -> &'static str {
1715
...
1816
LL | s
1917
| ^ returning this value requires that `'a` must outlive `'static`
20-
|
21-
= help: consider replacing `'a` with `'static`
2218

2319
error: aborting due to 2 previous errors
2420

src/test/ui/lub-match.nll.stderr

-4
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ LL | pub fn opt_str2<'a>(maybestr: &'a Option<String>) -> &'static str {
66
...
77
LL | s
88
| ^ returning this value requires that `'a` must outlive `'static`
9-
|
10-
= help: consider replacing `'a` with `'static`
119

1210
error: lifetime may not live long enough
1311
--> $DIR/lub-match.rs:39:13
@@ -17,8 +15,6 @@ LL | pub fn opt_str3<'a>(maybestr: &'a Option<String>) -> &'static str {
1715
...
1816
LL | s
1917
| ^ returning this value requires that `'a` must outlive `'static`
20-
|
21-
= help: consider replacing `'a` with `'static`
2218

2319
error: aborting due to 2 previous errors
2420

src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-no-bound.stderr

-2
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,6 @@ LL | | // Only works if 'x: 'y:
4646
LL | | demand_y(x, y, x.get())
4747
LL | | });
4848
| |______^ `cell_a` escapes the function body here
49-
|
50-
= help: consider replacing `'a` with `'static`
5149

5250
error: aborting due to previous error
5351

src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-wrong-bound.stderr

-2
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,6 @@ LL | | // Only works if 'x: 'y:
4646
LL | | demand_y(x, y, x.get())
4747
LL | | });
4848
| |______^ `cell_a` escapes the function body here
49-
|
50-
= help: consider replacing `'a` with `'static`
5149

5250
error: aborting due to previous error
5351

src/test/ui/nll/closure-requirements/region-lbr-named-does-not-outlive-static.stderr

-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ LL | fn foo<'a>(x: &'a u32) -> &'static u32 {
55
| -- lifetime `'a` defined here
66
LL | &*x
77
| ^^^ returning this value requires that `'a` must outlive `'static`
8-
|
9-
= help: consider replacing `'a` with `'static`
108

119
error: aborting due to previous error
1210

src/test/ui/nll/issue-50716.nll.stderr

-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ LL | fn foo<'a, T: 'static>(s: Box<<&'a T as A>::X>)
66
...
77
LL | let _x = *s;
88
| ^^ proving this value is `Sized` requires that `'a` must outlive `'static`
9-
|
10-
= help: consider replacing `'a` with `'static`
119

1210
error: aborting due to previous error
1311

src/test/ui/nll/issue-55401.nll.stderr

-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ LL | fn static_to_a_to_static_through_ref_in_tuple<'a>(x: &'a u32) -> &'static u
66
LL | let (ref y, _z): (&'a u32, u32) = (&22, 44);
77
LL | *y
88
| ^^ returning this value requires that `'a` must outlive `'static`
9-
|
10-
= help: consider replacing `'a` with `'static`
119

1210
error: aborting due to previous error
1311

src/test/ui/nll/issue-58299.stderr

-4
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ LL | fn foo<'a>(x: i32) {
66
...
77
LL | A::<'a>::X..=A::<'static>::X => (),
88
| ^^^^^^^^^^ requires that `'a` must outlive `'static`
9-
|
10-
= help: consider replacing `'a` with `'static`
119

1210
error: lifetime may not live long enough
1311
--> $DIR/issue-58299.rs:24:27
@@ -17,8 +15,6 @@ LL | fn bar<'a>(x: i32) {
1715
...
1816
LL | A::<'static>::X..=A::<'a>::X => (),
1917
| ^^^^^^^^^^ requires that `'a` must outlive `'static`
20-
|
21-
= help: consider replacing `'a` with `'static`
2218

2319
error: aborting due to 2 previous errors
2420

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Regression test for issue #73159
2+
// Tests thar we don't suggest replacing 'a with 'static'
3+
4+
#![feature(nll)]
5+
6+
struct Foo<'a>(&'a [u8]);
7+
8+
impl<'a> Foo<'a> {
9+
fn make_it(&self) -> impl Iterator<Item = u8> { //~ ERROR lifetime may not live
10+
self.0.iter().copied()
11+
}
12+
}
13+
14+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
error: lifetime may not live long enough
2+
--> $DIR/issue-73159-rpit-static.rs:9:26
3+
|
4+
LL | impl<'a> Foo<'a> {
5+
| -- lifetime `'a` defined here
6+
LL | fn make_it(&self) -> impl Iterator<Item = u8> {
7+
| ^^^^^^^^^^^^^^^^^^^^^^^^ opaque type requires that `'a` must outlive `'static`
8+
9+
error: aborting due to previous error
10+

src/test/ui/nll/mir_check_cast_reify.stderr

-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ LL | fn bar<'a>(x: &'a u32) -> &'static u32 {
66
...
77
LL | f(x)
88
| ^^^^ returning this value requires that `'a` must outlive `'static`
9-
|
10-
= help: consider replacing `'a` with `'static`
119

1210
error: aborting due to previous error
1311

src/test/ui/nll/mir_check_cast_unsafe_fn.stderr

-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ LL | fn bar<'a>(input: &'a u32, f: fn(&'a u32) -> &'a u32) -> &'static u32 {
66
...
77
LL | unsafe { g(input) }
88
| ^^^^^^^^ returning this value requires that `'a` must outlive `'static`
9-
|
10-
= help: consider replacing `'a` with `'static`
119

1210
error: aborting due to previous error
1311

src/test/ui/nll/mir_check_cast_unsize.stderr

-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ LL | fn bar<'a>(x: &'a u32) -> &'static dyn Debug {
55
| -- lifetime `'a` defined here
66
LL | x
77
| ^ returning this value requires that `'a` must outlive `'static`
8-
|
9-
= help: consider replacing `'a` with `'static`
108

119
error: aborting due to previous error
1210

src/test/ui/nll/outlives-suggestion-more.stderr

-4
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,6 @@ LL | fn foo2<'a, 'b, 'c>(x: &'a usize, y: &'b usize) -> (&'c usize, &'static usi
4646
| -- lifetime `'b` defined here
4747
LL | (x, y)
4848
| ^^^^^^ returning this value requires that `'b` must outlive `'static`
49-
|
50-
= help: consider replacing `'b` with `'static`
5149

5250
help: the following changes may resolve your lifetime errors
5351
|
@@ -88,8 +86,6 @@ LL | fn foo3<'a, 'b, 'c, 'd, 'e>(
8886
...
8987
LL | (x, y, z)
9088
| ^^^^^^^^^ returning this value requires that `'c` must outlive `'static`
91-
|
92-
= help: consider replacing `'c` with `'static`
9389

9490
help: the following changes may resolve your lifetime errors
9591
|

src/test/ui/nll/outlives-suggestion-simple.stderr

-4
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ LL | fn foo2<'a>(x: &'a usize) -> &'static usize {
1717
| -- lifetime `'a` defined here
1818
LL | x
1919
| ^ returning this value requires that `'a` must outlive `'static`
20-
|
21-
= help: consider replacing `'a` with `'static`
2220

2321
error: lifetime may not live long enough
2422
--> $DIR/outlives-suggestion-simple.rs:14:5
@@ -66,8 +64,6 @@ LL | pub fn foo<'a>(x: &'a usize) -> Self {
6664
| -- lifetime `'a` defined here
6765
LL | Foo { x }
6866
| ^^^^^^^^^ returning this value requires that `'a` must outlive `'static`
69-
|
70-
= help: consider replacing `'a` with `'static`
7167

7268
error: lifetime may not live long enough
7369
--> $DIR/outlives-suggestion-simple.rs:41:9

0 commit comments

Comments
 (0)