-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Suggest using a lock for *Cell: Sync
bounds
#106944
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
fn require_sync<T: Sync>() {} | ||
//~^ NOTE required by this bound in `require_sync` | ||
//~| NOTE required by this bound in `require_sync` | ||
//~| NOTE required by this bound in `require_sync` | ||
//~| NOTE required by this bound in `require_sync` | ||
//~| NOTE required by a bound in `require_sync` | ||
//~| NOTE required by a bound in `require_sync` | ||
//~| NOTE required by a bound in `require_sync` | ||
//~| NOTE required by a bound in `require_sync` | ||
|
||
fn main() { | ||
require_sync::<std::cell::Cell<()>>(); | ||
//~^ ERROR `Cell<()>` cannot be shared between threads safely | ||
//~| NOTE `Cell<()>` cannot be shared between threads safely | ||
//~| NOTE if you want to do aliasing and mutation between multiple threads, use `std::sync::RwLock` | ||
|
||
require_sync::<std::cell::Cell<u8>>(); | ||
//~^ ERROR `Cell<u8>` cannot be shared between threads safely | ||
//~| NOTE `Cell<u8>` cannot be shared between threads safely | ||
//~| NOTE if you want to do aliasing and mutation between multiple threads, use `std::sync::RwLock` or `std::sync::atomic::AtomicU8` instead | ||
|
||
require_sync::<std::cell::Cell<i32>>(); | ||
//~^ ERROR `Cell<i32>` cannot be shared between threads safely | ||
//~| NOTE `Cell<i32>` cannot be shared between threads safely | ||
//~| NOTE if you want to do aliasing and mutation between multiple threads, use `std::sync::RwLock` or `std::sync::atomic::AtomicI32` instead | ||
|
||
require_sync::<std::cell::Cell<bool>>(); | ||
//~^ ERROR `Cell<bool>` cannot be shared between threads safely | ||
//~| NOTE `Cell<bool>` cannot be shared between threads safely | ||
//~| NOTE if you want to do aliasing and mutation between multiple threads, use `std::sync::RwLock` or `std::sync::atomic::AtomicBool` instead | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
error[E0277]: `Cell<()>` cannot be shared between threads safely | ||
--> $DIR/suggest-cell.rs:12:20 | ||
| | ||
LL | require_sync::<std::cell::Cell<()>>(); | ||
| ^^^^^^^^^^^^^^^^^^^ `Cell<()>` cannot be shared between threads safely | ||
| | ||
= help: the trait `Sync` is not implemented for `Cell<()>` | ||
= note: if you want to do aliasing and mutation between multiple threads, use `std::sync::RwLock` | ||
note: required by a bound in `require_sync` | ||
--> $DIR/suggest-cell.rs:1:20 | ||
| | ||
LL | fn require_sync<T: Sync>() {} | ||
| ^^^^ required by this bound in `require_sync` | ||
|
||
error[E0277]: `Cell<u8>` cannot be shared between threads safely | ||
--> $DIR/suggest-cell.rs:17:20 | ||
| | ||
LL | require_sync::<std::cell::Cell<u8>>(); | ||
| ^^^^^^^^^^^^^^^^^^^ `Cell<u8>` cannot be shared between threads safely | ||
| | ||
= help: the trait `Sync` is not implemented for `Cell<u8>` | ||
= note: if you want to do aliasing and mutation between multiple threads, use `std::sync::RwLock` or `std::sync::atomic::AtomicU8` instead | ||
note: required by a bound in `require_sync` | ||
--> $DIR/suggest-cell.rs:1:20 | ||
| | ||
LL | fn require_sync<T: Sync>() {} | ||
| ^^^^ required by this bound in `require_sync` | ||
|
||
error[E0277]: `Cell<i32>` cannot be shared between threads safely | ||
--> $DIR/suggest-cell.rs:22:20 | ||
| | ||
LL | require_sync::<std::cell::Cell<i32>>(); | ||
| ^^^^^^^^^^^^^^^^^^^^ `Cell<i32>` cannot be shared between threads safely | ||
| | ||
= help: the trait `Sync` is not implemented for `Cell<i32>` | ||
= note: if you want to do aliasing and mutation between multiple threads, use `std::sync::RwLock` or `std::sync::atomic::AtomicI32` instead | ||
note: required by a bound in `require_sync` | ||
--> $DIR/suggest-cell.rs:1:20 | ||
| | ||
LL | fn require_sync<T: Sync>() {} | ||
| ^^^^ required by this bound in `require_sync` | ||
|
||
error[E0277]: `Cell<bool>` cannot be shared between threads safely | ||
--> $DIR/suggest-cell.rs:27:20 | ||
| | ||
LL | require_sync::<std::cell::Cell<bool>>(); | ||
| ^^^^^^^^^^^^^^^^^^^^^ `Cell<bool>` cannot be shared between threads safely | ||
| | ||
= help: the trait `Sync` is not implemented for `Cell<bool>` | ||
= note: if you want to do aliasing and mutation between multiple threads, use `std::sync::RwLock` or `std::sync::atomic::AtomicBool` instead | ||
note: required by a bound in `require_sync` | ||
--> $DIR/suggest-cell.rs:1:20 | ||
| | ||
LL | fn require_sync<T: Sync>() {} | ||
| ^^^^ required by this bound in `require_sync` | ||
|
||
error: aborting due to 4 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0277`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#![feature(once_cell)] | ||
|
||
fn require_sync<T: Sync>() {} | ||
//~^ NOTE required by this bound in `require_sync` | ||
//~| NOTE required by a bound in `require_sync` | ||
|
||
fn main() { | ||
require_sync::<std::cell::OnceCell<()>>(); | ||
//~^ ERROR `OnceCell<()>` cannot be shared between threads safely | ||
//~| NOTE `OnceCell<()>` cannot be shared between threads safely | ||
//~| NOTE use `std::sync::OnceLock` instead | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
error[E0277]: `OnceCell<()>` cannot be shared between threads safely | ||
--> $DIR/suggest-once-cell.rs:8:20 | ||
| | ||
LL | require_sync::<std::cell::OnceCell<()>>(); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^ `OnceCell<()>` cannot be shared between threads safely | ||
| | ||
= help: the trait `Sync` is not implemented for `OnceCell<()>` | ||
= note: if you want to do aliasing and mutation between multiple threads, use `std::sync::OnceLock` instead | ||
note: required by a bound in `require_sync` | ||
--> $DIR/suggest-once-cell.rs:3:20 | ||
| | ||
LL | fn require_sync<T: Sync>() {} | ||
| ^^^^ required by this bound in `require_sync` | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0277`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#![feature(once_cell)] | ||
|
||
fn require_sync<T: Sync>() {} | ||
//~^ NOTE required by this bound in `require_sync` | ||
//~| NOTE required by a bound in `require_sync` | ||
|
||
fn main() { | ||
require_sync::<std::cell::RefCell<()>>(); | ||
//~^ ERROR `RefCell<()>` cannot be shared between threads safely | ||
//~| NOTE `RefCell<()>` cannot be shared between threads safely | ||
//~| NOTE use `std::sync::RwLock` instead | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually... Removing this would be a breaking change: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=1f4ad2c6d839ce8a21237c4faa7b2e9e (tl;dr: you'll be able to impl trait for
<T: Sync>
andOnceCell
).Should we consult t-libs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not believe so (I'm not totally sure) - coherence only lets you do this in the crate where
S
is defined, for now there is no (stable) way to rely on a negative impl.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, this is easy to prove: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=1ff2fdaa8ed22c14e94aaddb348ab850.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, it is said to be a breaking change by the docs: https://doc.rust-lang.org/beta/unstable-book/language-features/negative-impls.html, so I'm again not sure about this.