Info
This post is auto-generated from RSS feed The Rust Programming Language Forum - Latest topics. Source: Why & how this error came
#![allow(warnings)]
fn main() {
let mut z = 4;
let mut x = & mut z;
//-----------------------------
let mut s = 444;
let mut d = &mut s;
//------------------------------
let mut f: &mut & mut u32;
f = &mut x;
f = &mut d;
println!("{}",f);
//-------------------------------
let mut zz = 4444;
let mut ss = 4444;
d= & mut zz;
x = & mut ss;
println!("{}",zz);
println!("{}",ss);
println!("{}",d);
}
Errors:
Compiling playground v0.0.1 (/playground)
error[E0502]: cannot borrow `zz` as immutable because it is also borrowed as mutable
--> src/main.rs:35:15
|
31 | d= & mut zz;
| -------- mutable borrow occurs here
...
35 | println!("{}",zz);
| ^^ immutable borrow occurs here
...
38 | println!("{}",d);
| - mutable borrow later used here
|
= note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0502]: cannot borrow `ss` as immutable because it is also borrowed as mutable
--> src/main.rs:36:15
|
32 | x = & mut ss;
| -------- mutable borrow occurs here
...
36 | println!("{}",ss);
| ^^ immutable borrow occurs here
37 |
38 | println!("{}",d);
| - mutable borrow later used here
|
= note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)
For more information about this error, try `rustc --explain E0502`.
error: could not compile `playground` (bin "playground") due to 2 previous errors
1 post - 1 participant
🏷️ Rust_feed