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

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



   Compiling playground v0.0.1 (/playground)
error[E0689]: can't call method `copy` on ambiguous numeric type `{integer}`
 --> src/
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;.


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;

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.