Hacker News new | ask | show | jobs
by millstone 2446 days ago

    let x = String::from("abc");
    std::mem::drop(&x);
    std::mem::drop(&x);
    std::mem::drop(&x);
    std::mem::drop(&x);
1 comments

FWIW, that won't compile because std::mem::drop requires ownership of the object being passed; your code is trying to pass a reference instead.
This code compiles just fine. It doesn't do anything since immutable references are Copy, and so dropping them doesn't do anything.

https://play.rust-lang.org/?version=stable&mode=debug&editio...

Oh right, I forgot about the interaction with generics in this case. Semantically, I suppose it's creating and dropping a reference 4 times.
This should compile, &T is Copy and so it will not really do anything, but it will still compile.

On my phone so I can’t triple check, but there’s no bound on T, you can pass in any type.