-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #44516 - gaurikholkar:fns, r=arielb1
Extend E0623 for fn items This fixes #44516 The below example now gives ``` error[E0623]: lifetime mismatch --> gg.rs:3:10 | 2 | fn foo(x:fn(&u8, &u8), y: Vec<&u8>, z: &u8) { | --- --- these two types are declared with different lifetimes... 3 | y.push(z); | ^ ...but data from `z` flows into `y` here error: aborting due to previous error ``` r? @nikomatsakis cc @arielb1
- Loading branch information
Showing
11 changed files
with
151 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
|
||
fn foo(x: fn(&u8, &u8), y: Vec<&u8>, z: &u8) { | ||
// Debruijn 1 1 1 1 | ||
// Anon-Index 0 1 0 1 | ||
// ------ | ||
// debruijn indices are shifted by 1 in here | ||
y.push(z); // index will be zero or one | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
src/test/ui/lifetime-errors/ex3-both-anon-regions-4.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
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 declared with different lifetimes... | ||
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 declared with different lifetimes... | ||
12 | z.push((x,y)); | ||
| ^ ...but data flows into `z` here | ||
|
||
error: aborting due to 2 previous errors | ||
|
19 changes: 19 additions & 0 deletions
19
src/test/ui/lifetime-errors/ex3-both-anon-regions-both-are-structs-4.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() {} |
12 changes: 12 additions & 0 deletions
12
src/test/ui/lifetime-errors/ex3-both-anon-regions-both-are-structs-4.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
error[E0623]: lifetime mismatch | ||
--> $DIR/ex3-both-anon-regions-both-are-structs-4.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 | ||
|
17 changes: 17 additions & 0 deletions
17
src/test/ui/lifetime-errors/ex3-both-anon-regions-one-is-struct-4.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() { } |
10 changes: 10 additions & 0 deletions
10
src/test/ui/lifetime-errors/ex3-both-anon-regions-one-is-struct-4.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
error[E0623]: lifetime mismatch | ||
--> $DIR/ex3-both-anon-regions-one-is-struct-4.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 | ||
|
14 changes: 14 additions & 0 deletions
14
src/test/ui/lifetime-errors/ex3-both-anon-regions-using-fn-items.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// 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. | ||
fn foo(x:fn(&u8, &u8), y: Vec<&u8>, z: &u8) { | ||
y.push(z); | ||
} | ||
|
||
fn main() { } |
10 changes: 10 additions & 0 deletions
10
src/test/ui/lifetime-errors/ex3-both-anon-regions-using-fn-items.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
error[E0623]: lifetime mismatch | ||
--> $DIR/ex3-both-anon-regions-using-fn-items.rs:11:10 | ||
| | ||
10 | fn foo(x:fn(&u8, &u8), y: Vec<&u8>, z: &u8) { | ||
| --- --- these two types are declared with different lifetimes... | ||
11 | y.push(z); | ||
| ^ ...but data from `z` flows into `y` here | ||
|
||
error: aborting due to previous error | ||
|
14 changes: 14 additions & 0 deletions
14
src/test/ui/lifetime-errors/ex3-both-anon-regions-using-trait-objects.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// 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. | ||
fn foo(x:Box<Fn(&u8, &u8)> , y: Vec<&u8>, z: &u8) { | ||
y.push(z); | ||
} | ||
|
||
fn main() { } |
10 changes: 10 additions & 0 deletions
10
src/test/ui/lifetime-errors/ex3-both-anon-regions-using-trait-objects.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
error[E0623]: lifetime mismatch | ||
--> $DIR/ex3-both-anon-regions-using-trait-objects.rs:11:10 | ||
| | ||
10 | fn foo(x:Box<Fn(&u8, &u8)> , y: Vec<&u8>, z: &u8) { | ||
| --- --- these two types are declared with different lifetimes... | ||
11 | y.push(z); | ||
| ^ ...but data from `z` flows into `y` here | ||
|
||
error: aborting due to previous error | ||
|