Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
kjh618 opened this issue Apr 6, 2024 · 2 comments
Closed
Assignees
Labels
lecture question/discussion related to lectures question Further information is requested

Comments

@kjh618
Copy link

kjh618 commented Apr 6, 2024

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?

@kjh618 kjh618 added the question Further information is requested label Apr 6, 2024
@Lee-Janggun
Copy link
Member

Lee-Janggun commented Apr 6, 2024

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.

@kjh618
Copy link
Author

kjh618 commented Apr 8, 2024

Thanks for the answer!

@kjh618 kjh618 closed this as completed Apr 8, 2024
@Lee-Janggun Lee-Janggun added the lecture question/discussion related to lectures label Apr 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lecture question/discussion related to lectures question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants