forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
These are some samples that I have been focusing on improving over time. In this PR, I mainly want to stem the bleeding where we in some cases we show an error that gives you no possible way to divine the problem.
- Loading branch information
1 parent
dc0bb3f
commit 5167ac8
Showing
14 changed files
with
243 additions
and
0 deletions.
There are no files selected for viewing
15 changes: 15 additions & 0 deletions
15
src/test/ui/lifetime-errors/ex1-return-one-existing-name-if-else.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,15 @@ | ||
// Copyright 2016 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<'a>(x: &'a i32, y: &i32) -> &'a i32 { | ||
if x > y { x } else { y } | ||
} | ||
|
||
fn main() { } |
25 changes: 25 additions & 0 deletions
25
src/test/ui/lifetime-errors/ex1-return-one-existing-name-if-else.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,25 @@ | ||
error[E0312]: lifetime of reference outlives lifetime of borrowed content... | ||
--> $DIR/ex1-return-one-existing-name-if-else.rs:12:27 | ||
| | ||
12 | if x > y { x } else { y } | ||
| ^ | ||
| | ||
note: ...the reference is valid for the lifetime 'a as defined on the body at 11:43... | ||
--> $DIR/ex1-return-one-existing-name-if-else.rs:11:44 | ||
| | ||
11 | fn foo<'a>(x: &'a i32, y: &i32) -> &'a i32 { | ||
| ____________________________________________^ starting here... | ||
12 | | if x > y { x } else { y } | ||
13 | | } | ||
| |_^ ...ending here | ||
note: ...but the borrowed content is only valid for the anonymous lifetime #1 defined on the body at 11:43 | ||
--> $DIR/ex1-return-one-existing-name-if-else.rs:11:44 | ||
| | ||
11 | fn foo<'a>(x: &'a i32, y: &i32) -> &'a i32 { | ||
| ____________________________________________^ starting here... | ||
12 | | if x > y { x } else { y } | ||
13 | | } | ||
| |_^ ...ending here | ||
|
||
error: aborting due to previous error | ||
|
15 changes: 15 additions & 0 deletions
15
src/test/ui/lifetime-errors/ex1b-return-no-names-if-else.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,15 @@ | ||
// Copyright 2016 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: &i32, y: &i32) -> &i32 { | ||
if x > y { x } else { y } | ||
} | ||
|
||
fn main() { } |
10 changes: 10 additions & 0 deletions
10
src/test/ui/lifetime-errors/ex1b-return-no-names-if-else.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[E0106]: missing lifetime specifier | ||
--> $DIR/ex1b-return-no-names-if-else.rs:11:29 | ||
| | ||
11 | fn foo(x: &i32, y: &i32) -> &i32 { | ||
| ^ expected lifetime parameter | ||
| | ||
= help: this function's return type contains a borrowed value, but the signature does not say whether it is borrowed from `x` or `y` | ||
|
||
error: aborting due to previous error | ||
|
19 changes: 19 additions & 0 deletions
19
src/test/ui/lifetime-errors/ex2a-push-one-existing-name.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 2016 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, T: 'a> { | ||
data: &'a T | ||
} | ||
|
||
fn foo<'a>(x: &mut Vec<Ref<'a, i32>>, y: Ref<i32>) { | ||
x.push(y); | ||
} | ||
|
||
fn main() { } |
27 changes: 27 additions & 0 deletions
27
src/test/ui/lifetime-errors/ex2a-push-one-existing-name.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,27 @@ | ||
error[E0308]: mismatched types | ||
--> $DIR/ex2a-push-one-existing-name.rs:16:12 | ||
| | ||
16 | x.push(y); | ||
| ^ lifetime mismatch | ||
| | ||
= note: expected type `Ref<'a, i32>` | ||
found type `Ref<'_, i32>` | ||
note: the anonymous lifetime #2 defined on the body at 15:51... | ||
--> $DIR/ex2a-push-one-existing-name.rs:15:52 | ||
| | ||
15 | fn foo<'a>(x: &mut Vec<Ref<'a, i32>>, y: Ref<i32>) { | ||
| ____________________________________________________^ starting here... | ||
16 | | x.push(y); | ||
17 | | } | ||
| |_^ ...ending here | ||
note: ...does not necessarily outlive the lifetime 'a as defined on the body at 15:51 | ||
--> $DIR/ex2a-push-one-existing-name.rs:15:52 | ||
| | ||
15 | fn foo<'a>(x: &mut Vec<Ref<'a, i32>>, y: Ref<i32>) { | ||
| ____________________________________________________^ starting here... | ||
16 | | x.push(y); | ||
17 | | } | ||
| |_^ ...ending here | ||
|
||
error: aborting due to previous error | ||
|
19 changes: 19 additions & 0 deletions
19
src/test/ui/lifetime-errors/ex2b-push-no-existing-names.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 2016 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, T: 'a> { | ||
data: &'a T | ||
} | ||
|
||
fn foo(x: &mut Vec<Ref<i32>>, y: Ref<i32>) { | ||
x.push(y); | ||
} | ||
|
||
fn main() { } |
27 changes: 27 additions & 0 deletions
27
src/test/ui/lifetime-errors/ex2b-push-no-existing-names.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,27 @@ | ||
error[E0308]: mismatched types | ||
--> $DIR/ex2b-push-no-existing-names.rs:16:12 | ||
| | ||
16 | x.push(y); | ||
| ^ lifetime mismatch | ||
| | ||
= note: expected type `Ref<'_, i32>` | ||
found type `Ref<'_, i32>` | ||
note: the anonymous lifetime #3 defined on the body at 15:43... | ||
--> $DIR/ex2b-push-no-existing-names.rs:15:44 | ||
| | ||
15 | fn foo(x: &mut Vec<Ref<i32>>, y: Ref<i32>) { | ||
| ____________________________________________^ starting here... | ||
16 | | x.push(y); | ||
17 | | } | ||
| |_^ ...ending here | ||
note: ...does not necessarily outlive the anonymous lifetime #2 defined on the body at 15:43 | ||
--> $DIR/ex2b-push-no-existing-names.rs:15:44 | ||
| | ||
15 | fn foo(x: &mut Vec<Ref<i32>>, y: Ref<i32>) { | ||
| ____________________________________________^ starting here... | ||
16 | | x.push(y); | ||
17 | | } | ||
| |_^ ...ending here | ||
|
||
error: aborting due to previous error | ||
|
20 changes: 20 additions & 0 deletions
20
src/test/ui/lifetime-errors/ex2c-push-inference-variable.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,20 @@ | ||
// Copyright 2016 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, T: 'a> { | ||
data: &'a T | ||
} | ||
|
||
fn foo<'a, 'b, 'c>(x: &'a mut Vec<Ref<'b, i32>>, y: Ref<'c, i32>) { | ||
let z = Ref { data: y.data }; | ||
x.push(z); | ||
} | ||
|
||
fn main() { } |
8 changes: 8 additions & 0 deletions
8
src/test/ui/lifetime-errors/ex2c-push-inference-variable.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,8 @@ | ||
error[E0495]: cannot infer an appropriate lifetime for lifetime parameter `'a` due to conflicting requirements | ||
--> $DIR/ex2c-push-inference-variable.rs:16:13 | ||
| | ||
16 | let z = Ref { data: y.data }; | ||
| ^^^ | ||
|
||
error: aborting due to previous error | ||
|
21 changes: 21 additions & 0 deletions
21
src/test/ui/lifetime-errors/ex2d-push-inference-variable-2.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,21 @@ | ||
// Copyright 2016 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, T: 'a> { | ||
data: &'a T | ||
} | ||
|
||
fn foo<'a, 'b, 'c>(x: &'a mut Vec<Ref<'b, i32>>, y: Ref<'c, i32>) { | ||
let a: &mut Vec<Ref<i32>> = x; | ||
let b = Ref { data: y.data }; | ||
a.push(b); | ||
} | ||
|
||
fn main() { } |
8 changes: 8 additions & 0 deletions
8
src/test/ui/lifetime-errors/ex2d-push-inference-variable-2.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,8 @@ | ||
error[E0495]: cannot infer an appropriate lifetime for lifetime parameter `'a` due to conflicting requirements | ||
--> $DIR/ex2d-push-inference-variable-2.rs:17:13 | ||
| | ||
17 | let b = Ref { data: y.data }; | ||
| ^^^ | ||
|
||
error: aborting due to previous error | ||
|
21 changes: 21 additions & 0 deletions
21
src/test/ui/lifetime-errors/ex2e-push-inference-variable-3.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,21 @@ | ||
// Copyright 2016 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, T: 'a> { | ||
data: &'a T | ||
} | ||
|
||
fn foo<'a, 'b, 'c>(x: &'a mut Vec<Ref<'b, i32>>, y: Ref<'c, i32>) { | ||
let a: &mut Vec<Ref<i32>> = x; | ||
let b = Ref { data: y.data }; | ||
Vec::push(a, b); | ||
} | ||
|
||
fn main() { } |
8 changes: 8 additions & 0 deletions
8
src/test/ui/lifetime-errors/ex2e-push-inference-variable-3.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,8 @@ | ||
error[E0495]: cannot infer an appropriate lifetime for lifetime parameter `'a` due to conflicting requirements | ||
--> $DIR/ex2e-push-inference-variable-3.rs:17:13 | ||
| | ||
17 | let b = Ref { data: y.data }; | ||
| ^^^ | ||
|
||
error: aborting due to previous error | ||
|