forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 7
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#121622 - dtolnay:wake, r=cuviper Preserve same vtable pointer when cloning raw waker, to fix Waker::will_wake Fixes rust-lang#121600. As `@jkarneges` identified in rust-lang#121600 (comment), the issue is two different const promotions produce two statics at different addresses, which may or may not later be deduplicated by the linker (in this case not). Prior to rust-lang#119863, the content of the statics was compared, and they were equal. After, the address of the statics are compared and they are not equal. It is documented that `will_wake` _"works on a best-effort basis, and may return false even when the Wakers would awaken the same task"_ so this PR fixes a quality-of-implementation issue, not a correctness issue.
- Loading branch information
Showing
3 changed files
with
49 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
use alloc::rc::Rc; | ||
use alloc::sync::Arc; | ||
use alloc::task::{LocalWake, Wake}; | ||
use core::task::{LocalWaker, Waker}; | ||
|
||
#[test] | ||
fn test_waker_will_wake_clone() { | ||
struct NoopWaker; | ||
|
||
impl Wake for NoopWaker { | ||
fn wake(self: Arc<Self>) {} | ||
} | ||
|
||
let waker = Waker::from(Arc::new(NoopWaker)); | ||
let clone = waker.clone(); | ||
|
||
assert!(waker.will_wake(&clone)); | ||
assert!(clone.will_wake(&waker)); | ||
} | ||
|
||
#[test] | ||
fn test_local_waker_will_wake_clone() { | ||
struct NoopWaker; | ||
|
||
impl LocalWake for NoopWaker { | ||
fn wake(self: Rc<Self>) {} | ||
} | ||
|
||
let waker = LocalWaker::from(Rc::new(NoopWaker)); | ||
let clone = waker.clone(); | ||
|
||
assert!(waker.will_wake(&clone)); | ||
assert!(clone.will_wake(&waker)); | ||
} |