Skip to content

Commit aebc4e0

Browse files
committed
Changing the error code to E0621
1 parent 82f25b3 commit aebc4e0

9 files changed

+34
-17
lines changed

src/librustc/diagnostics.rs

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1946,11 +1946,19 @@ Maybe you just misspelled the lint name or the lint doesn't exist anymore.
19461946
Either way, try to update/remove it in order to fix the error.
19471947
"##,
19481948

1949-
E0611: r##"
1950-
Lifetime parameter is missing in one of the function argument. Erroneous
1951-
code example:
1952-
1953-
```compile_fail,E0611
1949+
E0621: r##"
1950+
This error code indicates a mismatch between the function signature (i.e.,
1951+
the parameter types and the return type) and the function body. Most of
1952+
the time, this indicates that the function signature needs to be changed to
1953+
match the body, but it may be that the body needs to be changed to match
1954+
the signature.
1955+
1956+
Specifically, one or more of the parameters contain borrowed data that
1957+
needs to have a named lifetime in order for the body to type-check. Most of
1958+
the time, this is because the borrowed data is being returned from the
1959+
function, as in this example:
1960+
1961+
```compile_fail,E0621
19541962
fn foo<'a>(x: &'a i32, y: &i32) -> &'a i32 { // explicit lifetime required
19551963
// in the type of `y`
19561964
if x > y { x } else { y }
@@ -1959,15 +1967,24 @@ fn foo<'a>(x: &'a i32, y: &i32) -> &'a i32 { // explicit lifetime required
19591967
fn main () { }
19601968
```
19611969
1962-
Please add the missing lifetime parameter to remove this error. Example:
1970+
Here, the function is returning data borrowed from either x or y, but the
1971+
'a annotation indicates that it is returning data only from x. We can make
1972+
the signature match the body by changing the type of y to &'a i32, like so:
19631973
19641974
```
19651975
fn foo<'a>(x: &'a i32, y: &'a i32) -> &'a i32 {
19661976
if x > y { x } else { y }
19671977
}
19681978
1969-
fn main() {
1979+
fn main () { }
1980+
```
1981+
Alternatively, you could change the body not to return data from y:
1982+
```
1983+
fn foo<'a>(x: &'a i32, y: &i32) -> &'a i32 {
1984+
x
19701985
}
1986+
1987+
fn main () { }
19711988
```
19721989
"##,
19731990

src/librustc/infer/error_reporting/named_anon_conflict.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
124124
// Here we check for the case where anonymous region
125125
// corresponds to self and if yes, we display E0312.
126126
// FIXME(#42700) - Need to format self properly to
127-
// enable E0611 for it.
127+
// enable E0621 for it.
128128
if is_first &&
129129
self.tcx
130130
.opt_associated_item(scope_def_id)
@@ -136,7 +136,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
136136
if let Some(simple_name) = arg.pat.simple_name() {
137137
struct_span_err!(self.tcx.sess,
138138
span,
139-
E0611,
139+
E0621,
140140
"explicit lifetime required in the type of `{}`",
141141
simple_name)
142142
.span_label(arg.pat.span,
@@ -149,7 +149,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
149149
} else {
150150
struct_span_err!(self.tcx.sess,
151151
span,
152-
E0611,
152+
E0621,
153153
"explicit lifetime required in parameter type")
154154
.span_label(arg.pat.span,
155155
format!("consider changing type to `{}`", new_ty))

src/test/ui/lifetime-errors/ex1-return-one-existing-name-if-else-2.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0611]: explicit lifetime required in the type of `x`
1+
error[E0621]: explicit lifetime required in the type of `x`
22
--> $DIR/ex1-return-one-existing-name-if-else-2.rs:12:16
33
|
44
11 | fn foo<'a>(x: &i32, y: &'a i32) -> &'a i32 {

src/test/ui/lifetime-errors/ex1-return-one-existing-name-if-else-3.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0611]: explicit lifetime required in parameter type
1+
error[E0621]: explicit lifetime required in parameter type
22
--> $DIR/ex1-return-one-existing-name-if-else-3.rs:12:27
33
|
44
11 | fn foo<'a>((x, y): (&'a i32, &i32)) -> &'a i32 {

src/test/ui/lifetime-errors/ex1-return-one-existing-name-if-else-using-impl-2.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0611]: explicit lifetime required in the type of `x`
1+
error[E0621]: explicit lifetime required in the type of `x`
22
--> $DIR/ex1-return-one-existing-name-if-else-using-impl-2.rs:14:15
33
|
44
13 | fn foo<'a>(x: &i32, y: &'a i32) -> &'a i32 {

src/test/ui/lifetime-errors/ex1-return-one-existing-name-if-else-using-impl-3.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0611]: explicit lifetime required in the type of `x`
1+
error[E0621]: explicit lifetime required in the type of `x`
22
--> $DIR/ex1-return-one-existing-name-if-else-using-impl-3.rs:18:36
33
|
44
16 | fn foo<'a>(&'a self, x: &i32) -> &i32 {

src/test/ui/lifetime-errors/ex1-return-one-existing-name-if-else.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0611]: explicit lifetime required in the type of `y`
1+
error[E0621]: explicit lifetime required in the type of `y`
22
--> $DIR/ex1-return-one-existing-name-if-else.rs:12:27
33
|
44
11 | fn foo<'a>(x: &'a i32, y: &i32) -> &'a i32 {

src/test/ui/lifetime-errors/ex2a-push-one-existing-name-2.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0611]: explicit lifetime required in the type of `x`
1+
error[E0621]: explicit lifetime required in the type of `x`
22
--> $DIR/ex2a-push-one-existing-name-2.rs:16:12
33
|
44
15 | fn foo<'a>(x: Ref<i32>, y: &mut Vec<Ref<'a, i32>>) {

src/test/ui/lifetime-errors/ex2a-push-one-existing-name.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0611]: explicit lifetime required in the type of `y`
1+
error[E0621]: explicit lifetime required in the type of `y`
22
--> $DIR/ex2a-push-one-existing-name.rs:16:12
33
|
44
15 | fn foo<'a>(x: &mut Vec<Ref<'a, i32>>, y: Ref<i32>) {

0 commit comments

Comments
 (0)