News for hackers. Stuff that matters.
Re:My favorite Rust function by millstone on Saturday October 12, 2019 @09:09PM (#21237546)

    let x = String::from("abc");
    std::mem::drop(&x);
    std::mem::drop(&x);
    std::mem::drop(&x);
    std::mem::drop(&x);
Re:My favorite Rust function by hathawsh on Saturday October 12, 2019 @10:20PM (#21237855)
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.
Re:My favorite Rust function by lpghatguy on Saturday October 12, 2019 @10:25PM (#21237878)
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...

Re:My favorite Rust function by hathawsh on Saturday October 12, 2019 @10:31PM (#21237912)
Oh right, I forgot about the interaction with generics in this case. Semantically, I suppose it's creating and dropping a reference 4 times.
Re:My favorite Rust function by steveklabnik on Saturday October 12, 2019 @10:27PM (#21237893)
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.