forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1005970
commit f0e385d
Showing
11 changed files
with
143 additions
and
7 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
16 changes: 16 additions & 0 deletions
16
tests/ui/borrowck/alias-liveness/higher-ranked-outlives-for-capture.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,16 @@ | ||
// known-bug: #42940 | ||
|
||
trait Captures<'a> {} | ||
impl<T> Captures<'_> for T {} | ||
|
||
trait Outlives<'a>: 'a {} | ||
impl<'a, T: 'a> Outlives<'a> for T {} | ||
|
||
// Test that we treat `for<'a> Opaque: 'a` as `Opaque: 'static` | ||
fn test<'o>(v: &'o Vec<i32>) -> impl Captures<'o> + for<'a> Outlives<'a> {} | ||
|
||
fn statik() -> impl Sized { | ||
test(&vec![]) | ||
} | ||
|
||
fn main() {} |
16 changes: 16 additions & 0 deletions
16
tests/ui/borrowck/alias-liveness/higher-ranked-outlives-for-capture.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,16 @@ | ||
error[E0716]: temporary value dropped while borrowed | ||
--> $DIR/higher-ranked-outlives-for-capture.rs:13:11 | ||
| | ||
LL | test(&vec![]) | ||
| ------^^^^^^- | ||
| | | | ||
| | creates a temporary value which is freed while still in use | ||
| argument requires that borrow lasts for `'static` | ||
LL | } | ||
| - temporary value is freed at the end of this statement | ||
| | ||
= note: this error originates in the macro `vec` (in Nightly builds, run with -Z macro-backtrace for more info) | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0716`. |
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,16 @@ | ||
// check-pass | ||
|
||
trait Captures<'a> {} | ||
impl<T> Captures<'_> for T {} | ||
|
||
trait Outlives<'a>: 'a {} | ||
impl<'a, T: 'a> Outlives<'a> for T {} | ||
|
||
// Test that we treat `for<'a> Opaque: 'a` as `Opaque: 'static` | ||
fn test<'o>(v: &'o Vec<i32>) -> impl Captures<'o> + for<'a> Outlives<'a> {} | ||
|
||
fn opaque_doesnt_use_temporary() { | ||
let a = test(&vec![]); | ||
} | ||
|
||
fn main() {} |
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 @@ | ||
// check-pass | ||
|
||
// Check that opaques capturing early and late-bound vars correctly mark | ||
// regions required to be live using the item bounds. | ||
|
||
trait Captures<'a> {} | ||
impl<T> Captures<'_> for T {} | ||
|
||
fn captures_temp_late<'a>(x: &'a Vec<i32>) -> impl Sized + Captures<'a> + 'static {} | ||
fn captures_temp_early<'a: 'a>(x: &'a Vec<i32>) -> impl Sized + Captures<'a> + 'static {} | ||
|
||
fn test() { | ||
let x = captures_temp_early(&vec![]); | ||
let y = captures_temp_late(&vec![]); | ||
} | ||
|
||
fn main() {} |
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 @@ | ||
// known-bug: #42940 | ||
|
||
trait Trait {} | ||
impl Trait for () {} | ||
|
||
fn foo<'a>(s: &'a str) -> impl Trait + 'static { | ||
bar(s) | ||
} | ||
|
||
fn bar<P: AsRef<str>>(s: P) -> impl Trait + 'static { | ||
() | ||
} | ||
|
||
fn main() {} |
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,13 @@ | ||
error[E0700]: hidden type for `impl Trait + 'static` captures lifetime that does not appear in bounds | ||
--> $DIR/opaque-type-param.rs:7:5 | ||
| | ||
LL | fn foo<'a>(s: &'a str) -> impl Trait + 'static { | ||
| -- -------------------- opaque type defined here | ||
| | | ||
| hidden type `impl Trait + 'static` captures the lifetime `'a` as defined here | ||
LL | bar(s) | ||
| ^^^^^^ | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0700`. |
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
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
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
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 @@ | ||
// check-pass | ||
// issue: 116794 | ||
|
||
// Uncaptured lifetimes should not be required to be live. | ||
|
||
struct Invariant<T>(*mut T); | ||
|
||
fn opaque<'a: 'a>(_: &'a str) -> Invariant<impl Sized> { | ||
Invariant(&mut ()) | ||
} | ||
|
||
fn main() { | ||
let x = opaque(&String::new()); | ||
drop(x); | ||
} |