Auto merge of #43700 - gaurikholkar:struct_lifetimes, r=nikomatsakis

Adding E0623 for structs

This is a fix to #43275

The error message is
```
+error[E0623]: lifetime mismatch
+  --> $DIR/ex3-both-anon-regions-both-are-structs.rs:15:12
+   |
+14 | fn foo(mut x: Vec<Ref>, y: Ref) {
+   |                   ---      --- these structs are declared with different lifetimes...
+15 |     x.push(y);
+   |            ^ ...but data from `y` flows into `x` here
+
+error: aborting due to previous error
```

r? @nikomatsakis
This commit is contained in:
bors 2017-08-25 12:59:04 +00:00
commit a4d11495f9
29 changed files with 624 additions and 204 deletions

View file

@ -1,25 +1,10 @@
error[E0308]: mismatched types
error[E0623]: lifetime mismatch
--> $DIR/ex2b-push-no-existing-names.rs:16:12
|
15 | fn foo(x: &mut Vec<Ref<i32>>, y: Ref<i32>) {
| -------- -------- these two types are declared with different lifetimes...
16 | x.push(y);
| ^ lifetime mismatch
|
= note: expected type `Ref<'_, _>`
found type `Ref<'_, _>`
note: the anonymous lifetime #3 defined on the function body at 15:1...
--> $DIR/ex2b-push-no-existing-names.rs:15:1
|
15 | / fn foo(x: &mut Vec<Ref<i32>>, y: Ref<i32>) {
16 | | x.push(y);
17 | | }
| |_^
note: ...does not necessarily outlive the anonymous lifetime #2 defined on the function body at 15:1
--> $DIR/ex2b-push-no-existing-names.rs:15:1
|
15 | / fn foo(x: &mut Vec<Ref<i32>>, y: Ref<i32>) {
16 | | x.push(y);
17 | | }
| |_^
| ^ ...but data from `y` flows into `x` here
error: aborting due to previous error

View file

@ -2,7 +2,7 @@ error[E0623]: lifetime mismatch
--> $DIR/ex3-both-anon-regions-2.rs:12:9
|
11 | fn foo((v, w): (&u8, &u8), x: &u8) {
| --- --- these references are not declared with the same lifetime...
| --- --- these two types are declared with different lifetimes...
12 | v = x;
| ^ ...but data from `x` flows here

View file

@ -8,8 +8,9 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
fn foo((v, w): (&u8, &u8), (x, y): (&u8, &u8)) {
v = x;
fn foo(z: &mut Vec<(&u8,&u8)>, (x, y): (&u8, &u8)) {
z.push((x,y));
}
fn main() { }

View file

@ -1,10 +1,18 @@
error[E0623]: lifetime mismatch
--> $DIR/ex3-both-anon-regions-3.rs:12:9
--> $DIR/ex3-both-anon-regions-3.rs:12:13
|
11 | fn foo((v, w): (&u8, &u8), (x, y): (&u8, &u8)) {
| --- --- these references are not declared with the same lifetime...
12 | v = x;
| ^ ...but data flows here
11 | fn foo(z: &mut Vec<(&u8,&u8)>, (x, y): (&u8, &u8)) {
| --- --- these two types are declared with different lifetimes...
12 | z.push((x,y));
| ^ ...but data flows into `z` here
error: aborting due to previous error
error[E0623]: lifetime mismatch
--> $DIR/ex3-both-anon-regions-3.rs:12:15
|
11 | fn foo(z: &mut Vec<(&u8,&u8)>, (x, y): (&u8, &u8)) {
| --- --- these two types are declared with different lifetimes...
12 | z.push((x,y));
| ^ ...but data flows into `z` here
error: aborting due to 2 previous errors

View file

@ -1,20 +0,0 @@
error[E0601]: main function not found
error[E0623]: lifetime mismatch
--> $DIR/ex3-both-anon-regions-4.rs:12:13
|
11 | fn foo(z: &mut Vec<(&u8,&u8)>, (x, y): (&u8, &u8)) {
| --- --- these references are not declared with the same lifetime...
12 | z.push((x,y));
| ^ ...but data flows into `z` here
error[E0623]: lifetime mismatch
--> $DIR/ex3-both-anon-regions-4.rs:12:15
|
11 | fn foo(z: &mut Vec<(&u8,&u8)>, (x, y): (&u8, &u8)) {
| --- --- these references are not declared with the same lifetime...
12 | z.push((x,y));
| ^ ...but data flows into `z` here
error: aborting due to 3 previous errors

View file

@ -0,0 +1,19 @@
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
struct Ref<'a, 'b> {
a: &'a u32,
b: &'b u32,
}
fn foo(mut x: Ref, y: Ref) {
x.b = y.b;
}
fn main() {}

View file

@ -0,0 +1,10 @@
error[E0623]: lifetime mismatch
--> $DIR/ex3-both-anon-regions-both-are-structs-2.rs:16:11
|
15 | fn foo(mut x: Ref, y: Ref) {
| --- --- these two types are declared with different lifetimes...
16 | x.b = y.b;
| ^^^ ...but data from `y` flows into `x` here
error: aborting due to previous error

View file

@ -0,0 +1,19 @@
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
struct Ref<'a, 'b> {
a: &'a u32,
b: &'b u32,
}
fn foo(mut x: Ref) {
x.a = x.b;
}
fn main() {}

View file

@ -0,0 +1,12 @@
error[E0623]: lifetime mismatch
--> $DIR/ex3-both-anon-regions-both-are-structs-3.rs:16:11
|
15 | fn foo(mut x: Ref) {
| ---
| |
| this type was declared with multiple lifetimes...
16 | x.a = x.b;
| ^^^ ...but data with one lifetime flows into the other here
error: aborting due to previous error

View file

@ -1,4 +1,4 @@
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
@ -7,7 +7,12 @@
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
fn foo(z: &mut Vec<(&u8,&u8)>, (x, y): (&u8, &u8)) {
z.push((x,y));
struct Ref<'a> {
x: &'a u32,
}
fn foo(mut x: Vec<Ref>, y: Ref) {
x.push(y);
}
fn main() {}

View file

@ -0,0 +1,10 @@
error[E0623]: lifetime mismatch
--> $DIR/ex3-both-anon-regions-both-are-structs.rs:15:12
|
14 | fn foo(mut x: Vec<Ref>, y: Ref) {
| --- --- these two types are declared with different lifetimes...
15 | x.push(y);
| ^ ...but data from `y` flows into `x` here
error: aborting due to previous error

View file

@ -0,0 +1,17 @@
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
struct Ref<'a, 'b> { a: &'a u32, b: &'b u32 }
fn foo(mut x: Ref, y: &u32) {
y = x.b;
}
fn main() { }

View file

@ -0,0 +1,12 @@
error[E0623]: lifetime mismatch
--> $DIR/ex3-both-anon-regions-one-is-struct-2.rs:14:9
|
13 | fn foo(mut x: Ref, y: &u32) {
| --- ----
| |
| these two types are declared with different lifetimes...
14 | y = x.b;
| ^^^ ...but data from `x` flows into `y` here
error: aborting due to previous error

View file

@ -0,0 +1,17 @@
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
struct Ref<'a, 'b> { a: &'a u32, b: &'b u32 }
fn foo(mut y: Ref, x: &u32) {
y.b = x;
}
fn main() { }

View file

@ -0,0 +1,10 @@
error[E0623]: lifetime mismatch
--> $DIR/ex3-both-anon-regions-one-is-struct-3.rs:14:11
|
13 | fn foo(mut y: Ref, x: &u32) {
| --- ---- these two types are declared with different lifetimes...
14 | y.b = x;
| ^ ...but data from `x` flows into `y` here
error: aborting due to previous error

View file

@ -0,0 +1,20 @@
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
struct Ref<'a, 'b> {
a: &'a u32,
b: &'b u32,
}
fn foo(mut x: Ref, y: &u32) {
x.b = y;
}
fn main() {}

View file

@ -0,0 +1,10 @@
error[E0623]: lifetime mismatch
--> $DIR/ex3-both-anon-regions-one-is-struct.rs:17:11
|
16 | fn foo(mut x: Ref, y: &u32) {
| --- ---- these two types are declared with different lifetimes...
17 | x.b = y;
| ^ ...but data from `y` flows into `x` here
error: aborting due to previous error

View file

@ -0,0 +1,22 @@
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
struct Foo {
field: i32
}
impl Foo {
fn foo<'a>(&self, x: &i32) -> &i32 {
x
}
}
fn main() { }

View file

@ -0,0 +1,23 @@
error[E0312]: lifetime of reference outlives lifetime of borrowed content...
--> $DIR/ex3-both-anon-regions-return-type-is-anon.rs:17:5
|
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 | | }
| |___^
error: aborting due to previous error

View file

@ -0,0 +1,22 @@
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
struct Foo {
field: i32,
}
impl Foo {
fn foo<'a>(&self, x: &Foo) -> &Foo {
if true { x } else { self }
}
}
fn main() {}

View file

@ -0,0 +1,23 @@
error[E0312]: lifetime of reference outlives lifetime of borrowed content...
--> $DIR/ex3-both-anon-regions-self-is-anon.rs:17:19
|
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 | | }
| |_____^
error: aborting due to previous error

View file

@ -0,0 +1,18 @@
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
trait Foo {
fn foo<'a>(x: &mut Vec<&u8>, y: &u8);
}
impl Foo for () {
fn foo(x: &mut Vec<&u8>, y: &u8) {
x.push(y);
}
}
fn main() {}

View file

@ -0,0 +1,10 @@
error[E0623]: lifetime mismatch
--> $DIR/ex3-both-anon-regions-using-impl-items.rs:15:16
|
14 | fn foo(x: &mut Vec<&u8>, y: &u8) {
| --- --- these two types are declared with different lifetimes...
15 | x.push(y);
| ^ ...but data from `y` flows into `x` here
error: aborting due to previous error

View file

@ -1,4 +1,4 @@
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//

View file

@ -2,7 +2,7 @@ error[E0623]: lifetime mismatch
--> $DIR/ex3-both-anon-regions.rs:12:12
|
11 | fn foo(x: &mut Vec<&u8>, y: &u8) {
| --- --- these references are not declared with the same lifetime...
| --- --- these two types are declared with different lifetimes...
12 | x.push(y);
| ^ ...but data from `y` flows into `x` here