Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
bae0da8
Implement data and vtable getters for `RawWaker`
oxalica Dec 12, 2021
d9b98f9
Eliminate duplicate codes of is_single_fp_element
woodenarrow Dec 17, 2021
f8ee57b
`impl Display for io::ErrorKind`
jyn514 Jan 19, 2022
2bae730
update `FutureIncompatibilityReason`
lcnr Jan 27, 2022
2e9ee90
implement lint for suspicious auto trait impls
lcnr Jan 27, 2022
7f24778
Suggest making base prefix lowercase if parsing fails
5225225 Jan 17, 2022
1a77d62
kmc-solid: Increase the default stack size
kawadakk Jan 31, 2022
0b8f372
Remove two unnecessary transmutes from opaque Encoder and Decoder
bjorn3 Jan 29, 2022
ec3b711
Write UI tests, tweak message
5225225 Jan 27, 2022
c15ef58
Fix suggestion to slice if scrutinee is a `Result` or `Option`
FabianWolff Nov 29, 2021
0363f11
Add match on `Vec<_>` to `ui/typeck/issue-91328.rs` test
FabianWolff Jan 15, 2022
95344c0
Add FIXME comment
FabianWolff Jan 31, 2022
a937dd5
Rollup merge of #91343 - FabianWolff:issue-91328-as-deref, r=jackh726
matthiaskrgr Jan 31, 2022
2d658e9
Rollup merge of #91828 - oxalica:feat/waker-getters, r=dtolnay
matthiaskrgr Jan 31, 2022
0c44c66
Rollup merge of #92021 - woodenarrow:br_single_fp_element, r=Mark-Sim…
matthiaskrgr Jan 31, 2022
561f997
Rollup merge of #93019 - 5225225:uppercase-suffix, r=wesleywiser
matthiaskrgr Jan 31, 2022
802c57d
Rollup merge of #93090 - jyn514:errorkind-asstr, r=dtolnay
matthiaskrgr Jan 31, 2022
478698b
Rollup merge of #93267 - lcnr:auto-trait-lint, r=nikomatsakis
matthiaskrgr Jan 31, 2022
4aee623
Rollup merge of #93456 - bjorn3:remove_unnecessary_unsafe, r=michaelw…
matthiaskrgr Jan 31, 2022
8968b20
Rollup merge of #93504 - solid-rs:fix-kmc-solid-stack-size, r=nagisa
matthiaskrgr Jan 31, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions library/core/src/task/wake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,22 @@ impl RawWaker {
pub const fn new(data: *const (), vtable: &'static RawWakerVTable) -> RawWaker {
RawWaker { data, vtable }
}

/// Get the `data` pointer used to create this `RawWaker`.
#[inline]
#[must_use]
#[unstable(feature = "waker_getters", issue = "87021")]
pub fn data(&self) -> *const () {
self.data
}

/// Get the `vtable` pointer used to create this `RawWaker`.
#[inline]
#[must_use]
#[unstable(feature = "waker_getters", issue = "87021")]
pub fn vtable(&self) -> &'static RawWakerVTable {
self.vtable
}
}

/// A virtual function pointer table (vtable) that specifies the behavior
Expand Down Expand Up @@ -260,6 +276,14 @@ impl Waker {
pub unsafe fn from_raw(waker: RawWaker) -> Waker {
Waker { waker }
}

/// Get a reference to the underlying [`RawWaker`].
#[inline]
#[must_use]
#[unstable(feature = "waker_getters", issue = "87021")]
pub fn as_raw(&self) -> &RawWaker {
&self.waker
}
}

#[stable(feature = "futures_api", since = "1.36.0")]
Expand Down
2 changes: 2 additions & 0 deletions library/core/tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
#![feature(unzip_option)]
#![feature(const_array_from_ref)]
#![feature(const_slice_from_ref)]
#![feature(waker_getters)]
#![deny(unsafe_op_in_unsafe_fn)]

extern crate test;
Expand Down Expand Up @@ -131,3 +132,4 @@ mod task;
mod time;
mod tuple;
mod unicode;
mod waker;
22 changes: 22 additions & 0 deletions library/core/tests/waker.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
use std::ptr;
use std::task::{RawWaker, RawWakerVTable, Waker};

#[test]
fn test_waker_getters() {
let raw_waker = RawWaker::new(42usize as *mut (), &WAKER_VTABLE);
assert_eq!(raw_waker.data() as usize, 42);
assert!(ptr::eq(raw_waker.vtable(), &WAKER_VTABLE));

let waker = unsafe { Waker::from_raw(raw_waker) };
let waker2 = waker.clone();
let raw_waker2 = waker2.as_raw();
assert_eq!(raw_waker2.data() as usize, 43);
assert!(ptr::eq(raw_waker2.vtable(), &WAKER_VTABLE));
}

static WAKER_VTABLE: RawWakerVTable = RawWakerVTable::new(
|data| RawWaker::new((data as usize + 1) as *mut (), &WAKER_VTABLE),
|_| {},
|_| {},
|_| {},
);