diff options
author | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2022-06-15 21:44:04 +0000 |
---|---|---|
committer | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2022-06-15 21:44:04 +0000 |
commit | 69ae211656ab81a60cac338fb93e271f32d2a929 (patch) | |
tree | 08eaef0efd5d2e80891d9c7ea8ffce1511720014 | |
parent | e20a02ad0a58bb3f7b5be2a63d93190bb77cf5b0 (diff) | |
parent | 3619c28f407eeb71d739672b653d677dd4bebf17 (diff) | |
download | futures-task-aml_tz3_314012010.tar.gz |
Snap for 8730993 from 3619c28f407eeb71d739672b653d677dd4bebf17 to mainline-tzdata3-releaseaml_tz3_314012070aml_tz3_314012050aml_tz3_314012010aml_tz3_313110000aml_tz3_312511020aml_tz3_312511010aml_tz3_312410020aml_tz3_312410010android12-mainline-tzdata3-releaseaml_tz3_314012010
Change-Id: I4927e2bcd249060fec4051d619623adc66877165
-rw-r--r-- | .cargo_vcs_info.json | 7 | ||||
-rw-r--r-- | Android.bp | 26 | ||||
-rw-r--r-- | Cargo.toml | 19 | ||||
-rw-r--r-- | Cargo.toml.orig | 10 | ||||
-rw-r--r-- | METADATA | 8 | ||||
-rw-r--r-- | README.md | 23 | ||||
-rw-r--r-- | TEST_MAPPING | 150 | ||||
-rw-r--r-- | build.rs | 41 | ||||
-rw-r--r-- | cargo2android.json | 5 | ||||
-rw-r--r-- | no_atomic_cas.rs | 13 | ||||
-rw-r--r-- | src/future_obj.rs | 68 | ||||
-rw-r--r-- | src/lib.rs | 60 | ||||
-rw-r--r-- | src/spawn.rs | 34 | ||||
-rw-r--r-- | src/waker.rs | 18 | ||||
-rw-r--r-- | src/waker_ref.rs | 25 |
15 files changed, 284 insertions, 223 deletions
diff --git a/.cargo_vcs_info.json b/.cargo_vcs_info.json index 1f750b1..f3ad3ab 100644 --- a/.cargo_vcs_info.json +++ b/.cargo_vcs_info.json @@ -1,6 +1,5 @@ { "git": { - "sha1": "fc1e3250219170e31cddb8857a276cba7dd08d44" - }, - "path_in_vcs": "futures-task" -}
\ No newline at end of file + "sha1": "c91f8691672c7401b1923ab00bf138975c99391a" + } +} @@ -37,18 +37,12 @@ license { ], } -rust_test { - name: "futures-task_test_src_lib", - host_supported: true, +rust_defaults { + name: "futures-task_defaults", crate_name: "futures_task", - cargo_env_compat: true, - cargo_pkg_version: "0.3.21", srcs: ["src/lib.rs"], test_suites: ["general-tests"], auto_gen_config: true, - test_options: { - unit_test: true, - }, edition: "2018", features: [ "alloc", @@ -57,12 +51,23 @@ rust_test { ], } +rust_test_host { + name: "futures-task_host_test_src_lib", + defaults: ["futures-task_defaults"], + test_options: { + unit_test: true, + }, +} + +rust_test { + name: "futures-task_device_test_src_lib", + defaults: ["futures-task_defaults"], +} + rust_library { name: "libfutures_task", host_supported: true, crate_name: "futures_task", - cargo_env_compat: true, - cargo_pkg_version: "0.3.21", srcs: ["src/lib.rs"], edition: "2018", features: [ @@ -72,7 +77,6 @@ rust_library { ], apex_available: [ "//apex_available:platform", - "com.android.bluetooth", "com.android.resolv", "com.android.virt", ], @@ -3,24 +3,23 @@ # When uploading crates to the registry Cargo will automatically # "normalize" Cargo.toml files for maximal compatibility # with all versions of Cargo and also rewrite `path` dependencies -# to registry (e.g., crates.io) dependencies. +# to registry (e.g., crates.io) dependencies # -# If you are reading this file be aware that the original Cargo.toml -# will likely look very different (and much more reasonable). -# See Cargo.toml.orig for the original contents. +# If you believe there's an error in this file please file an +# issue against the rust-lang/cargo repository. If you're +# editing this file be aware that the upstream Cargo.toml +# will likely look very different (and much more reasonable) [package] edition = "2018" -rust-version = "1.45" name = "futures-task" -version = "0.3.21" -description = """ -Tools for working with tasks. -""" +version = "0.3.13" +authors = ["Alex Crichton <alex@alexcrichton.com>"] +description = "Tools for working with tasks.\n" homepage = "https://rust-lang.github.io/futures-rs" +documentation = "https://docs.rs/futures-task/0.3" license = "MIT OR Apache-2.0" repository = "https://github.com/rust-lang/futures-rs" - [package.metadata.docs.rs] all-features = true diff --git a/Cargo.toml.orig b/Cargo.toml.orig index 77fec6f..764a692 100644 --- a/Cargo.toml.orig +++ b/Cargo.toml.orig @@ -1,11 +1,12 @@ [package] name = "futures-task" -version = "0.3.21" edition = "2018" -rust-version = "1.45" +version = "0.3.13" +authors = ["Alex Crichton <alex@alexcrichton.com>"] license = "MIT OR Apache-2.0" repository = "https://github.com/rust-lang/futures-rs" homepage = "https://rust-lang.github.io/futures-rs" +documentation = "https://docs.rs/futures-task/0.3" description = """ Tools for working with tasks. """ @@ -15,8 +16,9 @@ default = ["std"] std = ["alloc"] alloc = [] -# These features are no longer used. -# TODO: remove in the next major version. +# Unstable features +# These features are outside of the normal semver guarantees and require the +# `unstable` feature as an explicit opt-in to unstable API. unstable = [] cfg-target-has-atomic = [] @@ -7,13 +7,13 @@ third_party { } url { type: ARCHIVE - value: "https://static.crates.io/crates/futures-task/futures-task-0.3.21.crate" + value: "https://static.crates.io/crates/futures-task/futures-task-0.3.13.crate" } - version: "0.3.21" + version: "0.3.13" license_type: NOTICE last_upgrade_date { - year: 2022 - month: 3 + year: 2021 + month: 4 day: 1 } } diff --git a/README.md b/README.md deleted file mode 100644 index 8ceeba9..0000000 --- a/README.md +++ /dev/null @@ -1,23 +0,0 @@ -# futures-task - -Tools for working with tasks. - -## Usage - -Add this to your `Cargo.toml`: - -```toml -[dependencies] -futures-task = "0.3" -``` - -The current `futures-task` requires Rust 1.45 or later. - -## License - -Licensed under either of [Apache License, Version 2.0](LICENSE-APACHE) or -[MIT license](LICENSE-MIT) at your option. - -Unless you explicitly state otherwise, any contribution intentionally submitted -for inclusion in the work by you, as defined in the Apache-2.0 license, shall -be dual licensed as above, without any additional terms or conditions. diff --git a/TEST_MAPPING b/TEST_MAPPING index 64f7c12..723e5ac 100644 --- a/TEST_MAPPING +++ b/TEST_MAPPING @@ -1,51 +1,161 @@ // Generated by update_crate_tests.py for tests that depend on this crate. { - "imports": [ + "presubmit": [ { - "path": "external/rust/crates/anyhow" + "name": "ZipFuseTest" }, { - "path": "external/rust/crates/futures-util" + "name": "anyhow_device_test_src_lib" }, { - "path": "external/rust/crates/tokio" + "name": "anyhow_device_test_tests_test_autotrait" }, { - "path": "external/rust/crates/tokio-test" - } - ], - "presubmit": [ + "name": "anyhow_device_test_tests_test_boxed" + }, { - "name": "ZipFuseTest" + "name": "anyhow_device_test_tests_test_chain" }, { - "name": "authfs_device_test_src_lib" + "name": "anyhow_device_test_tests_test_context" }, { - "name": "doh_unit_test" + "name": "anyhow_device_test_tests_test_convert" }, { - "name": "futures-task_test_src_lib" + "name": "anyhow_device_test_tests_test_downcast" }, { - "name": "virtualizationservice_device_test" - } - ], - "presubmit-rust": [ + "name": "anyhow_device_test_tests_test_ffi" + }, { - "name": "ZipFuseTest" + "name": "anyhow_device_test_tests_test_fmt" + }, + { + "name": "anyhow_device_test_tests_test_macros" + }, + { + "name": "anyhow_device_test_tests_test_repr" + }, + { + "name": "anyhow_device_test_tests_test_source" }, { "name": "authfs_device_test_src_lib" }, { - "name": "doh_unit_test" + "name": "futures-task_device_test_src_lib" + }, + { + "name": "futures-util_device_test_src_lib" + }, + { + "name": "tokio-test_device_test_src_lib" + }, + { + "name": "tokio-test_device_test_tests_block_on" + }, + { + "name": "tokio-test_device_test_tests_io" + }, + { + "name": "tokio-test_device_test_tests_macros" + }, + { + "name": "tokio_device_test_tests_buffered" + }, + { + "name": "tokio_device_test_tests_io_async_read" + }, + { + "name": "tokio_device_test_tests_io_copy_bidirectional" + }, + { + "name": "tokio_device_test_tests_io_lines" + }, + { + "name": "tokio_device_test_tests_io_mem_stream" + }, + { + "name": "tokio_device_test_tests_io_read" + }, + { + "name": "tokio_device_test_tests_io_read_buf" + }, + { + "name": "tokio_device_test_tests_io_read_to_end" + }, + { + "name": "tokio_device_test_tests_io_take" + }, + { + "name": "tokio_device_test_tests_io_write" + }, + { + "name": "tokio_device_test_tests_io_write_all" + }, + { + "name": "tokio_device_test_tests_io_write_buf" + }, + { + "name": "tokio_device_test_tests_io_write_int" + }, + { + "name": "tokio_device_test_tests_macros_join" + }, + { + "name": "tokio_device_test_tests_no_rt" + }, + { + "name": "tokio_device_test_tests_rt_basic" + }, + { + "name": "tokio_device_test_tests_rt_threaded" + }, + { + "name": "tokio_device_test_tests_sync_barrier" + }, + { + "name": "tokio_device_test_tests_sync_broadcast" + }, + { + "name": "tokio_device_test_tests_sync_errors" + }, + { + "name": "tokio_device_test_tests_sync_mpsc" + }, + { + "name": "tokio_device_test_tests_sync_mutex_owned" + }, + { + "name": "tokio_device_test_tests_sync_rwlock" + }, + { + "name": "tokio_device_test_tests_sync_watch" + }, + { + "name": "tokio_device_test_tests_task_local" + }, + { + "name": "tokio_device_test_tests_task_local_set" + }, + { + "name": "tokio_device_test_tests_tcp_accept" + }, + { + "name": "tokio_device_test_tests_tcp_echo" + }, + { + "name": "tokio_device_test_tests_tcp_into_std" + }, + { + "name": "tokio_device_test_tests_tcp_shutdown" }, { - "name": "futures-task_test_src_lib" + "name": "tokio_device_test_tests_time_rt" }, { - "name": "virtualizationservice_device_test" + "name": "tokio_device_test_tests_uds_split" } ] } diff --git a/build.rs b/build.rs deleted file mode 100644 index 05e0496..0000000 --- a/build.rs +++ /dev/null @@ -1,41 +0,0 @@ -// The rustc-cfg listed below are considered public API, but it is *unstable* -// and outside of the normal semver guarantees: -// -// - `futures_no_atomic_cas` -// Assume the target does *not* support atomic CAS operations. -// This is usually detected automatically by the build script, but you may -// need to enable it manually when building for custom targets or using -// non-cargo build systems that don't run the build script. -// -// With the exceptions mentioned above, the rustc-cfg emitted by the build -// script are *not* public API. - -#![warn(rust_2018_idioms, single_use_lifetimes)] - -use std::env; - -include!("no_atomic_cas.rs"); - -fn main() { - let target = match env::var("TARGET") { - Ok(target) => target, - Err(e) => { - println!( - "cargo:warning={}: unable to get TARGET environment variable: {}", - env!("CARGO_PKG_NAME"), - e - ); - return; - } - }; - - // Note that this is `no_*`, not `has_*`. This allows treating - // `cfg(target_has_atomic = "ptr")` as true when the build script doesn't - // run. This is needed for compatibility with non-cargo build systems that - // don't run the build script. - if NO_ATOMIC_CAS.contains(&&*target) { - println!("cargo:rustc-cfg=futures_no_atomic_cas"); - } - - println!("cargo:rerun-if-changed=no_atomic_cas.rs"); -} diff --git a/cargo2android.json b/cargo2android.json index 5b266a6..44e747c 100644 --- a/cargo2android.json +++ b/cargo2android.json @@ -1,13 +1,12 @@ { "apex-available": [ "//apex_available:platform", - "com.android.bluetooth", "com.android.resolv", "com.android.virt" ], + "min_sdk_version": "29", "dependencies": true, "device": true, - "min-sdk-version": "29", "run": true, "tests": true -} +}
\ No newline at end of file diff --git a/no_atomic_cas.rs b/no_atomic_cas.rs deleted file mode 100644 index 9b05d4b..0000000 --- a/no_atomic_cas.rs +++ /dev/null @@ -1,13 +0,0 @@ -// This file is @generated by no_atomic_cas.sh. -// It is not intended for manual editing. - -const NO_ATOMIC_CAS: &[&str] = &[ - "avr-unknown-gnu-atmega328", - "bpfeb-unknown-none", - "bpfel-unknown-none", - "msp430-none-elf", - "riscv32i-unknown-none-elf", - "riscv32imc-unknown-none-elf", - "thumbv4t-none-eabi", - "thumbv6m-none-eabi", -]; diff --git a/src/future_obj.rs b/src/future_obj.rs index f67494a..373be24 100644 --- a/src/future_obj.rs +++ b/src/future_obj.rs @@ -1,8 +1,8 @@ use core::{ + mem, fmt, future::Future, marker::PhantomData, - mem, pin::Pin, task::{Context, Poll}, }; @@ -26,16 +26,16 @@ impl<T> Unpin for LocalFutureObj<'_, T> {} #[allow(single_use_lifetimes)] #[allow(clippy::transmute_ptr_to_ptr)] -unsafe fn remove_future_lifetime<'a, T>( - ptr: *mut (dyn Future<Output = T> + 'a), -) -> *mut (dyn Future<Output = T> + 'static) { +unsafe fn remove_future_lifetime<'a, T>(ptr: *mut (dyn Future<Output = T> + 'a)) + -> *mut (dyn Future<Output = T> + 'static) +{ mem::transmute(ptr) } #[allow(single_use_lifetimes)] -unsafe fn remove_drop_lifetime<'a, T>( - ptr: unsafe fn(*mut (dyn Future<Output = T> + 'a)), -) -> unsafe fn(*mut (dyn Future<Output = T> + 'static)) { +unsafe fn remove_drop_lifetime<'a, T>(ptr: unsafe fn (*mut (dyn Future<Output = T> + 'a))) + -> unsafe fn(*mut (dyn Future<Output = T> + 'static)) +{ mem::transmute(ptr) } @@ -65,7 +65,8 @@ impl<'a, T> LocalFutureObj<'a, T> { impl<T> fmt::Debug for LocalFutureObj<'_, T> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.debug_struct("LocalFutureObj").finish() + f.debug_struct("LocalFutureObj") + .finish() } } @@ -81,13 +82,17 @@ impl<T> Future for LocalFutureObj<'_, T> { #[inline] fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<T> { - unsafe { Pin::new_unchecked(&mut *self.future).poll(cx) } + unsafe { + Pin::new_unchecked(&mut *self.future).poll(cx) + } } } impl<T> Drop for LocalFutureObj<'_, T> { fn drop(&mut self) { - unsafe { (self.drop_fn)(self.future) } + unsafe { + (self.drop_fn)(self.future) + } } } @@ -115,7 +120,8 @@ impl<'a, T> FutureObj<'a, T> { impl<T> fmt::Debug for FutureObj<'_, T> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.debug_struct("FutureObj").finish() + f.debug_struct("FutureObj") + .finish() } } @@ -124,7 +130,7 @@ impl<T> Future for FutureObj<'_, T> { #[inline] fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<T> { - Pin::new(&mut self.0).poll(cx) + Pin::new( &mut self.0 ).poll(cx) } } @@ -174,7 +180,7 @@ pub unsafe trait UnsafeFutureObj<'a, T>: 'a { unsafe impl<'a, T, F> UnsafeFutureObj<'a, T> for &'a mut F where - F: Future<Output = T> + Unpin + 'a, + F: Future<Output = T> + Unpin + 'a { fn into_raw(self) -> *mut (dyn Future<Output = T> + 'a) { self as *mut dyn Future<Output = T> @@ -183,7 +189,8 @@ where unsafe fn drop(_ptr: *mut (dyn Future<Output = T> + 'a)) {} } -unsafe impl<'a, T> UnsafeFutureObj<'a, T> for &'a mut (dyn Future<Output = T> + Unpin + 'a) { +unsafe impl<'a, T> UnsafeFutureObj<'a, T> for &'a mut (dyn Future<Output = T> + Unpin + 'a) +{ fn into_raw(self) -> *mut (dyn Future<Output = T> + 'a) { self as *mut dyn Future<Output = T> } @@ -193,7 +200,7 @@ unsafe impl<'a, T> UnsafeFutureObj<'a, T> for &'a mut (dyn Future<Output = T> + unsafe impl<'a, T, F> UnsafeFutureObj<'a, T> for Pin<&'a mut F> where - F: Future<Output = T> + 'a, + F: Future<Output = T> + 'a { fn into_raw(self) -> *mut (dyn Future<Output = T> + 'a) { unsafe { self.get_unchecked_mut() as *mut dyn Future<Output = T> } @@ -202,7 +209,8 @@ where unsafe fn drop(_ptr: *mut (dyn Future<Output = T> + 'a)) {} } -unsafe impl<'a, T> UnsafeFutureObj<'a, T> for Pin<&'a mut (dyn Future<Output = T> + 'a)> { +unsafe impl<'a, T> UnsafeFutureObj<'a, T> for Pin<&'a mut (dyn Future<Output = T> + 'a)> +{ fn into_raw(self) -> *mut (dyn Future<Output = T> + 'a) { unsafe { self.get_unchecked_mut() as *mut dyn Future<Output = T> } } @@ -216,15 +224,14 @@ mod if_alloc { use alloc::boxed::Box; unsafe impl<'a, T, F> UnsafeFutureObj<'a, T> for Box<F> - where - F: Future<Output = T> + 'a, + where F: Future<Output = T> + 'a { fn into_raw(self) -> *mut (dyn Future<Output = T> + 'a) { Box::into_raw(self) } unsafe fn drop(ptr: *mut (dyn Future<Output = T> + 'a)) { - drop(Box::from_raw(ptr.cast::<F>())) + drop(Box::from_raw(ptr as *mut F)) } } @@ -250,11 +257,12 @@ mod if_alloc { unsafe impl<'a, T, F> UnsafeFutureObj<'a, T> for Pin<Box<F>> where - F: Future<Output = T> + 'a, + F: Future<Output = T> + 'a { - fn into_raw(self) -> *mut (dyn Future<Output = T> + 'a) { - let mut this = mem::ManuallyDrop::new(self); - unsafe { this.as_mut().get_unchecked_mut() as *mut _ } + fn into_raw(mut self) -> *mut (dyn Future<Output = T> + 'a) { + let ptr = unsafe { self.as_mut().get_unchecked_mut() as *mut _ }; + mem::forget(self); + ptr } unsafe fn drop(ptr: *mut (dyn Future<Output = T> + 'a)) { @@ -263,9 +271,10 @@ mod if_alloc { } unsafe impl<'a, T: 'a> UnsafeFutureObj<'a, T> for Pin<Box<dyn Future<Output = T> + 'a>> { - fn into_raw(self) -> *mut (dyn Future<Output = T> + 'a) { - let mut this = mem::ManuallyDrop::new(self); - unsafe { this.as_mut().get_unchecked_mut() as *mut _ } + fn into_raw(mut self) -> *mut (dyn Future<Output = T> + 'a) { + let ptr = unsafe { self.as_mut().get_unchecked_mut() as *mut _ }; + mem::forget(self); + ptr } unsafe fn drop(ptr: *mut (dyn Future<Output = T> + 'a)) { @@ -274,9 +283,10 @@ mod if_alloc { } unsafe impl<'a, T: 'a> UnsafeFutureObj<'a, T> for Pin<Box<dyn Future<Output = T> + Send + 'a>> { - fn into_raw(self) -> *mut (dyn Future<Output = T> + 'a) { - let mut this = mem::ManuallyDrop::new(self); - unsafe { this.as_mut().get_unchecked_mut() as *mut _ } + fn into_raw(mut self) -> *mut (dyn Future<Output = T> + 'a) { + let ptr = unsafe { self.as_mut().get_unchecked_mut() as *mut _ }; + mem::forget(self); + ptr } unsafe fn drop(ptr: *mut (dyn Future<Output = T> + 'a)) { @@ -1,43 +1,47 @@ //! Tools for working with tasks. +#![cfg_attr(feature = "cfg-target-has-atomic", feature(cfg_target_has_atomic))] + #![cfg_attr(not(feature = "std"), no_std)] -#![warn(missing_debug_implementations, missing_docs, rust_2018_idioms, unreachable_pub)] + +#![warn(missing_docs, missing_debug_implementations, rust_2018_idioms, unreachable_pub)] // It cannot be included in the published code because this lints have false positives in the minimum required version. #![cfg_attr(test, warn(single_use_lifetimes))] -#![doc(test( - no_crate_inject, - attr( - deny(warnings, rust_2018_idioms, single_use_lifetimes), - allow(dead_code, unused_assignments, unused_variables) - ) -))] +#![warn(clippy::all)] +#![doc(test(attr(deny(warnings), allow(dead_code, unused_assignments, unused_variables))))] + +#[cfg(all(feature = "cfg-target-has-atomic", not(feature = "unstable")))] +compile_error!("The `cfg-target-has-atomic` feature requires the `unstable` feature as an explicit opt-in to unstable features"); #[cfg(feature = "alloc")] extern crate alloc; +macro_rules! cfg_target_has_atomic { + ($($item:item)*) => {$( + #[cfg_attr(feature = "cfg-target-has-atomic", cfg(target_has_atomic = "ptr"))] + $item + )*}; +} + mod spawn; -pub use crate::spawn::{LocalSpawn, Spawn, SpawnError}; +pub use crate::spawn::{Spawn, SpawnError, LocalSpawn}; -#[cfg(not(futures_no_atomic_cas))] -#[cfg(feature = "alloc")] -mod arc_wake; -#[cfg(not(futures_no_atomic_cas))] -#[cfg(feature = "alloc")] -pub use crate::arc_wake::ArcWake; +cfg_target_has_atomic! { + #[cfg(feature = "alloc")] + mod arc_wake; + #[cfg(feature = "alloc")] + pub use crate::arc_wake::ArcWake; -#[cfg(not(futures_no_atomic_cas))] -#[cfg(feature = "alloc")] -mod waker; -#[cfg(not(futures_no_atomic_cas))] -#[cfg(feature = "alloc")] -pub use crate::waker::waker; + #[cfg(feature = "alloc")] + mod waker; + #[cfg(feature = "alloc")] + pub use crate::waker::waker; -#[cfg(not(futures_no_atomic_cas))] -#[cfg(feature = "alloc")] -mod waker_ref; -#[cfg(not(futures_no_atomic_cas))] -#[cfg(feature = "alloc")] -pub use crate::waker_ref::{waker_ref, WakerRef}; + #[cfg(feature = "alloc")] + mod waker_ref; + #[cfg(feature = "alloc")] + pub use crate::waker_ref::{waker_ref, WakerRef}; +} mod future_obj; pub use crate::future_obj::{FutureObj, LocalFutureObj, UnsafeFutureObj}; @@ -47,4 +51,4 @@ pub use crate::noop_waker::noop_waker; pub use crate::noop_waker::noop_waker_ref; #[doc(no_inline)] -pub use core::task::{Context, Poll, RawWaker, RawWakerVTable, Waker}; +pub use core::task::{Context, Poll, Waker, RawWaker, RawWakerVTable}; diff --git a/src/spawn.rs b/src/spawn.rs index f4e6339..a515dd4 100644 --- a/src/spawn.rs +++ b/src/spawn.rs @@ -126,7 +126,7 @@ impl<Sp: ?Sized + LocalSpawn> LocalSpawn for &mut Sp { #[cfg(feature = "alloc")] mod if_alloc { use super::*; - use alloc::{boxed::Box, rc::Rc}; + use alloc::{ boxed::Box, rc::Rc }; impl<Sp: ?Sized + Spawn> Spawn for Box<Sp> { fn spawn_obj(&self, future: FutureObj<'static, ()>) -> Result<(), SpawnError> { @@ -168,25 +168,27 @@ mod if_alloc { } } - #[cfg(not(futures_no_atomic_cas))] - impl<Sp: ?Sized + Spawn> Spawn for alloc::sync::Arc<Sp> { - fn spawn_obj(&self, future: FutureObj<'static, ()>) -> Result<(), SpawnError> { - (**self).spawn_obj(future) - } + cfg_target_has_atomic! { + use alloc::{ sync::Arc }; - fn status(&self) -> Result<(), SpawnError> { - (**self).status() - } - } + impl<Sp: ?Sized + Spawn> Spawn for Arc<Sp> { + fn spawn_obj(&self, future: FutureObj<'static, ()>) -> Result<(), SpawnError> { + (**self).spawn_obj(future) + } - #[cfg(not(futures_no_atomic_cas))] - impl<Sp: ?Sized + LocalSpawn> LocalSpawn for alloc::sync::Arc<Sp> { - fn spawn_local_obj(&self, future: LocalFutureObj<'static, ()>) -> Result<(), SpawnError> { - (**self).spawn_local_obj(future) + fn status(&self) -> Result<(), SpawnError> { + (**self).status() + } } - fn status_local(&self) -> Result<(), SpawnError> { - (**self).status_local() + impl<Sp: ?Sized + LocalSpawn> LocalSpawn for Arc<Sp> { + fn spawn_local_obj(&self, future: LocalFutureObj<'static, ()>) -> Result<(), SpawnError> { + (**self).spawn_local_obj(future) + } + + fn status_local(&self) -> Result<(), SpawnError> { + (**self).status_local() + } } } } diff --git a/src/waker.rs b/src/waker.rs index 7911256..265a445 100644 --- a/src/waker.rs +++ b/src/waker.rs @@ -1,7 +1,7 @@ use super::arc_wake::ArcWake; -use alloc::sync::Arc; use core::mem; -use core::task::{RawWaker, RawWakerVTable, Waker}; +use core::task::{Waker, RawWaker, RawWakerVTable}; +use alloc::sync::Arc; pub(super) fn waker_vtable<W: ArcWake>() -> &'static RawWakerVTable { &RawWakerVTable::new( @@ -20,9 +20,11 @@ pub fn waker<W>(wake: Arc<W>) -> Waker where W: ArcWake + 'static, { - let ptr = Arc::into_raw(wake).cast::<()>(); + let ptr = Arc::into_raw(wake) as *const (); - unsafe { Waker::from_raw(RawWaker::new(ptr, waker_vtable::<W>())) } + unsafe { + Waker::from_raw(RawWaker::new(ptr, waker_vtable::<W>())) + } } // FIXME: panics on Arc::clone / refcount changes could wreak havoc on the @@ -31,7 +33,7 @@ where #[allow(clippy::redundant_clone)] // The clone here isn't actually redundant. unsafe fn increase_refcount<T: ArcWake>(data: *const ()) { // Retain Arc, but don't touch refcount by wrapping in ManuallyDrop - let arc = mem::ManuallyDrop::new(Arc::<T>::from_raw(data.cast::<T>())); + let arc = mem::ManuallyDrop::new(Arc::<T>::from_raw(data as *const T)); // Now increase refcount, but don't drop new refcount either let _arc_clone: mem::ManuallyDrop<_> = arc.clone(); } @@ -43,17 +45,17 @@ unsafe fn clone_arc_raw<T: ArcWake>(data: *const ()) -> RawWaker { } unsafe fn wake_arc_raw<T: ArcWake>(data: *const ()) { - let arc: Arc<T> = Arc::from_raw(data.cast::<T>()); + let arc: Arc<T> = Arc::from_raw(data as *const T); ArcWake::wake(arc); } // used by `waker_ref` unsafe fn wake_by_ref_arc_raw<T: ArcWake>(data: *const ()) { // Retain Arc, but don't touch refcount by wrapping in ManuallyDrop - let arc = mem::ManuallyDrop::new(Arc::<T>::from_raw(data.cast::<T>())); + let arc = mem::ManuallyDrop::new(Arc::<T>::from_raw(data as *const T)); ArcWake::wake_by_ref(&arc); } unsafe fn drop_arc_raw<T: ArcWake>(data: *const ()) { - drop(Arc::<T>::from_raw(data.cast::<T>())) + drop(Arc::<T>::from_raw(data as *const T)) } diff --git a/src/waker_ref.rs b/src/waker_ref.rs index 7fb552f..76d849a 100644 --- a/src/waker_ref.rs +++ b/src/waker_ref.rs @@ -1,10 +1,10 @@ -use super::arc_wake::ArcWake; +use super::arc_wake::{ArcWake}; use super::waker::waker_vtable; use alloc::sync::Arc; -use core::marker::PhantomData; use core::mem::ManuallyDrop; +use core::marker::PhantomData; use core::ops::Deref; -use core::task::{RawWaker, Waker}; +use core::task::{Waker, RawWaker}; /// A [`Waker`] that is only valid for a given lifetime. /// @@ -22,7 +22,10 @@ impl<'a> WakerRef<'a> { // copy the underlying (raw) waker without calling a clone, // as we won't call Waker::drop either. let waker = ManuallyDrop::new(unsafe { core::ptr::read(waker) }); - Self { waker, _marker: PhantomData } + Self { + waker, + _marker: PhantomData, + } } /// Create a new [`WakerRef`] from a [`Waker`] that must not be dropped. @@ -32,7 +35,10 @@ impl<'a> WakerRef<'a> { /// by the caller), and the [`Waker`] doesn't need to or must not be /// destroyed. pub fn new_unowned(waker: ManuallyDrop<Waker>) -> Self { - Self { waker, _marker: PhantomData } + Self { + waker, + _marker: PhantomData, + } } } @@ -51,13 +57,14 @@ impl Deref for WakerRef<'_> { #[inline] pub fn waker_ref<W>(wake: &Arc<W>) -> WakerRef<'_> where - W: ArcWake, + W: ArcWake { // simply copy the pointer instead of using Arc::into_raw, // as we don't actually keep a refcount by using ManuallyDrop.< - let ptr = Arc::as_ptr(wake).cast::<()>(); + let ptr = (&**wake as *const W) as *const (); - let waker = - ManuallyDrop::new(unsafe { Waker::from_raw(RawWaker::new(ptr, waker_vtable::<W>())) }); + let waker = ManuallyDrop::new(unsafe { + Waker::from_raw(RawWaker::new(ptr, waker_vtable::<W>())) + }); WakerRef::new_unowned(waker) } |