You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fnfoo(){letmut x = 5;// type: i32{let y = &x;// type: &i32//x = 4; // Error - x has been borrowedprintln!("{}", x);// Ok - x can be read}
x = 4;// OK - y no longer exists}
But when I tested this, uncommenting the x = 4 line, it built and ran just fine. The same was true for the next example where y = &mut x: when I uncommented the two releavant lines it still ran.
I think either this is a bad example of the concept you were trying to communicate (borrowed values becoming temporarily immutable), or the concept has been changed over time and the material should be updated.
HOWEVER I am just learning Rust, so I may be utterly mistaken :)
The text was updated successfully, but these errors were encountered:
Huh, presumably due to non-lexical lifetimes. I think changing println!("{}", x); to println!("{}", y); should fix this, although maybe we should add rather than replace so that the comment on that line still makes sense
The example given is:
But when I tested this, uncommenting the
x = 4
line, it built and ran just fine. The same was true for the next example wherey = &mut x
: when I uncommented the two releavant lines it still ran.I think either this is a bad example of the concept you were trying to communicate (borrowed values becoming temporarily immutable), or the concept has been changed over time and the material should be updated.
HOWEVER I am just learning Rust, so I may be utterly mistaken :)
The text was updated successfully, but these errors were encountered: