Closes #52413: Provide structured suggestion instead of label

This commit is contained in:
Pramod Bisht 2018-08-05 18:44:03 +00:00
parent 9f9ac89d11
commit 19401086df
40 changed files with 59 additions and 51 deletions

View File

@ -65,9 +65,10 @@ impl<'a, 'gcx, 'tcx> NiceRegionError<'a, 'gcx, 'tcx> {
region_info region_info
); );
let (arg, new_ty, br, is_first, scope_def_id, is_impl_item) = ( let (arg, new_ty, new_ty_span, br, is_first, scope_def_id, is_impl_item) = (
anon_arg_info.arg, anon_arg_info.arg,
anon_arg_info.arg_ty, anon_arg_info.arg_ty,
anon_arg_info.arg_ty_span,
anon_arg_info.bound_region, anon_arg_info.bound_region,
anon_arg_info.is_first, anon_arg_info.is_first,
region_info.def_id, region_info.def_id,
@ -110,9 +111,10 @@ impl<'a, 'gcx, 'tcx> NiceRegionError<'a, 'gcx, 'tcx> {
E0621, E0621,
"explicit lifetime required in {}", "explicit lifetime required in {}",
error_var error_var
).span_label( ).span_suggestion(
arg.pat.span, new_ty_span,
format!("consider changing {} to `{}`", span_label_var, new_ty), &format!("consider changing {} to ", span_label_var),
new_ty.to_string()
) )
.span_label(span, format!("lifetime `{}` required", named)) .span_label(span, format!("lifetime `{}` required", named))
.emit(); .emit();

View File

@ -27,6 +27,8 @@ pub(super) struct AnonymousArgInfo<'tcx> {
pub arg_ty: Ty<'tcx>, pub arg_ty: Ty<'tcx>,
// the ty::BoundRegion corresponding to the anonymous region // the ty::BoundRegion corresponding to the anonymous region
pub bound_region: ty::BoundRegion, pub bound_region: ty::BoundRegion,
// arg_ty_span contains span of argument type
pub arg_ty_span : Span,
// corresponds to id the argument is the first parameter // corresponds to id the argument is the first parameter
// in the declaration // in the declaration
pub is_first: bool, pub is_first: bool,
@ -74,12 +76,16 @@ impl<'a, 'gcx, 'tcx> NiceRegionError<'a, 'gcx, 'tcx> {
if let Some(node_id) = hir.as_local_node_id(id) { if let Some(node_id) = hir.as_local_node_id(id) {
if let Some(body_id) = hir.maybe_body_owned_by(node_id) { if let Some(body_id) = hir.maybe_body_owned_by(node_id) {
let body = hir.body(body_id); let body = hir.body(body_id);
let owner_id = hir.body_owner(body_id);
let fn_decl = hir.fn_decl(owner_id).unwrap();
if let Some(tables) = self.tables { if let Some(tables) = self.tables {
body.arguments body.arguments
.iter() .iter()
.enumerate() .enumerate()
.filter_map(|(index, arg)| { .filter_map(|(index, arg)| {
// May return None; sometimes the tables are not yet populated. // May return None; sometimes the tables are not yet populated.
let ty_hir_id = fn_decl.inputs[index].hir_id;
let arg_ty_span = hir.span(hir.hir_to_node_id(ty_hir_id));
let ty = tables.node_id_to_type_opt(arg.hir_id)?; let ty = tables.node_id_to_type_opt(arg.hir_id)?;
let mut found_anon_region = false; let mut found_anon_region = false;
let new_arg_ty = self.tcx.fold_regions(&ty, &mut false, |r, _| { let new_arg_ty = self.tcx.fold_regions(&ty, &mut false, |r, _| {
@ -95,6 +101,7 @@ impl<'a, 'gcx, 'tcx> NiceRegionError<'a, 'gcx, 'tcx> {
Some(AnonymousArgInfo { Some(AnonymousArgInfo {
arg: arg, arg: arg,
arg_ty: new_arg_ty, arg_ty: new_arg_ty,
arg_ty_span : arg_ty_span,
bound_region: bound_region, bound_region: bound_region,
is_first: is_first, is_first: is_first,
}) })

View File

@ -14,9 +14,9 @@ error[E0621]: explicit lifetime required in the type of `y`
--> $DIR/mismatched.rs:14:42 --> $DIR/mismatched.rs:14:42
| |
LL | fn foo(x: &'a u32, y: &u32) -> &'a u32 { y } //~ ERROR explicit lifetime required LL | fn foo(x: &'a u32, y: &u32) -> &'a u32 { y } //~ ERROR explicit lifetime required
| - ^ lifetime `'a` required | ---- ^ lifetime `'a` required
| | | |
| consider changing the type of `y` to `&'a u32` | help: consider changing the type of `y` to : `&'a u32`
error[E0623]: lifetime mismatch error[E0623]: lifetime mismatch
--> $DIR/mismatched.rs:16:46 --> $DIR/mismatched.rs:16:46

View File

@ -2,9 +2,9 @@ error[E0621]: explicit lifetime required in the type of `y`
--> $DIR/mismatched.rs:14:42 --> $DIR/mismatched.rs:14:42
| |
LL | fn foo(x: &'a u32, y: &u32) -> &'a u32 { y } //~ ERROR explicit lifetime required LL | fn foo(x: &'a u32, y: &u32) -> &'a u32 { y } //~ ERROR explicit lifetime required
| - ^ lifetime `'a` required | ---- ^ lifetime `'a` required
| | | |
| consider changing the type of `y` to `&'a u32` | help: consider changing the type of `y` to : `&'a u32`
error[E0623]: lifetime mismatch error[E0623]: lifetime mismatch
--> $DIR/mismatched.rs:16:46 --> $DIR/mismatched.rs:16:46

View File

@ -8,7 +8,7 @@ error[E0621]: explicit lifetime required in the type of `y`
--> $DIR/mismatched_trait.rs:16:9 --> $DIR/mismatched_trait.rs:16:9
| |
LL | fn baz(&self, x: &'a u32, y: &u32) -> &'a u32 { LL | fn baz(&self, x: &'a u32, y: &u32) -> &'a u32 {
| - consider changing the type of `y` to `&'a u32` | ---- help: consider changing the type of `y` to : `&'a u32`
LL | y //~ ERROR explicit lifetime required LL | y //~ ERROR explicit lifetime required
| ^ lifetime `'a` required | ^ lifetime `'a` required

View File

@ -2,7 +2,7 @@ error[E0621]: explicit lifetime required in the type of `y`
--> $DIR/mismatched_trait.rs:16:9 --> $DIR/mismatched_trait.rs:16:9
| |
LL | fn baz(&self, x: &'a u32, y: &u32) -> &'a u32 { LL | fn baz(&self, x: &'a u32, y: &u32) -> &'a u32 {
| - consider changing the type of `y` to `&'a u32` | ---- help: consider changing the type of `y` to : `&'a u32`
LL | y //~ ERROR explicit lifetime required LL | y //~ ERROR explicit lifetime required
| ^ lifetime `'a` required | ^ lifetime `'a` required

View File

@ -2,7 +2,7 @@ error[E0621]: explicit lifetime required in the type of `cont`
--> $DIR/issue-13058.rs:24:26 --> $DIR/issue-13058.rs:24:26
| |
LL | fn check<'r, I: Iterator<Item=usize>, T: Itble<'r, usize, I>>(cont: &T) -> bool LL | fn check<'r, I: Iterator<Item=usize>, T: Itble<'r, usize, I>>(cont: &T) -> bool
| ---- consider changing the type of `cont` to `&'r T` | -- help: consider changing the type of `cont` to : `&'r T`
LL | { LL | {
LL | let cont_iter = cont.iter(); LL | let cont_iter = cont.iter();
| ^^^^ lifetime `'r` required | ^^^^ lifetime `'r` required

View File

@ -8,7 +8,7 @@ error[E0621]: explicit lifetime required in the type of `a`
--> $DIR/issue-14285.rs:22:7 --> $DIR/issue-14285.rs:22:7
| |
LL | fn foo<'a>(a: &Foo) -> B<'a> { LL | fn foo<'a>(a: &Foo) -> B<'a> {
| - consider changing the type of `a` to `&'a (dyn Foo + 'a)` | ---- help: consider changing the type of `a` to : `&'a (dyn Foo + 'a)`
LL | B(a) //~ ERROR 22:5: 22:9: explicit lifetime required in the type of `a` [E0621] LL | B(a) //~ ERROR 22:5: 22:9: explicit lifetime required in the type of `a` [E0621]
| ^ lifetime `'a` required | ^ lifetime `'a` required

View File

@ -2,7 +2,7 @@ error[E0621]: explicit lifetime required in the type of `a`
--> $DIR/issue-14285.rs:22:5 --> $DIR/issue-14285.rs:22:5
| |
LL | fn foo<'a>(a: &Foo) -> B<'a> { LL | fn foo<'a>(a: &Foo) -> B<'a> {
| - consider changing the type of `a` to `&'a (dyn Foo + 'a)` | ---- help: consider changing the type of `a` to : `&'a (dyn Foo + 'a)`
LL | B(a) //~ ERROR 22:5: 22:9: explicit lifetime required in the type of `a` [E0621] LL | B(a) //~ ERROR 22:5: 22:9: explicit lifetime required in the type of `a` [E0621]
| ^^^^ lifetime `'a` required | ^^^^ lifetime `'a` required

View File

@ -8,7 +8,7 @@ error[E0621]: explicit lifetime required in the type of `lexer`
--> $DIR/issue-15034.rs:27:25 --> $DIR/issue-15034.rs:27:25
| |
LL | pub fn new(lexer: &'a mut Lexer) -> Parser<'a> { LL | pub fn new(lexer: &'a mut Lexer) -> Parser<'a> {
| ----- consider changing the type of `lexer` to `&'a mut Lexer<'a>` | ------------- help: consider changing the type of `lexer` to : `&'a mut Lexer<'a>`
LL | Parser { lexer: lexer } LL | Parser { lexer: lexer }
| ^^^^^ lifetime `'a` required | ^^^^^ lifetime `'a` required

View File

@ -2,7 +2,7 @@ error[E0621]: explicit lifetime required in the type of `lexer`
--> $DIR/issue-15034.rs:27:25 --> $DIR/issue-15034.rs:27:25
| |
LL | pub fn new(lexer: &'a mut Lexer) -> Parser<'a> { LL | pub fn new(lexer: &'a mut Lexer) -> Parser<'a> {
| ----- consider changing the type of `lexer` to `&'a mut Lexer<'a>` | ------------- help: consider changing the type of `lexer` to : `&'a mut Lexer<'a>`
LL | Parser { lexer: lexer } LL | Parser { lexer: lexer }
| ^^^^^ lifetime `'a` required | ^^^^^ lifetime `'a` required

View File

@ -8,7 +8,7 @@ error[E0621]: explicit lifetime required in the type of `value`
--> $DIR/issue-16922.rs:14:5 --> $DIR/issue-16922.rs:14:5
| |
LL | fn foo<T: Any>(value: &T) -> Box<Any> { LL | fn foo<T: Any>(value: &T) -> Box<Any> {
| ----- consider changing the type of `value` to `&'static T` | -- help: consider changing the type of `value` to : `&'static T`
LL | Box::new(value) as Box<Any> LL | Box::new(value) as Box<Any>
| ^^^^^^^^^^^^^^^ lifetime `'static` required | ^^^^^^^^^^^^^^^ lifetime `'static` required

View File

@ -2,7 +2,7 @@ error[E0621]: explicit lifetime required in the type of `value`
--> $DIR/issue-16922.rs:14:5 --> $DIR/issue-16922.rs:14:5
| |
LL | fn foo<T: Any>(value: &T) -> Box<Any> { LL | fn foo<T: Any>(value: &T) -> Box<Any> {
| ----- consider changing the type of `value` to `&'static T` | -- help: consider changing the type of `value` to : `&'static T`
LL | Box::new(value) as Box<Any> LL | Box::new(value) as Box<Any>
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ lifetime `'static` required | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ lifetime `'static` required

View File

@ -14,7 +14,7 @@ error[E0621]: explicit lifetime required in the type of `x`
--> $DIR/issue-3154.rs:16:15 --> $DIR/issue-3154.rs:16:15
| |
LL | fn thing<'a,Q>(x: &Q) -> thing<'a,Q> { LL | fn thing<'a,Q>(x: &Q) -> thing<'a,Q> {
| - consider changing the type of `x` to `&'a Q` | -- help: consider changing the type of `x` to : `&'a Q`
LL | thing{ x: x } //~ ERROR 16:5: 16:18: explicit lifetime required in the type of `x` [E0621] LL | thing{ x: x } //~ ERROR 16:5: 16:18: explicit lifetime required in the type of `x` [E0621]
| ^ lifetime `'a` required | ^ lifetime `'a` required

View File

@ -2,7 +2,7 @@ error[E0621]: explicit lifetime required in the type of `x`
--> $DIR/issue-3154.rs:16:5 --> $DIR/issue-3154.rs:16:5
| |
LL | fn thing<'a,Q>(x: &Q) -> thing<'a,Q> { LL | fn thing<'a,Q>(x: &Q) -> thing<'a,Q> {
| - consider changing the type of `x` to `&'a Q` | -- help: consider changing the type of `x` to : `&'a Q`
LL | thing{ x: x } //~ ERROR 16:5: 16:18: explicit lifetime required in the type of `x` [E0621] LL | thing{ x: x } //~ ERROR 16:5: 16:18: explicit lifetime required in the type of `x` [E0621]
| ^^^^^^^^^^^^^ lifetime `'a` required | ^^^^^^^^^^^^^ lifetime `'a` required

View File

@ -38,7 +38,7 @@ error[E0621]: explicit lifetime required in the type of `y`
--> $DIR/issue-40288-2.rs:17:9 --> $DIR/issue-40288-2.rs:17:9
| |
LL | fn lifetime_transmute_slice<'a, T: ?Sized>(x: &'a T, y: &T) -> &'a T { LL | fn lifetime_transmute_slice<'a, T: ?Sized>(x: &'a T, y: &T) -> &'a T {
| - consider changing the type of `y` to `&'a T` | -- help: consider changing the type of `y` to : `&'a T`
... ...
LL | slice[0] = y; LL | slice[0] = y;
| ^^^^^^^^^^^^ lifetime `'a` required | ^^^^^^^^^^^^ lifetime `'a` required
@ -47,7 +47,7 @@ error[E0621]: explicit lifetime required in the type of `y`
--> $DIR/issue-40288-2.rs:32:9 --> $DIR/issue-40288-2.rs:32:9
| |
LL | fn lifetime_transmute_struct<'a, T: ?Sized>(x: &'a T, y: &T) -> &'a T { LL | fn lifetime_transmute_struct<'a, T: ?Sized>(x: &'a T, y: &T) -> &'a T {
| - consider changing the type of `y` to `&'a T` | -- help: consider changing the type of `y` to : `&'a T`
... ...
LL | dst.head = y; LL | dst.head = y;
| ^^^^^^^^^^^^ lifetime `'a` required | ^^^^^^^^^^^^ lifetime `'a` required

View File

@ -2,7 +2,7 @@ error[E0621]: explicit lifetime required in the type of `y`
--> $DIR/issue-40288-2.rs:19:5 --> $DIR/issue-40288-2.rs:19:5
| |
LL | fn lifetime_transmute_slice<'a, T: ?Sized>(x: &'a T, y: &T) -> &'a T { LL | fn lifetime_transmute_slice<'a, T: ?Sized>(x: &'a T, y: &T) -> &'a T {
| - consider changing the type of `y` to `&'a T` | -- help: consider changing the type of `y` to : `&'a T`
... ...
LL | out[0] LL | out[0]
| ^^^^^^ lifetime `'a` required | ^^^^^^ lifetime `'a` required
@ -11,7 +11,7 @@ error[E0621]: explicit lifetime required in the type of `y`
--> $DIR/issue-40288-2.rs:34:5 --> $DIR/issue-40288-2.rs:34:5
| |
LL | fn lifetime_transmute_struct<'a, T: ?Sized>(x: &'a T, y: &T) -> &'a T { LL | fn lifetime_transmute_struct<'a, T: ?Sized>(x: &'a T, y: &T) -> &'a T {
| - consider changing the type of `y` to `&'a T` | -- help: consider changing the type of `y` to : `&'a T`
... ...
LL | out.head LL | out.head
| ^^^^^^^^ lifetime `'a` required | ^^^^^^^^ lifetime `'a` required

View File

@ -2,7 +2,7 @@ error[E0621]: explicit lifetime required in the type of `x`
--> $DIR/issue-46983.rs:14:5 --> $DIR/issue-46983.rs:14:5
| |
LL | fn foo(x: &u32) -> &'static u32 { LL | fn foo(x: &u32) -> &'static u32 {
| - consider changing the type of `x` to `&'static u32` | ---- help: consider changing the type of `x` to : `&'static u32`
LL | &*x LL | &*x
| ^^^ lifetime `'static` required | ^^^ lifetime `'static` required

View File

@ -8,7 +8,7 @@ error[E0621]: explicit lifetime required in the type of `x`
--> $DIR/42701_one_named_and_one_anonymous.rs:16:5 --> $DIR/42701_one_named_and_one_anonymous.rs:16:5
| |
LL | fn foo2<'a>(a: &'a Foo, x: &i32) -> &'a i32 { LL | fn foo2<'a>(a: &'a Foo, x: &i32) -> &'a i32 {
| - consider changing the type of `x` to `&'a i32` | ---- help: consider changing the type of `x` to : `&'a i32`
LL | / if true { LL | / if true {
LL | | let p: &i32 = &a.field; LL | | let p: &i32 = &a.field;
LL | | &*p LL | | &*p

View File

@ -2,7 +2,7 @@ error[E0621]: explicit lifetime required in the type of `x`
--> $DIR/42701_one_named_and_one_anonymous.rs:20:9 --> $DIR/42701_one_named_and_one_anonymous.rs:20:9
| |
LL | fn foo2<'a>(a: &'a Foo, x: &i32) -> &'a i32 { LL | fn foo2<'a>(a: &'a Foo, x: &i32) -> &'a i32 {
| - consider changing the type of `x` to `&'a i32` | ---- help: consider changing the type of `x` to : `&'a i32`
... ...
LL | &*x //~ ERROR explicit lifetime LL | &*x //~ ERROR explicit lifetime
| ^^^ lifetime `'a` required | ^^^ lifetime `'a` required

View File

@ -8,7 +8,7 @@ error[E0621]: explicit lifetime required in the type of `other`
--> $DIR/ex1-return-one-existing-name-early-bound-in-struct.rs:18:15 --> $DIR/ex1-return-one-existing-name-early-bound-in-struct.rs:18:15
| |
LL | fn bar(&self, other: Foo) -> Foo<'a> { LL | fn bar(&self, other: Foo) -> Foo<'a> {
| ----- consider changing the type of `other` to `Foo<'a>` | --- help: consider changing the type of `other` to : `Foo<'a>`
LL | match *self { LL | match *self {
| ^^^^^ lifetime `'a` required | ^^^^^ lifetime `'a` required

View File

@ -2,7 +2,7 @@ error[E0621]: explicit lifetime required in the type of `other`
--> $DIR/ex1-return-one-existing-name-early-bound-in-struct.rs:21:21 --> $DIR/ex1-return-one-existing-name-early-bound-in-struct.rs:21:21
| |
LL | fn bar(&self, other: Foo) -> Foo<'a> { LL | fn bar(&self, other: Foo) -> Foo<'a> {
| ----- consider changing the type of `other` to `Foo<'a>` | --- help: consider changing the type of `other` to : `Foo<'a>`
... ...
LL | other //~ ERROR explicit lifetime LL | other //~ ERROR explicit lifetime
| ^^^^^ lifetime `'a` required | ^^^^^ lifetime `'a` required

View File

@ -8,7 +8,7 @@ error[E0621]: explicit lifetime required in the type of `x`
--> $DIR/ex1-return-one-existing-name-if-else-2.rs:12:8 --> $DIR/ex1-return-one-existing-name-if-else-2.rs:12:8
| |
LL | fn foo<'a>(x: &i32, y: &'a i32) -> &'a i32 { LL | fn foo<'a>(x: &i32, y: &'a i32) -> &'a i32 {
| - consider changing the type of `x` to `&'a i32` | ---- help: consider changing the type of `x` to : `&'a i32`
LL | if x > y { x } else { y } //~ ERROR explicit lifetime LL | if x > y { x } else { y } //~ ERROR explicit lifetime
| ^^^^^ lifetime `'a` required | ^^^^^ lifetime `'a` required

View File

@ -2,7 +2,7 @@ error[E0621]: explicit lifetime required in the type of `x`
--> $DIR/ex1-return-one-existing-name-if-else-2.rs:12:16 --> $DIR/ex1-return-one-existing-name-if-else-2.rs:12:16
| |
LL | fn foo<'a>(x: &i32, y: &'a i32) -> &'a i32 { LL | fn foo<'a>(x: &i32, y: &'a i32) -> &'a i32 {
| - consider changing the type of `x` to `&'a i32` | ---- help: consider changing the type of `x` to : `&'a i32`
LL | if x > y { x } else { y } //~ ERROR explicit lifetime LL | if x > y { x } else { y } //~ ERROR explicit lifetime
| ^ lifetime `'a` required | ^ lifetime `'a` required

View File

@ -8,10 +8,9 @@ error[E0621]: explicit lifetime required in parameter type
--> $DIR/ex1-return-one-existing-name-if-else-3.rs:11:16 --> $DIR/ex1-return-one-existing-name-if-else-3.rs:11:16
| |
LL | fn foo<'a>((x, y): (&'a i32, &i32)) -> &'a i32 { LL | fn foo<'a>((x, y): (&'a i32, &i32)) -> &'a i32 {
| ----^- | ^ --------------- help: consider changing type to : `(&'a i32, &'a i32)`
| | | | |
| | lifetime `'a` required | lifetime `'a` required
| consider changing type to `(&'a i32, &'a i32)`
error: aborting due to previous error error: aborting due to previous error

View File

@ -2,7 +2,7 @@ error[E0621]: explicit lifetime required in parameter type
--> $DIR/ex1-return-one-existing-name-if-else-3.rs:12:27 --> $DIR/ex1-return-one-existing-name-if-else-3.rs:12:27
| |
LL | fn foo<'a>((x, y): (&'a i32, &i32)) -> &'a i32 { LL | fn foo<'a>((x, y): (&'a i32, &i32)) -> &'a i32 {
| ------ consider changing type to `(&'a i32, &'a i32)` | --------------- help: consider changing type to : `(&'a i32, &'a i32)`
LL | if x > y { x } else { y } //~ ERROR explicit lifetime LL | if x > y { x } else { y } //~ ERROR explicit lifetime
| ^ lifetime `'a` required | ^ lifetime `'a` required

View File

@ -8,7 +8,7 @@ error[E0621]: explicit lifetime required in the type of `x`
--> $DIR/ex1-return-one-existing-name-if-else-using-impl-2.rs:14:7 --> $DIR/ex1-return-one-existing-name-if-else-using-impl-2.rs:14:7
| |
LL | fn foo<'a>(x: &i32, y: &'a i32) -> &'a i32 { LL | fn foo<'a>(x: &i32, y: &'a i32) -> &'a i32 {
| - consider changing the type of `x` to `&'a i32` | ---- help: consider changing the type of `x` to : `&'a i32`
LL | if x > y { x } else { y } //~ ERROR explicit lifetime LL | if x > y { x } else { y } //~ ERROR explicit lifetime
| ^^^^^ lifetime `'a` required | ^^^^^ lifetime `'a` required

View File

@ -2,7 +2,7 @@ error[E0621]: explicit lifetime required in the type of `x`
--> $DIR/ex1-return-one-existing-name-if-else-using-impl-2.rs:14:15 --> $DIR/ex1-return-one-existing-name-if-else-using-impl-2.rs:14:15
| |
LL | fn foo<'a>(x: &i32, y: &'a i32) -> &'a i32 { LL | fn foo<'a>(x: &i32, y: &'a i32) -> &'a i32 {
| - consider changing the type of `x` to `&'a i32` | ---- help: consider changing the type of `x` to : `&'a i32`
LL | if x > y { x } else { y } //~ ERROR explicit lifetime LL | if x > y { x } else { y } //~ ERROR explicit lifetime
| ^ lifetime `'a` required | ^ lifetime `'a` required

View File

@ -8,7 +8,7 @@ error[E0621]: explicit lifetime required in the type of `x`
--> $DIR/ex1-return-one-existing-name-if-else-using-impl-3.rs:18:5 --> $DIR/ex1-return-one-existing-name-if-else-using-impl-3.rs:18:5
| |
LL | fn foo<'a>(&'a self, x: &i32) -> &i32 { LL | fn foo<'a>(&'a self, x: &i32) -> &i32 {
| - consider changing the type of `x` to `&'a i32` | ---- help: consider changing the type of `x` to : `&'a i32`
LL | LL |
LL | if true { &self.field } else { x } //~ ERROR explicit lifetime LL | if true { &self.field } else { x } //~ ERROR explicit lifetime
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ lifetime `'a` required | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ lifetime `'a` required

View File

@ -2,7 +2,7 @@ error[E0621]: explicit lifetime required in the type of `x`
--> $DIR/ex1-return-one-existing-name-if-else-using-impl-3.rs:18:36 --> $DIR/ex1-return-one-existing-name-if-else-using-impl-3.rs:18:36
| |
LL | fn foo<'a>(&'a self, x: &i32) -> &i32 { LL | fn foo<'a>(&'a self, x: &i32) -> &i32 {
| - consider changing the type of `x` to `&'a i32` | ---- help: consider changing the type of `x` to : `&'a i32`
LL | LL |
LL | if true { &self.field } else { x } //~ ERROR explicit lifetime LL | if true { &self.field } else { x } //~ ERROR explicit lifetime
| ^ lifetime `'a` required | ^ lifetime `'a` required

View File

@ -8,7 +8,7 @@ error[E0621]: explicit lifetime required in the type of `y`
--> $DIR/ex1-return-one-existing-name-if-else.rs:12:8 --> $DIR/ex1-return-one-existing-name-if-else.rs:12:8
| |
LL | fn foo<'a>(x: &'a i32, y: &i32) -> &'a i32 { LL | fn foo<'a>(x: &'a i32, y: &i32) -> &'a i32 {
| - consider changing the type of `y` to `&'a i32` | ---- help: consider changing the type of `y` to : `&'a i32`
LL | if x > y { x } else { y } //~ ERROR explicit lifetime LL | if x > y { x } else { y } //~ ERROR explicit lifetime
| ^^^^^ lifetime `'a` required | ^^^^^ lifetime `'a` required

View File

@ -2,7 +2,7 @@ error[E0621]: explicit lifetime required in the type of `y`
--> $DIR/ex1-return-one-existing-name-if-else.rs:12:27 --> $DIR/ex1-return-one-existing-name-if-else.rs:12:27
| |
LL | fn foo<'a>(x: &'a i32, y: &i32) -> &'a i32 { LL | fn foo<'a>(x: &'a i32, y: &i32) -> &'a i32 {
| - consider changing the type of `y` to `&'a i32` | ---- help: consider changing the type of `y` to : `&'a i32`
LL | if x > y { x } else { y } //~ ERROR explicit lifetime LL | if x > y { x } else { y } //~ ERROR explicit lifetime
| ^ lifetime `'a` required | ^ lifetime `'a` required

View File

@ -8,7 +8,7 @@ error[E0621]: explicit lifetime required in the type of `x`
--> $DIR/ex2a-push-one-existing-name-2.rs:16:5 --> $DIR/ex2a-push-one-existing-name-2.rs:16:5
| |
LL | fn foo<'a>(x: Ref<i32>, y: &mut Vec<Ref<'a, i32>>) { LL | fn foo<'a>(x: Ref<i32>, y: &mut Vec<Ref<'a, i32>>) {
| - consider changing the type of `x` to `Ref<'a, i32>` | -------- help: consider changing the type of `x` to : `Ref<'a, i32>`
LL | y.push(x); //~ ERROR explicit lifetime LL | y.push(x); //~ ERROR explicit lifetime
| ^^^^^^^^^ lifetime `'a` required | ^^^^^^^^^ lifetime `'a` required

View File

@ -2,7 +2,7 @@ error[E0621]: explicit lifetime required in the type of `x`
--> $DIR/ex2a-push-one-existing-name-2.rs:16:12 --> $DIR/ex2a-push-one-existing-name-2.rs:16:12
| |
LL | fn foo<'a>(x: Ref<i32>, y: &mut Vec<Ref<'a, i32>>) { LL | fn foo<'a>(x: Ref<i32>, y: &mut Vec<Ref<'a, i32>>) {
| - consider changing the type of `x` to `Ref<'a, i32>` | -------- help: consider changing the type of `x` to : `Ref<'a, i32>`
LL | y.push(x); //~ ERROR explicit lifetime LL | y.push(x); //~ ERROR explicit lifetime
| ^ lifetime `'a` required | ^ lifetime `'a` required

View File

@ -2,7 +2,7 @@ error[E0621]: explicit lifetime required in the type of `y`
--> $DIR/ex2a-push-one-existing-name-early-bound.rs:17:12 --> $DIR/ex2a-push-one-existing-name-early-bound.rs:17:12
| |
LL | fn baz<'a, 'b, T>(x: &mut Vec<&'a T>, y: &T) LL | fn baz<'a, 'b, T>(x: &mut Vec<&'a T>, y: &T)
| - consider changing the type of `y` to `&'a T` | -- help: consider changing the type of `y` to : `&'a T`
... ...
LL | x.push(y); //~ ERROR explicit lifetime required LL | x.push(y); //~ ERROR explicit lifetime required
| ^ lifetime `'a` required | ^ lifetime `'a` required

View File

@ -8,7 +8,7 @@ error[E0621]: explicit lifetime required in the type of `y`
--> $DIR/ex2a-push-one-existing-name.rs:16:5 --> $DIR/ex2a-push-one-existing-name.rs:16:5
| |
LL | fn foo<'a>(x: &mut Vec<Ref<'a, i32>>, y: Ref<i32>) { LL | fn foo<'a>(x: &mut Vec<Ref<'a, i32>>, y: Ref<i32>) {
| - consider changing the type of `y` to `Ref<'a, i32>` | -------- help: consider changing the type of `y` to : `Ref<'a, i32>`
LL | x.push(y); //~ ERROR explicit lifetime LL | x.push(y); //~ ERROR explicit lifetime
| ^^^^^^^^^ lifetime `'a` required | ^^^^^^^^^ lifetime `'a` required

View File

@ -2,7 +2,7 @@ error[E0621]: explicit lifetime required in the type of `y`
--> $DIR/ex2a-push-one-existing-name.rs:16:12 --> $DIR/ex2a-push-one-existing-name.rs:16:12
| |
LL | fn foo<'a>(x: &mut Vec<Ref<'a, i32>>, y: Ref<i32>) { LL | fn foo<'a>(x: &mut Vec<Ref<'a, i32>>, y: Ref<i32>) {
| - consider changing the type of `y` to `Ref<'a, i32>` | -------- help: consider changing the type of `y` to : `Ref<'a, i32>`
LL | x.push(y); //~ ERROR explicit lifetime LL | x.push(y); //~ ERROR explicit lifetime
| ^ lifetime `'a` required | ^ lifetime `'a` required

View File

@ -8,7 +8,7 @@ error[E0621]: explicit lifetime required in the type of `x`
--> $DIR/region-lbr-anon-does-not-outlive-static.rs:19:5 --> $DIR/region-lbr-anon-does-not-outlive-static.rs:19:5
| |
LL | fn foo(x: &u32) -> &'static u32 { LL | fn foo(x: &u32) -> &'static u32 {
| - consider changing the type of `x` to `&ReStatic u32` | ---- help: consider changing the type of `x` to : `&ReStatic u32`
LL | &*x LL | &*x
| ^^^ lifetime `ReStatic` required | ^^^ lifetime `ReStatic` required

View File

@ -13,7 +13,7 @@ error[E0621]: explicit lifetime required in the type of `s`
--> $DIR/guarantor-issue-46974.rs:25:5 --> $DIR/guarantor-issue-46974.rs:25:5
| |
LL | fn bar(s: &Box<(i32,)>) -> &'static i32 { LL | fn bar(s: &Box<(i32,)>) -> &'static i32 {
| - consider changing the type of `s` to `&'static std::boxed::Box<(i32,)>` | ------------ help: consider changing the type of `s` to : `&'static std::boxed::Box<(i32,)>`
LL | // FIXME(#46983): error message should be better LL | // FIXME(#46983): error message should be better
LL | &s.0 //~ ERROR explicit lifetime required in the type of `s` [E0621] LL | &s.0 //~ ERROR explicit lifetime required in the type of `s` [E0621]
| ^^^^ lifetime `'static` required | ^^^^ lifetime `'static` required

View File

@ -8,7 +8,7 @@ error[E0621]: explicit lifetime required in the type of `x`
--> $DIR/impl-trait-captures.rs:21:5 --> $DIR/impl-trait-captures.rs:21:5
| |
LL | fn foo<'a, T>(x: &T) -> impl Foo<'a> { LL | fn foo<'a, T>(x: &T) -> impl Foo<'a> {
| - consider changing the type of `x` to `&ReEarlyBound(0, 'a) T` | -- help: consider changing the type of `x` to : `&ReEarlyBound(0, 'a) T`
LL | x LL | x
| ^ lifetime `ReEarlyBound(0, 'a)` required | ^ lifetime `ReEarlyBound(0, 'a)` required