diff options
author | Joel Galenson <jgalenson@google.com> | 2021-05-19 15:31:02 -0700 |
---|---|---|
committer | Joel Galenson <jgalenson@google.com> | 2021-05-19 15:31:02 -0700 |
commit | 9ceddf6d21bf5892c136f62c419604570f3a343c (patch) | |
tree | 01e18ddf2c995c4f887c1bd6f3e5ee7c487c83d4 | |
parent | 0301e86f3b3b458bc9cca7b2d22eca2abb4415b4 (diff) | |
download | futures-task-9ceddf6d21bf5892c136f62c419604570f3a343c.tar.gz |
Upgrade rust/crates/futures-task to 0.3.15
Test: make
Change-Id: Iec088a6db925103d58b665a3a374989c78944efa
-rw-r--r-- | .cargo_vcs_info.json | 2 | ||||
-rw-r--r-- | Cargo.toml | 2 | ||||
-rw-r--r-- | Cargo.toml.orig | 7 | ||||
-rw-r--r-- | METADATA | 8 | ||||
-rw-r--r-- | build.rs | 42 | ||||
-rw-r--r-- | no_atomic_cas.rs | 11 | ||||
-rw-r--r-- | src/future_obj.rs | 45 | ||||
-rw-r--r-- | src/lib.rs | 12 | ||||
-rw-r--r-- | src/spawn.rs | 2 | ||||
-rw-r--r-- | src/waker.rs | 8 | ||||
-rw-r--r-- | src/waker_ref.rs | 23 |
11 files changed, 96 insertions, 66 deletions
diff --git a/.cargo_vcs_info.json b/.cargo_vcs_info.json index f3ad3ab..ec6442e 100644 --- a/.cargo_vcs_info.json +++ b/.cargo_vcs_info.json @@ -1,5 +1,5 @@ { "git": { - "sha1": "c91f8691672c7401b1923ab00bf138975c99391a" + "sha1": "fc080d153bc7bf00429ec5e2b91e2f21f2243846" } } @@ -13,7 +13,7 @@ [package] edition = "2018" name = "futures-task" -version = "0.3.13" +version = "0.3.15" authors = ["Alex Crichton <alex@alexcrichton.com>"] description = "Tools for working with tasks.\n" homepage = "https://rust-lang.github.io/futures-rs" diff --git a/Cargo.toml.orig b/Cargo.toml.orig index 764a692..b454722 100644 --- a/Cargo.toml.orig +++ b/Cargo.toml.orig @@ -1,7 +1,7 @@ [package] name = "futures-task" edition = "2018" -version = "0.3.13" +version = "0.3.15" authors = ["Alex Crichton <alex@alexcrichton.com>"] license = "MIT OR Apache-2.0" repository = "https://github.com/rust-lang/futures-rs" @@ -16,9 +16,8 @@ default = ["std"] std = ["alloc"] alloc = [] -# Unstable features -# These features are outside of the normal semver guarantees and require the -# `unstable` feature as an explicit opt-in to unstable API. +# These features are no longer used. +# TODO: remove in the next major version. 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.13.crate" + value: "https://static.crates.io/crates/futures-task/futures-task-0.3.15.crate" } - version: "0.3.13" + version: "0.3.15" license_type: NOTICE last_upgrade_date { year: 2021 - month: 4 - day: 1 + month: 5 + day: 19 } } diff --git a/build.rs b/build.rs new file mode 100644 index 0000000..c4f341d --- /dev/null +++ b/build.rs @@ -0,0 +1,42 @@ +#![warn(rust_2018_idioms, single_use_lifetimes)] + +use std::env; + +include!("no_atomic_cas.rs"); + +// 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 have atomic CAS (compare-and-swap). +// 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 strings below are +// *not* public API. Please let us know by opening a GitHub issue if your build +// environment requires some way to enable these cfgs other than by executing +// our build script. +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_TARGETS.contains(&&*target) { + println!("cargo:rustc-cfg=futures_no_atomic_cas"); + } + + println!("cargo:rerun-if-changed=no_atomic_cas.rs"); +} diff --git a/no_atomic_cas.rs b/no_atomic_cas.rs new file mode 100644 index 0000000..0819af1 --- /dev/null +++ b/no_atomic_cas.rs @@ -0,0 +1,11 @@ +// This file is @generated by no_atomic_cas.sh. +// It is not intended for manual editing. + +const NO_ATOMIC_CAS_TARGETS: &[&str] = &[ + "avr-unknown-gnu-atmega328", + "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 373be24..48ec12b 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,8 +65,7 @@ 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() } } @@ -82,17 +81,13 @@ 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) } } } @@ -120,8 +115,7 @@ 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() } } @@ -130,7 +124,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) } } @@ -180,7 +174,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> @@ -189,8 +183,7 @@ 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> } @@ -200,7 +193,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> } @@ -209,8 +202,7 @@ 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> } } @@ -224,7 +216,8 @@ 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) @@ -257,7 +250,7 @@ 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(mut self) -> *mut (dyn Future<Output = T> + 'a) { let ptr = unsafe { self.as_mut().get_unchecked_mut() as *mut _ }; @@ -1,30 +1,24 @@ //! 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_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))] #![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"))] + #[cfg(not(futures_no_atomic_cas))] $item )*}; } mod spawn; -pub use crate::spawn::{Spawn, SpawnError, LocalSpawn}; +pub use crate::spawn::{LocalSpawn, Spawn, SpawnError}; cfg_target_has_atomic! { #[cfg(feature = "alloc")] @@ -51,4 +45,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, Waker, RawWaker, RawWakerVTable}; +pub use core::task::{Context, Poll, RawWaker, RawWakerVTable, Waker}; diff --git a/src/spawn.rs b/src/spawn.rs index a515dd4..50f5d0d 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> { diff --git a/src/waker.rs b/src/waker.rs index 265a445..a7310a0 100644 --- a/src/waker.rs +++ b/src/waker.rs @@ -1,7 +1,7 @@ use super::arc_wake::ArcWake; -use core::mem; -use core::task::{Waker, RawWaker, RawWakerVTable}; use alloc::sync::Arc; +use core::mem; +use core::task::{RawWaker, RawWakerVTable, Waker}; pub(super) fn waker_vtable<W: ArcWake>() -> &'static RawWakerVTable { &RawWakerVTable::new( @@ -22,9 +22,7 @@ where { 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 diff --git a/src/waker_ref.rs b/src/waker_ref.rs index 76d849a..791c690 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::mem::ManuallyDrop; use core::marker::PhantomData; +use core::mem::ManuallyDrop; use core::ops::Deref; -use core::task::{Waker, RawWaker}; +use core::task::{RawWaker, Waker}; /// A [`Waker`] that is only valid for a given lifetime. /// @@ -22,10 +22,7 @@ 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. @@ -35,10 +32,7 @@ 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 } } } @@ -57,14 +51,13 @@ 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 = (&**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) } |