Skip to content

Commit aa6f0c8

Browse files
gaurikholkarnikomatsakis
authored andcommitted
modify message for return time having multiple lifetimes
1 parent e58f528 commit aa6f0c8

6 files changed

+27
-42
lines changed

src/librustc/infer/error_reporting/different_lifetimes.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
8282
self.is_return_type_anon(scope_def_id_sub, bregion_sub, ty_fndecl_sub);
8383

8484
let span_label_var1 = if let Some(simple_name) = anon_arg_sup.pat.simple_name() {
85-
format!(" flows from `{}`", simple_name)
85+
format!(" from `{}`", simple_name)
8686
} else {
8787
format!("")
8888
};
@@ -103,21 +103,13 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
103103
format!(" with one lifetime"),
104104
format!(" into the other")))
105105
} else {
106-
(format!("these two types was declared with multiple lifetimes..."),
106+
(format!("these two types was declared with different lifetimes..."),
107107
format!("...but data{} flows{} here",
108108
span_label_var1,
109109
span_label_var2))
110110
};
111111
(ty_sup.span, ty_sub.span, main_label_1, span_label_1)
112112
}
113-
(Some(ret_span1), Some(ret_span2)) => {
114-
(ret_span1,
115-
ret_span2,
116-
format!("the return type is declared with different lifetimes..."),
117-
format!("...but data{} flows{} here",
118-
format!(" with one lifetime"),
119-
format!(" into the other")))
120-
}
121113

122114
(Some(ret_span), _) => {
123115
(ty_sub.span,
Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,14 @@
1-
error[E0312]: lifetime of reference outlives lifetime of borrowed content...
1+
error[E0623]: lifetime mismatch
22
--> $DIR/ex1-return-one-existing-name-if-else-using-impl.rs:21:20
33
|
4+
19 | fn foo<'a>(x: &i32, y: &'a i32) -> &'a i32 {
5+
| ---- -------
6+
| |
7+
| this parameter and the return type are declared
8+
with different lifetimes...
9+
20 |
410
21 | if x > y { x } else { y }
5-
| ^
6-
|
7-
note: ...the reference is valid for the lifetime 'a as defined on the method body at 19:5...
8-
--> $DIR/ex1-return-one-existing-name-if-else-using-impl.rs:19:5
9-
|
10-
19 | / fn foo<'a>(x: &i32, y: &'a i32) -> &'a i32 {
11-
20 | |
12-
21 | | if x > y { x } else { y }
13-
22 | |
14-
23 | | }
15-
| |_____^
16-
note: ...but the borrowed content is only valid for the anonymous lifetime #1 defined on the method body at 19:5
17-
--> $DIR/ex1-return-one-existing-name-if-else-using-impl.rs:19:5
18-
|
19-
19 | / fn foo<'a>(x: &i32, y: &'a i32) -> &'a i32 {
20-
20 | |
21-
21 | | if x > y { x } else { y }
22-
22 | |
23-
23 | | }
24-
| |_____^
11+
| ^ ...but data flows `x` is returned here
2512

2613
error: aborting due to previous error
2714

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1-
error[E0621]: explicit lifetime required in the type of `self`
1+
error[E0623]: lifetime mismatch
22
--> $DIR/ex1-return-one-existing-name-return-type-is-anon.rs:18:5
33
|
44
16 | fn foo<'a>(&self, x: &'a i32) -> &i32 {
5-
| ----- consider changing the type of `self` to `&'a Foo`
5+
| ------- ----
6+
| |
7+
| this parameter and the return type are declared
8+
with different lifetimes...
69
17 |
710
18 | x
8-
| ^ lifetime `'a` required
11+
| ^ ...but data flows from `x` is returned here
912

1013
error: aborting due to previous error
1114

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1-
error[E0621]: explicit lifetime required in the type of `self`
1+
error[E0623]: lifetime mismatch
22
--> $DIR/ex1-return-one-existing-name-self-is-anon.rs:18:30
33
|
44
16 | fn foo<'a>(&self, x: &'a Foo) -> &'a Foo {
5-
| ----- consider changing the type of `self` to `&'a Foo`
5+
| ----- -------
6+
| |
7+
| this parameter and the return type are declared
8+
with different lifetimes...
69
17 |
710
18 | if true { x } else { self }
8-
| ^^^^ lifetime `'a` required
11+
| ^^^^ ...but data flows from `self` is returned here
912

1013
error: aborting due to previous error
1114

src/test/ui/lifetime-errors/ex3-both-anon-regions-return-type-is-anon.stderr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
error[E0621]: explicit lifetime required in the type of `self`
1+
error[E0623]: lifetime mismatch
22
--> $DIR/ex3-both-anon-regions-return-type-is-anon.rs:17:5
33
|
44
16 | fn foo<'a>(&self, x: &i32) -> &i32 {
55
| ---- ----
66
| |
7-
| this parameter and the return type are
8-
declared with different lifetimes...
7+
| this parameter and the return type are declared
8+
with different lifetimes...
99
17 | x
1010
| ^ ...but data from `x` is returned here
1111

src/test/ui/lifetime-errors/ex3-both-anon-regions-self-is-anon.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ error[E0623]: lifetime mismatch
44
16 | fn foo<'a>(&self, x: &Foo) -> &Foo {
55
| ---- ----
66
| |
7-
| this parameter and the return type are
8-
declared with different lifetimes...
7+
| this parameter and the return type are declared
8+
with different lifetimes...
99
17 | if true { x } else { self }
1010
| ^ ...but data from `x` is returned here
1111

0 commit comments

Comments
 (0)