Changing the error code to E0621
This commit is contained in:
parent
82f25b32ae
commit
aebc4e0074
9 changed files with 33 additions and 16 deletions
|
|
@ -1946,11 +1946,19 @@ Maybe you just misspelled the lint name or the lint doesn't exist anymore.
|
|||
Either way, try to update/remove it in order to fix the error.
|
||||
"##,
|
||||
|
||||
E0611: r##"
|
||||
Lifetime parameter is missing in one of the function argument. Erroneous
|
||||
code example:
|
||||
E0621: r##"
|
||||
This error code indicates a mismatch between the function signature (i.e.,
|
||||
the parameter types and the return type) and the function body. Most of
|
||||
the time, this indicates that the function signature needs to be changed to
|
||||
match the body, but it may be that the body needs to be changed to match
|
||||
the signature.
|
||||
|
||||
```compile_fail,E0611
|
||||
Specifically, one or more of the parameters contain borrowed data that
|
||||
needs to have a named lifetime in order for the body to type-check. Most of
|
||||
the time, this is because the borrowed data is being returned from the
|
||||
function, as in this example:
|
||||
|
||||
```compile_fail,E0621
|
||||
fn foo<'a>(x: &'a i32, y: &i32) -> &'a i32 { // explicit lifetime required
|
||||
// in the type of `y`
|
||||
if x > y { x } else { y }
|
||||
|
|
@ -1959,15 +1967,24 @@ fn foo<'a>(x: &'a i32, y: &i32) -> &'a i32 { // explicit lifetime required
|
|||
fn main () { }
|
||||
```
|
||||
|
||||
Please add the missing lifetime parameter to remove this error. Example:
|
||||
Here, the function is returning data borrowed from either x or y, but the
|
||||
'a annotation indicates that it is returning data only from x. We can make
|
||||
the signature match the body by changing the type of y to &'a i32, like so:
|
||||
|
||||
```
|
||||
fn foo<'a>(x: &'a i32, y: &'a i32) -> &'a i32 {
|
||||
if x > y { x } else { y }
|
||||
}
|
||||
|
||||
fn main() {
|
||||
fn main () { }
|
||||
```
|
||||
Alternatively, you could change the body not to return data from y:
|
||||
```
|
||||
fn foo<'a>(x: &'a i32, y: &i32) -> &'a i32 {
|
||||
x
|
||||
}
|
||||
|
||||
fn main () { }
|
||||
```
|
||||
"##,
|
||||
|
||||
|
|
|
|||
|
|
@ -124,7 +124,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
|
|||
// Here we check for the case where anonymous region
|
||||
// corresponds to self and if yes, we display E0312.
|
||||
// FIXME(#42700) - Need to format self properly to
|
||||
// enable E0611 for it.
|
||||
// enable E0621 for it.
|
||||
if is_first &&
|
||||
self.tcx
|
||||
.opt_associated_item(scope_def_id)
|
||||
|
|
@ -136,7 +136,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
|
|||
if let Some(simple_name) = arg.pat.simple_name() {
|
||||
struct_span_err!(self.tcx.sess,
|
||||
span,
|
||||
E0611,
|
||||
E0621,
|
||||
"explicit lifetime required in the type of `{}`",
|
||||
simple_name)
|
||||
.span_label(arg.pat.span,
|
||||
|
|
@ -149,7 +149,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
|
|||
} else {
|
||||
struct_span_err!(self.tcx.sess,
|
||||
span,
|
||||
E0611,
|
||||
E0621,
|
||||
"explicit lifetime required in parameter type")
|
||||
.span_label(arg.pat.span,
|
||||
format!("consider changing type to `{}`", new_ty))
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
error[E0611]: explicit lifetime required in the type of `x`
|
||||
error[E0621]: explicit lifetime required in the type of `x`
|
||||
--> $DIR/ex1-return-one-existing-name-if-else-2.rs:12:16
|
||||
|
|
||||
11 | fn foo<'a>(x: &i32, y: &'a i32) -> &'a i32 {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
error[E0611]: explicit lifetime required in parameter type
|
||||
error[E0621]: explicit lifetime required in parameter type
|
||||
--> $DIR/ex1-return-one-existing-name-if-else-3.rs:12:27
|
||||
|
|
||||
11 | fn foo<'a>((x, y): (&'a i32, &i32)) -> &'a i32 {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
error[E0611]: explicit lifetime required in the type of `x`
|
||||
error[E0621]: explicit lifetime required in the type of `x`
|
||||
--> $DIR/ex1-return-one-existing-name-if-else-using-impl-2.rs:14:15
|
||||
|
|
||||
13 | fn foo<'a>(x: &i32, y: &'a i32) -> &'a i32 {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
error[E0611]: explicit lifetime required in the type of `x`
|
||||
error[E0621]: explicit lifetime required in the type of `x`
|
||||
--> $DIR/ex1-return-one-existing-name-if-else-using-impl-3.rs:18:36
|
||||
|
|
||||
16 | fn foo<'a>(&'a self, x: &i32) -> &i32 {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
error[E0611]: explicit lifetime required in the type of `y`
|
||||
error[E0621]: explicit lifetime required in the type of `y`
|
||||
--> $DIR/ex1-return-one-existing-name-if-else.rs:12:27
|
||||
|
|
||||
11 | fn foo<'a>(x: &'a i32, y: &i32) -> &'a i32 {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
error[E0611]: explicit lifetime required in the type of `x`
|
||||
error[E0621]: explicit lifetime required in the type of `x`
|
||||
--> $DIR/ex2a-push-one-existing-name-2.rs:16:12
|
||||
|
|
||||
15 | fn foo<'a>(x: Ref<i32>, y: &mut Vec<Ref<'a, i32>>) {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
error[E0611]: explicit lifetime required in the type of `y`
|
||||
error[E0621]: explicit lifetime required in the type of `y`
|
||||
--> $DIR/ex2a-push-one-existing-name.rs:16:12
|
||||
|
|
||||
15 | fn foo<'a>(x: &mut Vec<Ref<'a, i32>>, y: Ref<i32>) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue