1 #[derive(Copy, Clone, Debug, Eq, PartialEq)]
2 pub struct Foo {
3 }
4 
5 impl Foo {
get(&self) -> Option<&Result<String, String>>6     fn get(&self) -> Option<&Result<String, String>> {
7         None
8     }
9 
mutate(&mut self)10     fn mutate(&mut self) { }
11 }
12 
main()13 fn main() {
14     let mut foo = Foo { };
15 
16     // foo.get() returns type Option<&Result<String, String>>, so
17     // using `string` keeps borrow of `foo` alive. Hence calling
18     // `foo.mutate()` should be an error.
19     while let Some(Ok(string)) = foo.get() {
20         foo.mutate();
21         //~^ ERROR cannot borrow `foo` as mutable
22         println!("foo={:?}", *string);
23     }
24 }
25