-
-
Save jpastuszek/559bc637c2715248bac62822a710ad36 to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
This file contains hidden or 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
// https://stackoverflow.com/questions/50519147/double-mutable-borrow-error-in-a-loop-happens-even-with-nll-on | |
// https://github.com/rust-lang/rust/issues/54663 | |
// This will complie with polonius: rustc +nightly -Zpolonius --edition=2018 /tmp/p.rs | |
struct Foo(u8); | |
impl Foo { | |
fn even<'i>(&'i mut self) -> &'i u8 { | |
loop { | |
match self.next() { | |
Some(even) => return even, | |
None => continue, | |
} | |
} | |
} | |
fn next<'i>(&'i mut self) -> Option<&'i u8> { | |
self.0 += 1; | |
if self.0 % 2 == 0 { | |
Some(&self.0) | |
} else { | |
None | |
} | |
} | |
} | |
fn main() { | |
let mut foo = Foo(1); | |
println!("{:?}", foo.next()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment