fn main() {
let mut s = String::from("hello");
let mut f = Foo(&mut s);
let r = &mut f;
run(r);
println!("{:?}", f); // cannot borrow `f` as immutable ...
// but println!("{}", s); works fine
}
#[derive(Debug)]
struct Foo<'a>(&'a mut String);
fn run<'a, 'b: 'a>(_: &'b mut Foo<'a>) {}
It's not a real problem, is just something I found and I'm curious about
Why can't I use f
after passing its mutable reference to run
?
I know 'b: 'a
is causing the error, and it probably never makes sense for the reference to live longer than the bounds of the parameter, but what is happening?
And why I can use s
if theoretically it is borrowed by f that is borrowed by something?