forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#106944 - Nilstrieb:there-once-was-a-diagnos…
…tic, r=WaffleLapkin Suggest using a lock for `*Cell: Sync` bounds I mostly did this for `OnceCell<T>` at first because users will be confused to see that the `OnceCell<T>` in `std` isn't `Sync` but then extended it to `Cell<T>` and `RefCell<T>` as well.
- Loading branch information
Showing
19 changed files
with
233 additions
and
5 deletions.
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.