kaist-cp/cs431

[Question] Exam problem "a variable can be `drop()`ed using its `&mut` reference"

Closed this issue · 2 comments

In the 2023 fall midterm exam, there is a true/false question "In safe Rust, a variable can be drop()ed using its &mut reference."

I think it's possible to drop the value behind &mut by using mem::replace. (-> True)
But the question asks if a variable can be dropped using &mut, which makes me think it's just asking about the signatue of drop, which takes T. (-> False)

Which interpretation is correct in this case?

For that exam, the intention was the latter. The point is to have a proper understanding of &mut T v.s. T.

Also, for mem::replace(), it does require T : Default, so your statement is not unconditionally true.

Oh its not mem::take(). Still, using mem::replace() requires the user to create a value of T to replace with, which is not always possible.

Thanks for the answer!