-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Alexander Regueiro
committed
Mar 24, 2019
1 parent
3be9417
commit 74a623f
Showing
6 changed files
with
56 additions
and
9 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
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
2 changes: 1 addition & 1 deletion
2
src/test/ui/impl-trait/region-escape-via-bound-contravariant.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
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,29 @@ | ||
// compile-fail | ||
|
||
// See https://github.com/rust-lang/rust/pull/57870#issuecomment-457333709 for more details. | ||
|
||
trait Swap: Sized { | ||
fn swap(self, other: Self); | ||
} | ||
|
||
impl<T> Swap for &mut T { | ||
fn swap(self, other: Self) { | ||
std::mem::swap(self, other); | ||
} | ||
} | ||
|
||
// The hidden relifetimegion `'b` should not be allowed to escape this function, since it may not | ||
// outlive '`a`, in which case we have a dangling reference. | ||
fn hide<'a, 'b, T: 'static>(x: &'a mut &'b T) -> impl Swap + 'a { | ||
//~^ lifetime mismatch [E0623] | ||
x | ||
} | ||
|
||
fn dangle() -> &'static [i32; 3] { | ||
let mut res = &[4, 5, 6]; | ||
let x = [1, 2, 3]; | ||
hide(&mut res).swap(hide(&mut &x)); | ||
res | ||
} | ||
|
||
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,12 @@ | ||
error[E0623]: lifetime mismatch | ||
--> $DIR/region-escape-via-swap.rs:17:50 | ||
| | ||
LL | fn hide<'a, 'b, T: 'static>(x: &'a mut &'b T) -> impl Swap + 'a { | ||
| ----- ^^^^^^^^^^^^^^ | ||
| | | | ||
| | ...but data from `x` is returned here | ||
| this parameter and the return type are declared with different lifetimes... | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0623`. |