Rollup merge of #44124 - gaurikholkar:return_self, r=arielb1

adding E0623 for return types - both parameters are anonymous

This is a fix for #44018
```
error[E0621]: explicit lifetime required in the type of `self`
  --> $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...
17 |     x
   |     ^ ...but data from `x` is returned here

error: aborting due to previous error
```
It also works for the below case where we have self as anonymous

```
error[E0623]: lifetime mismatch
  --> src/test/ui/lifetime-errors/ex3-both-anon-regions-self-is-anon.rs:17:19
   |
16 |     fn foo<'a>(&self, x: &Foo) -> &Foo {
   |                          ----     ----
   |                          |
   |                          this parameter and the return type are
                            declared with different lifetimes...
17 |         if true { x } else { self }
   |                   ^ ...but data from `x` is returned here

error: aborting due to previous error
```
r? @nikomatsakis

Currently, I have enabled E0621 where return type and self are anonymous, hence WIP.
This commit is contained in:
Mark Simulacrum 2017-09-29 17:58:51 -06:00 committed by GitHub
commit f407b2bf4a
12 changed files with 146 additions and 254 deletions

View file

@ -34,7 +34,7 @@ fn load1<'a,'b>(a: &'a MyBox<SomeTrait>,
b: &'b MyBox<SomeTrait>)
-> &'b MyBox<SomeTrait>
{
a //~ ERROR E0312
a //~ ERROR lifetime mismatch
}
fn load2<'a>(ss: &MyBox<SomeTrait+'a>) -> MyBox<SomeTrait+'a> {

View file

@ -1,27 +1,13 @@
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 from `x` is returned here
error: aborting due to previous error

View file

@ -1,27 +1,13 @@
error[E0312]: lifetime of reference outlives lifetime of borrowed content...
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 {
| ------- ----
| |
| this parameter and the return type are declared with different lifetimes...
17 |
18 | x
| ^
|
note: ...the reference is valid for the anonymous lifetime #1 defined on the method body at 16:3...
--> $DIR/ex1-return-one-existing-name-return-type-is-anon.rs:16:3
|
16 | / fn foo<'a>(&self, x: &'a i32) -> &i32 {
17 | |
18 | | x
19 | |
20 | | }
| |___^
note: ...but the borrowed content is only valid for the lifetime 'a as defined on the method body at 16:3
--> $DIR/ex1-return-one-existing-name-return-type-is-anon.rs:16:3
|
16 | / fn foo<'a>(&self, x: &'a i32) -> &i32 {
17 | |
18 | | x
19 | |
20 | | }
| |___^
| ^ ...but data from `x` is returned here
error: aborting due to previous error

View file

@ -1,27 +1,13 @@
error[E0312]: lifetime of reference outlives lifetime of borrowed content...
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 {
| ----- -------
| |
| this parameter and the return type are declared with different lifetimes...
17 |
18 | if true { x } else { self }
| ^^^^
|
note: ...the reference is valid for the lifetime 'a as defined on the method body at 16:5...
--> $DIR/ex1-return-one-existing-name-self-is-anon.rs:16:5
|
16 | / fn foo<'a>(&self, x: &'a Foo) -> &'a Foo {
17 | |
18 | | if true { x } else { self }
19 | |
20 | | }
| |_____^
note: ...but the borrowed content is only valid for the anonymous lifetime #1 defined on the method body at 16:5
--> $DIR/ex1-return-one-existing-name-self-is-anon.rs:16:5
|
16 | / fn foo<'a>(&self, x: &'a Foo) -> &'a Foo {
17 | |
18 | | if true { x } else { self }
19 | |
20 | | }
| |_____^
| ^^^^ ...but data from `self` is returned here
error: aborting due to previous error

View file

@ -4,7 +4,7 @@ error[E0623]: lifetime mismatch
15 | fn foo(mut x: Ref) {
| ---
| |
| this type was declared with multiple lifetimes...
| this type is declared with multiple lifetimes...
16 | x.a = x.b;
| ^^^ ...but data with one lifetime flows into the other here

View file

@ -4,7 +4,7 @@ error[E0623]: lifetime mismatch
15 | fn foo(mut x: Ref) {
| ---
| |
| this type was declared with multiple lifetimes...
| this type is declared with multiple lifetimes...
16 | x.a = x.b;
| ^^^ ...but data with one lifetime flows into the other here

View file

@ -1,23 +1,12 @@
error[E0312]: lifetime of reference outlives lifetime of borrowed content...
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...
17 | x
| ^
|
note: ...the reference is valid for the anonymous lifetime #1 defined on the method body at 16:3...
--> $DIR/ex3-both-anon-regions-return-type-is-anon.rs:16:3
|
16 | / fn foo<'a>(&self, x: &i32) -> &i32 {
17 | | x
18 | | }
| |___^
note: ...but the borrowed content is only valid for the anonymous lifetime #2 defined on the method body at 16:3
--> $DIR/ex3-both-anon-regions-return-type-is-anon.rs:16:3
|
16 | / fn foo<'a>(&self, x: &i32) -> &i32 {
17 | | x
18 | | }
| |___^
| ^ ...but data from `x` is returned here
error: aborting due to previous error

View file

@ -1,23 +1,12 @@
error[E0312]: lifetime of reference outlives lifetime of borrowed content...
error[E0623]: lifetime mismatch
--> $DIR/ex3-both-anon-regions-self-is-anon.rs:17:19
|
16 | fn foo<'a>(&self, x: &Foo) -> &Foo {
| ---- ----
| |
| this parameter and the return type are declared with different lifetimes...
17 | if true { x } else { self }
| ^
|
note: ...the reference is valid for the anonymous lifetime #1 defined on the method body at 16:5...
--> $DIR/ex3-both-anon-regions-self-is-anon.rs:16:5
|
16 | / fn foo<'a>(&self, x: &Foo) -> &Foo {
17 | | if true { x } else { self }
18 | | }
| |_____^
note: ...but the borrowed content is only valid for the anonymous lifetime #2 defined on the method body at 16:5
--> $DIR/ex3-both-anon-regions-self-is-anon.rs:16:5
|
16 | / fn foo<'a>(&self, x: &Foo) -> &Foo {
17 | | if true { x } else { self }
18 | | }
| |_____^
| ^ ...but data from `x` is returned here
error: aborting due to previous error