Can't call method `copy` on ambiguous numeric type `{integer}`

fn main() {
    let a=1;
    let b=a.copy();
}

(Playground)

Errors:

   Compiling playground v0.0.1 (/playground)
error[E0689]: can't call method `copy` on ambiguous numeric type `{integer}`
 --> src/main.rs:3:13
  |
3 |     let b=a.copy();
  |             ^^^^
  |
help: you must specify a type for this binding, like `i32`
  |
2 |     let a: i32=1;
  |         ~~~~~~

For more information about this error, try `rustc --explain E0689`.
error: could not compile `playground` due to previous error

What is the question?

I'm not entirely sure why the error message looks the way it looks, but integer types in Rust simply don't have any method called copy. You can copy them implicitly by just writing let b = a;.

3 Likes

There is a method called .clone(), but no method named .copy(). The Copy trait works by changing how moves work - it doesn't work by introducing a new method.

Here's how to make a copy of a:

fn main() {
    let a = 1;
    let b = a;
}
3 Likes

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.