2
let a = "abcd";
let b = a;
let c = a;
let x = String::from("abcd");
let y = x;
let z = x;

I get the error:

error[E0382]: use of moved value: `x`
 --> src/lib.rs:7:13
  |
5 |     let x = String::from("abcd");
  |         - move occurs because `x` has type `String`, which does not implement the `Copy` trait
6 |     let y = x;
  |             - value moved here
7 |     let z = x;
  |             ^ value used here after move

Am I not supposed to get same error for a?

Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366
r1thedev
  • 21
  • 3

0 Answers0