Skip to content

Added a ?Sized constraint to T in Mutex<T> #47

New issue

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

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

Already on GitHub? # to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

za-songguo
Copy link

Added a ?Sized constraint to T in Mutex<T>, allowing it to work with unsized types, such as trait objects.

@za-songguo za-songguo requested a review from a team as a code owner August 17, 2024 13:22
@@ -71,7 +71,7 @@ use core::cell::{Ref, RefCell, RefMut, UnsafeCell};
/// [`std::sync::Mutex`]: https://doc.rust-lang.org/std/sync/struct.Mutex.html
/// [interior mutability]: https://doc.rust-lang.org/reference/interior-mutability.html
#[derive(Debug)]
pub struct Mutex<T> {
pub struct Mutex<T: ?Sized> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you should add ?Sized in all the impl blocks too, like impl<T: ?Sized> Mutex<T>

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you are right.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But the compiler throws errors because the impl of UnsafeCell<T> doesn't mark T as ?Sized.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants