This answer option is marked as incorrect.
let b = Box::new(0); let b2 = b; println!("{}", b); move_a_box(b2);
So, I'm getting this output in the Rust Playground(https://play.rust-lang.org/?version=stable&mode=debug&edition=2024&gist=4fa02a56f1d3102a34269c15af4b025b):
Errors
Exited with status 101
Standard Error
Compiling playground v0.0.1 (/playground)
error[E0382]: borrow of moved value: b
--> src/main.rs:5:20
|
3 | let b = Box::new(0);
| - move occurs because b has type Box<i32>, which does not implement the Copy trait
4 | let b2 = b;
| - value moved here
5 | println!("{}", b);
| ^ value borrowed here after move
|
help: consider cloning the value if the performance cost is acceptable
|
4 | let b2 = b.clone();
| ++++++++
warning: unused variable: b
--> src/main.rs:10:15
|
10 | fn move_a_box(b: Box) {
| ^ help: if this is intentional, prefix it with an underscore: _b
|
= note: #[warn(unused_variables)] (part of #[warn(unused)]) on by default
For more information about this error, try rustc --explain E0382.
warning: playground (bin "playground") generated 1 warning
error: could not compile playground (bin "playground") due to 1 previous error; 1 warning emitted
This answer option is marked as incorrect.
let b = Box::new(0); let b2 = b; println!("{}", b); move_a_box(b2);So, I'm getting this output in the Rust Playground(https://play.rust-lang.org/?version=stable&mode=debug&edition=2024&gist=4fa02a56f1d3102a34269c15af4b025b):
Errors
Exited with status 101
Standard Error
Compiling playground v0.0.1 (/playground)
error[E0382]: borrow of moved value:
b--> src/main.rs:5:20
|
3 | let b = Box::new(0);
| - move occurs because
bhas typeBox<i32>, which does not implement theCopytrait4 | let b2 = b;
| - value moved here
5 | println!("{}", b);
| ^ value borrowed here after move
|
help: consider cloning the value if the performance cost is acceptable
|
4 | let b2 = b.clone();
| ++++++++
warning: unused variable:
b--> src/main.rs:10:15
|
10 | fn move_a_box(b: Box) {
| ^ help: if this is intentional, prefix it with an underscore:
_b|
= note:
#[warn(unused_variables)](part of#[warn(unused)]) on by defaultFor more information about this error, try
rustc --explain E0382.warning:
playground(bin "playground") generated 1 warningerror: could not compile
playground(bin "playground") due to 1 previous error; 1 warning emitted