Skip to content

Commit 31ea589

Browse files
committed
review comments: wording
1 parent 539e978 commit 31ea589

14 files changed

+85
-81
lines changed

src/librustc_infer/infer/error_reporting/nice_region_error/static_impl_trait.rs

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -75,18 +75,18 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
7575
// | ---- ^
7676
err.span_label(
7777
sup_origin.span(),
78-
"...is captured here requiring it to live as long as `'static`",
78+
"...is captured here, requiring it to live as long as `'static`",
7979
);
8080
} else if sup_origin.span() <= return_sp {
8181
err.span_label(sup_origin.span(), "...is captured here...");
8282
err.span_label(
8383
return_sp,
84-
"...and required to live as long as `'static` by this",
84+
"...and is required to live as long as `'static` here",
8585
);
8686
} else {
8787
err.span_label(
8888
return_sp,
89-
"...is required to live as long as `'static` by this...",
89+
"...is required to live as long as `'static` here...",
9090
);
9191
err.span_label(sup_origin.span(), "...and is captured here");
9292
}
@@ -101,6 +101,20 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
101101
// explicit non-desugar'able return.
102102
if fn_return.span.desugaring_kind().is_none() {
103103
// FIXME: account for the need of parens in `&(dyn Trait + '_)`
104+
105+
let consider = "consider changing the";
106+
let declare = "to declare that the";
107+
let arg = match param_info.param.pat.simple_ident() {
108+
Some(simple_ident) => format!("argument `{}`", simple_ident),
109+
None => "the argument".to_string(),
110+
};
111+
let explicit =
112+
format!("you can add an explicit `{}` lifetime bound", lifetime_name);
113+
let explicit_static = format!("explicit `'static` bound to {}", arg);
114+
let captures = format!("captures data from {}", arg);
115+
let add_static_bound =
116+
"alternatively, add an explicit `'static` bound to this reference";
117+
let plus_lt = format!(" + {}", lifetime_name);
104118
match fn_return.kind {
105119
TyKind::Def(item_id, _) => {
106120
let item = self.tcx().hir().item(item_id.id);
@@ -126,30 +140,26 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
126140
{
127141
err.span_suggestion_verbose(
128142
span,
129-
&format!(
130-
"consider changing the `impl Trait`'s explicit \
131-
`'static` bound to {}",
132-
lifetime,
133-
),
143+
&format!("{} `impl Trait`'s {}", consider, explicit_static),
134144
lifetime_name,
135145
Applicability::MaybeIncorrect,
136146
);
137147
err.span_suggestion_verbose(
138148
param_info.param_ty_span,
139-
"alternatively, set an explicit `'static` lifetime to \
140-
this parameter",
149+
add_static_bound,
141150
param_info.param_ty.to_string(),
142151
Applicability::MaybeIncorrect,
143152
);
144153
} else {
145154
err.span_suggestion_verbose(
146155
fn_return.span.shrink_to_hi(),
147156
&format!(
148-
"to permit non-static references in an `impl Trait` \
149-
value, you can add an explicit bound for {}",
150-
lifetime,
157+
"{declare} `impl Trait` {captures}, {explicit}",
158+
declare = declare,
159+
captures = captures,
160+
explicit = explicit,
151161
),
152-
format!(" + {}", lifetime_name),
162+
plus_lt,
153163
Applicability::MaybeIncorrect,
154164
);
155165
};
@@ -159,31 +169,25 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
159169
err.span_suggestion_verbose(
160170
fn_return.span.shrink_to_hi(),
161171
&format!(
162-
"to permit non-static references in a trait object \
163-
value, you can add an explicit bound for {}",
164-
lifetime,
172+
"{declare} trait object {captures}, {explicit}",
173+
declare = declare,
174+
captures = captures,
175+
explicit = explicit,
165176
),
166-
format!(" + {}", lifetime_name),
177+
plus_lt,
167178
Applicability::MaybeIncorrect,
168179
);
169180
}
170181
_ => {
171182
err.span_suggestion_verbose(
172183
lt.span,
173-
&format!(
174-
"consider changing the trait object's explicit \
175-
`'static` bound to {}",
176-
lifetime,
177-
),
184+
&format!("{} trait object's {}", consider, explicit_static),
178185
lifetime_name,
179186
Applicability::MaybeIncorrect,
180187
);
181188
err.span_suggestion_verbose(
182189
param_info.param_ty_span,
183-
&format!(
184-
"alternatively, set an explicit `'static` lifetime \
185-
in this parameter",
186-
),
190+
add_static_bound,
187191
param_info.param_ty.to_string(),
188192
Applicability::MaybeIncorrect,
189193
);

src/test/ui/async-await/issues/issue-62097.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ LL | pub async fn run_dummy_fn(&self) {
77
| this data with an anonymous lifetime `'_`...
88
| ...is captured here...
99
LL | foo(|| self.bar()).await;
10-
| --- ...and required to live as long as `'static` by this
10+
| --- ...and is required to live as long as `'static` here
1111

1212
error: aborting due to previous error
1313

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

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ error[E0758]: cannot infer an appropriate lifetime
44
LL | fn elided(x: &i32) -> impl Copy { x }
55
| ---- --------- ^ ...and is captured here
66
| | |
7-
| | ...is required to live as long as `'static` by this...
7+
| | ...is required to live as long as `'static` here...
88
| this data with an anonymous lifetime `'_`...
99
|
10-
help: to permit non-static references in an `impl Trait` value, you can add an explicit bound for an anonymous lifetime `'_`
10+
help: to declare that the `impl Trait` captures data from argument `x`, you can add an explicit `'_` lifetime bound
1111
|
1212
LL | fn elided(x: &i32) -> impl Copy + '_ { x }
1313
| ^^^^
@@ -18,10 +18,10 @@ error[E0758]: cannot infer an appropriate lifetime
1818
LL | fn explicit<'a>(x: &'a i32) -> impl Copy { x }
1919
| ------- --------- ^ ...and is captured here
2020
| | |
21-
| | ...is required to live as long as `'static` by this...
21+
| | ...is required to live as long as `'static` here...
2222
| this data with lifetime `'a`...
2323
|
24-
help: to permit non-static references in an `impl Trait` value, you can add an explicit bound for lifetime `'a`
24+
help: to declare that the `impl Trait` captures data from argument `x`, you can add an explicit `'a` lifetime bound
2525
|
2626
LL | fn explicit<'a>(x: &'a i32) -> impl Copy + 'a { x }
2727
| ^^^^
@@ -32,14 +32,14 @@ error[E0758]: cannot infer an appropriate lifetime
3232
LL | fn elided2(x: &i32) -> impl Copy + 'static { x }
3333
| ---- ------------------- ^ ...and is captured here
3434
| | |
35-
| | ...is required to live as long as `'static` by this...
35+
| | ...is required to live as long as `'static` here...
3636
| this data with an anonymous lifetime `'_`...
3737
|
38-
help: consider changing the `impl Trait`'s explicit `'static` bound to an anonymous lifetime `'_`
38+
help: consider changing the `impl Trait`'s explicit `'static` bound to argument `x`
3939
|
4040
LL | fn elided2(x: &i32) -> impl Copy + '_ { x }
4141
| ^^
42-
help: alternatively, set an explicit `'static` lifetime to this parameter
42+
help: alternatively, add an explicit `'static` bound to this reference
4343
|
4444
LL | fn elided2(x: &'static i32) -> impl Copy + 'static { x }
4545
| ^^^^^^^^^^^^
@@ -50,14 +50,14 @@ error[E0758]: cannot infer an appropriate lifetime
5050
LL | fn explicit2<'a>(x: &'a i32) -> impl Copy + 'static { x }
5151
| ------- ------------------- ^ ...and is captured here
5252
| | |
53-
| | ...is required to live as long as `'static` by this...
53+
| | ...is required to live as long as `'static` here...
5454
| this data with lifetime `'a`...
5555
|
56-
help: consider changing the `impl Trait`'s explicit `'static` bound to lifetime `'a`
56+
help: consider changing the `impl Trait`'s explicit `'static` bound to argument `x`
5757
|
5858
LL | fn explicit2<'a>(x: &'a i32) -> impl Copy + 'a { x }
5959
| ^^
60-
help: alternatively, set an explicit `'static` lifetime to this parameter
60+
help: alternatively, add an explicit `'static` bound to this reference
6161
|
6262
LL | fn explicit2<'a>(x: &'static i32) -> impl Copy + 'static { x }
6363
| ^^^^^^^^^^^^
@@ -76,14 +76,14 @@ error[E0758]: cannot infer an appropriate lifetime
7676
LL | fn with_bound<'a>(x: &'a i32) -> impl LifetimeTrait<'a> + 'static { x }
7777
| ------- -------------------------------- ^ ...and is captured here
7878
| | |
79-
| | ...is required to live as long as `'static` by this...
79+
| | ...is required to live as long as `'static` here...
8080
| this data with lifetime `'a`...
8181
|
82-
help: consider changing the `impl Trait`'s explicit `'static` bound to lifetime `'a`
82+
help: consider changing the `impl Trait`'s explicit `'static` bound to argument `x`
8383
|
8484
LL | fn with_bound<'a>(x: &'a i32) -> impl LifetimeTrait<'a> + 'a { x }
8585
| ^^
86-
help: alternatively, set an explicit `'static` lifetime to this parameter
86+
help: alternatively, add an explicit `'static` bound to this reference
8787
|
8888
LL | fn with_bound<'a>(x: &'static i32) -> impl LifetimeTrait<'a> + 'static { x }
8989
| ^^^^^^^^^^^^
@@ -109,11 +109,11 @@ error[E0758]: cannot infer an appropriate lifetime
109109
--> $DIR/must_outlive_least_region_or_bound.rs:18:50
110110
|
111111
LL | fn elided3(x: &i32) -> Box<dyn Debug> { Box::new(x) }
112-
| ---- ^ ...is captured here requiring it to live as long as `'static`
112+
| ---- ^ ...is captured here, requiring it to live as long as `'static`
113113
| |
114114
| this data with an anonymous lifetime `'_`...
115115
|
116-
help: to permit non-static references in a trait object value, you can add an explicit bound for an anonymous lifetime `'_`
116+
help: to declare that the trait object captures data from argument `x`, you can add an explicit `'_` lifetime bound
117117
|
118118
LL | fn elided3(x: &i32) -> Box<dyn Debug + '_> { Box::new(x) }
119119
| ^^^^
@@ -122,11 +122,11 @@ error[E0758]: cannot infer an appropriate lifetime
122122
--> $DIR/must_outlive_least_region_or_bound.rs:21:59
123123
|
124124
LL | fn explicit3<'a>(x: &'a i32) -> Box<dyn Debug> { Box::new(x) }
125-
| ------- ^ ...is captured here requiring it to live as long as `'static`
125+
| ------- ^ ...is captured here, requiring it to live as long as `'static`
126126
| |
127127
| this data with lifetime `'a`...
128128
|
129-
help: to permit non-static references in a trait object value, you can add an explicit bound for lifetime `'a`
129+
help: to declare that the trait object captures data from argument `x`, you can add an explicit `'a` lifetime bound
130130
|
131131
LL | fn explicit3<'a>(x: &'a i32) -> Box<dyn Debug + 'a> { Box::new(x) }
132132
| ^^^^
@@ -135,15 +135,15 @@ error[E0758]: cannot infer an appropriate lifetime
135135
--> $DIR/must_outlive_least_region_or_bound.rs:24:60
136136
|
137137
LL | fn elided4(x: &i32) -> Box<dyn Debug + 'static> { Box::new(x) }
138-
| ---- ^ ...is captured here requiring it to live as long as `'static`
138+
| ---- ^ ...is captured here, requiring it to live as long as `'static`
139139
| |
140140
| this data with an anonymous lifetime `'_`...
141141
|
142-
help: consider changing the trait object's explicit `'static` bound to an anonymous lifetime `'_`
142+
help: consider changing the trait object's explicit `'static` bound to argument `x`
143143
|
144144
LL | fn elided4(x: &i32) -> Box<dyn Debug + '_> { Box::new(x) }
145145
| ^^
146-
help: alternatively, set an explicit `'static` lifetime in this parameter
146+
help: alternatively, add an explicit `'static` bound to this reference
147147
|
148148
LL | fn elided4(x: &'static i32) -> Box<dyn Debug + 'static> { Box::new(x) }
149149
| ^^^^^^^^^^^^
@@ -152,13 +152,13 @@ error[E0758]: cannot infer an appropriate lifetime
152152
--> $DIR/must_outlive_least_region_or_bound.rs:27:69
153153
|
154154
LL | fn explicit4<'a>(x: &'a i32) -> Box<dyn Debug + 'static> { Box::new(x) }
155-
| ------- this data with lifetime `'a`... ^ ...is captured here requiring it to live as long as `'static`
155+
| ------- this data with lifetime `'a`... ^ ...is captured here, requiring it to live as long as `'static`
156156
|
157-
help: consider changing the trait object's explicit `'static` bound to lifetime `'a`
157+
help: consider changing the trait object's explicit `'static` bound to argument `x`
158158
|
159159
LL | fn explicit4<'a>(x: &'a i32) -> Box<dyn Debug + 'a> { Box::new(x) }
160160
| ^^
161-
help: alternatively, set an explicit `'static` lifetime in this parameter
161+
help: alternatively, add an explicit `'static` bound to this reference
162162
|
163163
LL | fn explicit4<'a>(x: &'static i32) -> Box<dyn Debug + 'static> { Box::new(x) }
164164
| ^^^^^^^^^^^^

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ error[E0758]: cannot infer an appropriate lifetime
22
--> $DIR/static-return-lifetime-infered.rs:7:16
33
|
44
LL | fn iter_values_anon(&self) -> impl Iterator<Item=u32> {
5-
| ----- ----------------------- ...is required to live as long as `'static` by this...
5+
| ----- ----------------------- ...is required to live as long as `'static` here...
66
| |
77
| this data with an anonymous lifetime `'_`...
88
LL | self.x.iter().map(|a| a.0)
99
| ------ ^^^^
1010
| |
1111
| ...and is captured here
1212
|
13-
help: to permit non-static references in an `impl Trait` value, you can add an explicit bound for an anonymous lifetime `'_`
13+
help: to declare that the `impl Trait` captures data from argument `self`, you can add an explicit `'_` lifetime bound
1414
|
1515
LL | fn iter_values_anon(&self) -> impl Iterator<Item=u32> + '_ {
1616
| ^^^^
@@ -19,15 +19,15 @@ error[E0758]: cannot infer an appropriate lifetime
1919
--> $DIR/static-return-lifetime-infered.rs:11:16
2020
|
2121
LL | fn iter_values<'a>(&'a self) -> impl Iterator<Item=u32> {
22-
| -------- ----------------------- ...is required to live as long as `'static` by this...
22+
| -------- ----------------------- ...is required to live as long as `'static` here...
2323
| |
2424
| this data with lifetime `'a`...
2525
LL | self.x.iter().map(|a| a.0)
2626
| ------ ^^^^
2727
| |
2828
| ...and is captured here
2929
|
30-
help: to permit non-static references in an `impl Trait` value, you can add an explicit bound for lifetime `'a`
30+
help: to declare that the `impl Trait` captures data from argument `self`, you can add an explicit `'a` lifetime bound
3131
|
3232
LL | fn iter_values<'a>(&'a self) -> impl Iterator<Item=u32> + 'a {
3333
| ^^^^

