Skip to content

Commit bf62c6d

Browse files
authored
Rollup merge of #89504 - Aaron1011:rpit-nll-static, r=nikomatsakis
Don't suggest replacing region with 'static in NLL Fixes #73159 This is similar to #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

Lines changed: 1 addition & 3 deletions
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

Lines changed: 0 additions & 2 deletions
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

Lines changed: 0 additions & 2 deletions
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

Lines changed: 0 additions & 2 deletions
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

Lines changed: 0 additions & 2 deletions
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

Lines changed: 0 additions & 2 deletions
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

Lines changed: 0 additions & 2 deletions
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

Lines changed: 0 additions & 2 deletions
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

Lines changed: 0 additions & 3 deletions
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

Lines changed: 0 additions & 1 deletion
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 {

0 commit comments

Comments
 (0)