modify message for return time having multiple lifetimes
This commit is contained in:
parent
e58f528bb0
commit
aa6f0c8050
6 changed files with 27 additions and 42 deletions
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue