-
Notifications
You must be signed in to change notification settings - Fork 352
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
exclude mutable references to !Unpin types from uniqueness guarantees
- Loading branch information
Showing
2 changed files
with
49 additions
and
3 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
34 changes: 34 additions & 0 deletions
34
tests/run-pass/stacked-borrows/generators-self-referential.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,34 @@ | ||
// See https://github.com/rust-lang/unsafe-code-guidelines/issues/148: | ||
// this fails when Stacked Borrows is strictly applied even to `!Unpin` types. | ||
#![feature(generators, generator_trait)] | ||
|
||
use std::{ | ||
ops::{Generator, GeneratorState}, | ||
pin::Pin, | ||
}; | ||
|
||
fn firstn() -> impl Generator<Yield = u64, Return = ()> { | ||
static move || { | ||
let mut num = 0; | ||
let num = &mut num; | ||
|
||
yield *num; | ||
*num += 1; //~ ERROR: borrow stack | ||
|
||
yield *num; | ||
*num += 1; | ||
|
||
yield *num; | ||
*num += 1; | ||
} | ||
} | ||
|
||
fn main() { | ||
let mut generator_iterator = firstn(); | ||
let mut pin = unsafe { Pin::new_unchecked(&mut generator_iterator) }; | ||
let mut sum = 0; | ||
while let GeneratorState::Yielded(x) = pin.as_mut().resume(()) { | ||
sum += x; | ||
} | ||
assert_eq!(sum, 3); | ||
} |