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

Make Gc<T> require bounds T: Send + Sync #44

Merged
merged 1 commit into from
Feb 9, 2021

Conversation

jacob-hughes
Copy link
Contributor

The collector finalizes objects off the main thread. This means that if
any fields are accessed via T's drop method, it must be done in a
thread-safe way.

A common pattern is to allow the Gc<T> to hold trait objects. For this
change to work, TO methods need a where Self: Send + Sync clause for
the compiler to guarantee object safety. Such clauses are deprecated in
rustc because they can be used to create UB when binding to user traits
with methods. However, at the time of this commit it's the only known
way to add additional bounds for auto traits. From my understanding this
usage is considered safe until a better situation arises 1.

The collector finalizes objects off the main thread. This means that if
any fields are accessed via T's drop method, it must be done in a
thread-safe way.

A common pattern is to allow the `Gc<T>` to hold trait objects. For this
change to work, TO methods need a `where Self: Send + Sync` clause for
the compiler to guarantee object safety. Such clauses are deprecated in
rustc because they can be used to create UB when binding to user traits
with methods. However, at the time of this commit it's the only known
way to add additional bounds for auto traits. From my understanding this
usage is considered safe until a better situation arises [1].

[1]: rust-lang/rust#50781 (comment)
@ltratt
Copy link
Member

ltratt commented Feb 9, 2021

bors r+

bors bot added a commit that referenced this pull request Feb 9, 2021
44: Make `Gc<T>` require bounds `T: Send + Sync` r=ltratt a=jacob-hughes

The collector finalizes objects off the main thread. This means that if
any fields are accessed via T's drop method, it must be done in a
thread-safe way.

A common pattern is to allow the `Gc<T>` to hold trait objects. For this
change to work, TO methods need a `where Self: Send + Sync` clause for
the compiler to guarantee object safety. Such clauses are deprecated in
rustc because they can be used to create UB when binding to user traits
with methods. However, at the time of this commit it's the only known
way to add additional bounds for auto traits. From my understanding this
usage is considered safe until a better situation arises [1].

[1]: rust-lang/rust#50781 (comment)

Co-authored-by: Jake Hughes <jh@jakehughes.uk>
@bors
Copy link
Contributor

bors bot commented Feb 9, 2021

Timed out.

@jacob-hughes
Copy link
Contributor Author

I think this just needs another kick

@ltratt
Copy link
Member

ltratt commented Feb 9, 2021

bors r+

@bors
Copy link
Contributor

bors bot commented Feb 9, 2021

Build succeeded:

@bors bors bot merged commit aa5913a into softdevteam:master Feb 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants