-
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
Preserve same vtable pointer when cloning raw waker, to fix Waker::will_wake #121622
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. More problems with this test... it seems to have a memory leak. Is that expected?
Any idea how to fix that? This reproduces in a stand-alone test (run it in Miri to see the leak). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Filed as #122180 |
||
let clone = waker.clone(); | ||
|
||
assert!(waker.will_wake(&clone)); | ||
assert!(clone.will_wake(&waker)); | ||
} |
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.
These tests are testing things which are not guaranteed by the language, they just happen to be what rustc currently does. In particular, these tests fail in Miri.
Not sure if that is intentional; there's no comment here indicating such an intent.