src/test/ui/issues/issue-16922.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ error[E0758]: cannot infer an appropriate lifetime
44
LL | fn foo<T: Any>(value: &T) -> Box<dyn Any> {
55
| -- this data with an anonymous lifetime `'_`...
66
LL | Box::new(value) as Box<dyn Any>
7-
| ^^^^^ ...is captured here requiring it to live as long as `'static`
7+
| ^^^^^ ...is captured here, requiring it to live as long as `'static`
88
|
9-
help: to permit non-static references in a trait object value, you can add an explicit bound for an anonymous lifetime `'_`
9+
help: to declare that the trait object captures data from argument `value`, you can add an explicit `'_` lifetime bound
1010
|
1111
LL | fn foo<T: Any>(value: &T) -> Box<dyn Any + '_> {
1212
| ^^^^

src/test/ui/object-lifetime/object-lifetime-default-from-box-error.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ LL | fn load(ss: &mut SomeStruct) -> Box<dyn SomeTrait> {
77
LL | ss.r
88
| ^^^^ ...is captured and required live as long as `'static` here
99
|
10-
help: to permit non-static references in a trait object value, you can add an explicit bound for an anonymous lifetime `'_`
10+
help: to declare that the trait object captures data from argument `ss`, you can add an explicit `'_` lifetime bound
1111
|
1212
LL | fn load(ss: &mut SomeStruct) -> Box<dyn SomeTrait + '_> {
1313
| ^^^^

0 commit comments

Comments
 (0)