From aa6f0c80507230d864f7af5fe3c4085e28cabfe9 Mon Sep 17 00:00:00 2001 From: gaurikholkar Date: Mon, 11 Sep 2017 20:27:26 +0530 Subject: [PATCH] modify message for return time having multiple lifetimes --- .../error_reporting/different_lifetimes.rs | 12 ++------ ...ne-existing-name-if-else-using-impl.stderr | 29 +++++-------------- ...e-existing-name-return-type-is-anon.stderr | 9 ++++-- ...turn-one-existing-name-self-is-anon.stderr | 9 ++++-- ...th-anon-regions-return-type-is-anon.stderr | 6 ++-- .../ex3-both-anon-regions-self-is-anon.stderr | 4 +-- 6 files changed, 27 insertions(+), 42 deletions(-) diff --git a/src/librustc/infer/error_reporting/different_lifetimes.rs b/src/librustc/infer/error_reporting/different_lifetimes.rs index 687b518ef6af..e9866545f976 100644 --- a/src/librustc/infer/error_reporting/different_lifetimes.rs +++ b/src/librustc/infer/error_reporting/different_lifetimes.rs @@ -82,7 +82,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { self.is_return_type_anon(scope_def_id_sub, bregion_sub, ty_fndecl_sub); let span_label_var1 = if let Some(simple_name) = anon_arg_sup.pat.simple_name() { - format!(" flows from `{}`", simple_name) + format!(" from `{}`", simple_name) } else { format!("") }; @@ -103,21 +103,13 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { format!(" with one lifetime"), format!(" into the other"))) } else { - (format!("these two types was declared with multiple lifetimes..."), + (format!("these two types was declared with different lifetimes..."), format!("...but data{} flows{} here", span_label_var1, span_label_var2)) }; (ty_sup.span, ty_sub.span, main_label_1, span_label_1) } - (Some(ret_span1), Some(ret_span2)) => { - (ret_span1, - ret_span2, - format!("the return type is declared with different lifetimes..."), - format!("...but data{} flows{} here", - format!(" with one lifetime"), - format!(" into the other"))) - } (Some(ret_span), _) => { (ty_sub.span, diff --git a/src/test/ui/lifetime-errors/ex1-return-one-existing-name-if-else-using-impl.stderr b/src/test/ui/lifetime-errors/ex1-return-one-existing-name-if-else-using-impl.stderr index 9e4f6c421790..f383a4dcf673 100644 --- a/src/test/ui/lifetime-errors/ex1-return-one-existing-name-if-else-using-impl.stderr +++ b/src/test/ui/lifetime-errors/ex1-return-one-existing-name-if-else-using-impl.stderr @@ -1,27 +1,14 @@ -error[E0312]: lifetime of reference outlives lifetime of borrowed content... +error[E0623]: lifetime mismatch --> $DIR/ex1-return-one-existing-name-if-else-using-impl.rs:21:20 | +19 | fn foo<'a>(x: &i32, y: &'a i32) -> &'a i32 { + | ---- ------- + | | + | this parameter and the return type are declared + with different lifetimes... +20 | 21 | if x > y { x } else { y } - | ^ - | -note: ...the reference is valid for the lifetime 'a as defined on the method body at 19:5... - --> $DIR/ex1-return-one-existing-name-if-else-using-impl.rs:19:5 - | -19 | / fn foo<'a>(x: &i32, y: &'a i32) -> &'a i32 { -20 | | -21 | | if x > y { x } else { y } -22 | | -23 | | } - | |_____^ -note: ...but the borrowed content is only valid for the anonymous lifetime #1 defined on the method body at 19:5 - --> $DIR/ex1-return-one-existing-name-if-else-using-impl.rs:19:5 - | -19 | / fn foo<'a>(x: &i32, y: &'a i32) -> &'a i32 { -20 | | -21 | | if x > y { x } else { y } -22 | | -23 | | } - | |_____^ + | ^ ...but data flows `x` is returned here error: aborting due to previous error diff --git a/src/test/ui/lifetime-errors/ex1-return-one-existing-name-return-type-is-anon.stderr b/src/test/ui/lifetime-errors/ex1-return-one-existing-name-return-type-is-anon.stderr index 4a1673a531d3..27a674e5bb7e 100644 --- a/src/test/ui/lifetime-errors/ex1-return-one-existing-name-return-type-is-anon.stderr +++ b/src/test/ui/lifetime-errors/ex1-return-one-existing-name-return-type-is-anon.stderr @@ -1,11 +1,14 @@ -error[E0621]: explicit lifetime required in the type of `self` +error[E0623]: lifetime mismatch --> $DIR/ex1-return-one-existing-name-return-type-is-anon.rs:18:5 | 16 | fn foo<'a>(&self, x: &'a i32) -> &i32 { - | ----- consider changing the type of `self` to `&'a Foo` + | ------- ---- + | | + | this parameter and the return type are declared + with different lifetimes... 17 | 18 | x - | ^ lifetime `'a` required + | ^ ...but data flows from `x` is returned here error: aborting due to previous error diff --git a/src/test/ui/lifetime-errors/ex1-return-one-existing-name-self-is-anon.stderr b/src/test/ui/lifetime-errors/ex1-return-one-existing-name-self-is-anon.stderr index 973c5ed72f87..8f957d1b009d 100644 --- a/src/test/ui/lifetime-errors/ex1-return-one-existing-name-self-is-anon.stderr +++ b/src/test/ui/lifetime-errors/ex1-return-one-existing-name-self-is-anon.stderr @@ -1,11 +1,14 @@ -error[E0621]: explicit lifetime required in the type of `self` +error[E0623]: lifetime mismatch --> $DIR/ex1-return-one-existing-name-self-is-anon.rs:18:30 | 16 | fn foo<'a>(&self, x: &'a Foo) -> &'a Foo { - | ----- consider changing the type of `self` to `&'a Foo` + | ----- ------- + | | + | this parameter and the return type are declared + with different lifetimes... 17 | 18 | if true { x } else { self } - | ^^^^ lifetime `'a` required + | ^^^^ ...but data flows from `self` is returned here error: aborting due to previous error diff --git a/src/test/ui/lifetime-errors/ex3-both-anon-regions-return-type-is-anon.stderr b/src/test/ui/lifetime-errors/ex3-both-anon-regions-return-type-is-anon.stderr index c6b1280ca95a..1ea2a4ff8ad4 100644 --- a/src/test/ui/lifetime-errors/ex3-both-anon-regions-return-type-is-anon.stderr +++ b/src/test/ui/lifetime-errors/ex3-both-anon-regions-return-type-is-anon.stderr @@ -1,11 +1,11 @@ -error[E0621]: explicit lifetime required in the type of `self` +error[E0623]: lifetime mismatch --> $DIR/ex3-both-anon-regions-return-type-is-anon.rs:17:5 | 16 | fn foo<'a>(&self, x: &i32) -> &i32 { | ---- ---- | | - | this parameter and the return type are - declared with different lifetimes... + | this parameter and the return type are declared + with different lifetimes... 17 | x | ^ ...but data from `x` is returned here diff --git a/src/test/ui/lifetime-errors/ex3-both-anon-regions-self-is-anon.stderr b/src/test/ui/lifetime-errors/ex3-both-anon-regions-self-is-anon.stderr index 9b15de1b1738..316b76c64607 100644 --- a/src/test/ui/lifetime-errors/ex3-both-anon-regions-self-is-anon.stderr +++ b/src/test/ui/lifetime-errors/ex3-both-anon-regions-self-is-anon.stderr @@ -4,8 +4,8 @@ error[E0623]: lifetime mismatch 16 | fn foo<'a>(&self, x: &Foo) -> &Foo { | ---- ---- | | - | this parameter and the return type are - declared with different lifetimes... + | this parameter and the return type are declared + with different lifetimes... 17 | if true { x } else { self } | ^ ...but data from `x` is returned here