]> git.lizzy.rs Git - rust.git/commitdiff
Changing the error code to E0621
authorgaurikholkar <f2013002@goa.bits-pilani.ac.in>
Mon, 26 Jun 2017 18:26:01 +0000 (11:26 -0700)
committergaurikholkar <f2013002@goa.bits-pilani.ac.in>
Thu, 29 Jun 2017 13:37:18 +0000 (06:37 -0700)
src/librustc/diagnostics.rs
src/librustc/infer/error_reporting/named_anon_conflict.rs
src/test/ui/lifetime-errors/ex1-return-one-existing-name-if-else-2.stderr
src/test/ui/lifetime-errors/ex1-return-one-existing-name-if-else-3.stderr
src/test/ui/lifetime-errors/ex1-return-one-existing-name-if-else-using-impl-2.stderr
src/test/ui/lifetime-errors/ex1-return-one-existing-name-if-else-using-impl-3.stderr
src/test/ui/lifetime-errors/ex1-return-one-existing-name-if-else.stderr
src/test/ui/lifetime-errors/ex2a-push-one-existing-name-2.stderr
src/test/ui/lifetime-errors/ex2a-push-one-existing-name.stderr

index 1e7f3f9aeb8b9e10db632e1d3db5bfd5d652d819..aa62cab7c3dccf22bf2163ba695524cffe00c69b 100644 (file)
@@ -1946,11 +1946,19 @@ fn main() {
 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:
-
-```compile_fail,E0611
+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.
+
+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 () { }
 ```
 "##,
 
index 4a1f4b418ae4a1555089d4f566c7d7da846f385f..fb0bd901db4b793b6c58bc361314a91b89da647e 100644 (file)
@@ -124,7 +124,7 @@ pub fn try_report_named_anon_conflict(&self, error: &RegionResolutionError<'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 @@ pub fn try_report_named_anon_conflict(&self, error: &RegionResolutionError<'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 @@ pub fn try_report_named_anon_conflict(&self, error: &RegionResolutionError<'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))
index ada7af8c1e46f755784797dba2cbe58a6998f7e7..4d8c5e039af418846ed2476fe098e08ce4ddc445 100644 (file)
@@ -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 {
index 58aab7113944057c05e01c06ed470a1610e6f752..07b276601f47cef82517949e2908b28265b3f0ea 100644 (file)
@@ -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 {
index ec787eb749c014efd90d2120cc1c9b22a30794f9..2adf0cd762c59b342f855438fbe5b3310b256f61 100644 (file)
@@ -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 {
index 502871022ff6f3b06ae79886ddb5df717f9dd436..15825017d15c3edd9aada9447f00ee275a5435e9 100644 (file)
@@ -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 {
index 837fa141bf1c20bccb96f8c7d56043e1b911cb0a..892a6dcd1e9346bf414746f577dac32d9ea6ec40 100644 (file)
@@ -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 {
index a16dac672aeda15e9f4a313fea142d38acbf3ebb..ea696c51d62188ece63e4d106e3b6f612d02e005 100644 (file)
@@ -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>>) {
index 537090aa67de7e736b4fca602e5cbff6cea0f93f..1630ae32ba6bf65d7f48bbfac1e4e726a70ba66a 100644 (file)
@@ -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>) {