From da4df8700cb9390cb8455b661f94b403027bdf7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Linus=20F=C3=A4rnstrand?= Date: Tue, 5 Nov 2019 21:37:32 +0100 Subject: [PATCH] Remove pre 1.36 backwards compatibility code --- build.rs | 7 ---- core/build.rs | 9 ---- core/src/lib.rs | 1 - core/src/maybe_uninit.rs | 41 ------------------- core/src/thread_parker/cloudabi.rs | 3 +- core/src/thread_parker/mod.rs | 4 +- core/src/thread_parker/unix.rs | 6 ++- core/src/thread_parker/windows/keyed_event.rs | 6 ++- src/once.rs | 19 +++------ src/raw_mutex.rs | 18 +++----- src/util.rs | 7 +--- 11 files changed, 23 insertions(+), 98 deletions(-) delete mode 100644 build.rs delete mode 100644 core/build.rs delete mode 100644 core/src/maybe_uninit.rs diff --git a/build.rs b/build.rs deleted file mode 100644 index e014fbb3..00000000 --- a/build.rs +++ /dev/null @@ -1,7 +0,0 @@ -fn main() { - let cfg = autocfg::new(); - if cfg.probe_rustc_version(1, 34) { - println!("cargo:rustc-cfg=has_sized_atomics"); - println!("cargo:rustc-cfg=has_checked_instant"); - } -} diff --git a/core/build.rs b/core/build.rs deleted file mode 100644 index 19bdd7a5..00000000 --- a/core/build.rs +++ /dev/null @@ -1,9 +0,0 @@ -fn main() { - let cfg = autocfg::new(); - if cfg.probe_rustc_version(1, 34) { - println!("cargo:rustc-cfg=has_sized_atomics"); - } - if cfg.probe_rustc_version(1, 36) { - println!("cargo:rustc-cfg=has_maybe_uninit"); - } -} diff --git a/core/src/lib.rs b/core/src/lib.rs index 6ff954b3..6fad7801 100644 --- a/core/src/lib.rs +++ b/core/src/lib.rs @@ -56,7 +56,6 @@ feature(thread_local, checked_duration_since) )] -mod maybe_uninit; mod parking_lot; mod spinwait; mod thread_parker; diff --git a/core/src/maybe_uninit.rs b/core/src/maybe_uninit.rs deleted file mode 100644 index 2562e3c2..00000000 --- a/core/src/maybe_uninit.rs +++ /dev/null @@ -1,41 +0,0 @@ -//! This module contains a re-export or vendored version of `core::mem::MaybeUninit` depending -//! on which Rust version it's compiled for. -//! -//! Remove this module and use `core::mem::MaybeUninit` directly when dropping support for <1.36 -#![allow(dead_code)] - -#[cfg(has_maybe_uninit)] -pub use core::mem::MaybeUninit; - -#[cfg(not(has_maybe_uninit))] -use core::mem::ManuallyDrop; - -/// Copied from `core::mem::MaybeUninit` to support Rust older than 1.36 -#[cfg(not(has_maybe_uninit))] -pub union MaybeUninit { - uninit: (), - value: ManuallyDrop, -} - -#[cfg(not(has_maybe_uninit))] -impl MaybeUninit { - #[inline] - pub fn uninit() -> MaybeUninit { - MaybeUninit { uninit: () } - } - - #[inline] - pub fn as_ptr(&self) -> *const T { - unsafe { &*self.value as *const T } - } - - #[inline] - pub fn as_mut_ptr(&mut self) -> *mut T { - unsafe { &mut *self.value as *mut T } - } - - #[inline] - pub unsafe fn assume_init(self) -> T { - ManuallyDrop::into_inner(self.value) - } -} diff --git a/core/src/thread_parker/cloudabi.rs b/core/src/thread_parker/cloudabi.rs index a3195529..520cc729 100644 --- a/core/src/thread_parker/cloudabi.rs +++ b/core/src/thread_parker/cloudabi.rs @@ -5,11 +5,10 @@ // http://opensource.org/licenses/MIT>, at your option. This file may not be // copied, modified, or distributed except according to those terms. -use crate::maybe_uninit::MaybeUninit; use cloudabi as abi; use core::{ cell::Cell, - mem, + mem::{self, MaybeUninit}, sync::atomic::{AtomicU32, Ordering}, }; use std::{convert::TryFrom, thread, time::Instant}; diff --git a/core/src/thread_parker/mod.rs b/core/src/thread_parker/mod.rs index 7b442630..4c721c3d 100644 --- a/core/src/thread_parker/mod.rs +++ b/core/src/thread_parker/mod.rs @@ -51,7 +51,7 @@ pub trait UnparkHandleT { } cfg_if! { - if #[cfg(all(has_sized_atomics, any(target_os = "linux", target_os = "android")))] { + if #[cfg(any(target_os = "linux", target_os = "android"))] { #[path = "linux.rs"] mod imp; } else if #[cfg(unix)] { @@ -60,7 +60,7 @@ cfg_if! { } else if #[cfg(windows)] { #[path = "windows/mod.rs"] mod imp; - } else if #[cfg(all(has_sized_atomics, target_os = "redox"))] { + } else if #[cfg(target_os = "redox")] { #[path = "redox.rs"] mod imp; } else if #[cfg(all(target_env = "sgx", target_vendor = "fortanix"))] { diff --git a/core/src/thread_parker/unix.rs b/core/src/thread_parker/unix.rs index 2710563d..e61ab623 100644 --- a/core/src/thread_parker/unix.rs +++ b/core/src/thread_parker/unix.rs @@ -5,10 +5,12 @@ // http://opensource.org/licenses/MIT>, at your option. This file may not be // copied, modified, or distributed except according to those terms. -use crate::maybe_uninit::MaybeUninit; -use core::cell::{Cell, UnsafeCell}; #[cfg(any(target_os = "macos", target_os = "ios"))] use core::ptr; +use core::{ + cell::{Cell, UnsafeCell}, + mem::MaybeUninit, +}; use libc; use std::{ thread, diff --git a/core/src/thread_parker/windows/keyed_event.rs b/core/src/thread_parker/windows/keyed_event.rs index 39d1e329..7b516fe1 100644 --- a/core/src/thread_parker/windows/keyed_event.rs +++ b/core/src/thread_parker/windows/keyed_event.rs @@ -5,8 +5,10 @@ // http://opensource.org/licenses/MIT>, at your option. This file may not be // copied, modified, or distributed except according to those terms. -use crate::maybe_uninit::MaybeUninit; -use core::{mem, ptr}; +use core::{ + mem::{self, MaybeUninit}, + ptr, +}; use std::{ sync::atomic::{AtomicUsize, Ordering}, time::Instant, diff --git a/src/once.rs b/src/once.rs index b86c58b4..ae6f2bcd 100644 --- a/src/once.rs +++ b/src/once.rs @@ -6,25 +6,16 @@ // copied, modified, or distributed except according to those terms. use crate::util::UncheckedOptionExt; -#[cfg(has_sized_atomics)] -use core::sync::atomic::AtomicU8; -#[cfg(not(has_sized_atomics))] -use core::sync::atomic::AtomicUsize as AtomicU8; use core::{ fmt, mem, - sync::atomic::{fence, Ordering}, + sync::atomic::{fence, AtomicU8, Ordering}, }; use parking_lot_core::{self, SpinWait, DEFAULT_PARK_TOKEN, DEFAULT_UNPARK_TOKEN}; -#[cfg(has_sized_atomics)] -type U8 = u8; -#[cfg(not(has_sized_atomics))] -type U8 = usize; - -const DONE_BIT: U8 = 1; -const POISON_BIT: U8 = 2; -const LOCKED_BIT: U8 = 4; -const PARKED_BIT: U8 = 8; +const DONE_BIT: u8 = 1; +const POISON_BIT: u8 = 2; +const LOCKED_BIT: u8 = 4; +const PARKED_BIT: u8 = 8; /// Current state of a `Once`. #[derive(Copy, Clone, Eq, PartialEq, Debug)] diff --git a/src/raw_mutex.rs b/src/raw_mutex.rs index 436b0fd9..ee39c3bd 100644 --- a/src/raw_mutex.rs +++ b/src/raw_mutex.rs @@ -6,20 +6,14 @@ // copied, modified, or distributed except according to those terms. use crate::{deadlock, util}; -#[cfg(has_sized_atomics)] -use core::sync::atomic::AtomicU8; -#[cfg(not(has_sized_atomics))] -use core::sync::atomic::AtomicUsize as AtomicU8; -use core::{sync::atomic::Ordering, time::Duration}; +use core::{ + sync::atomic::{AtomicU8, Ordering}, + time::Duration, +}; use lock_api::{GuardNoSend, RawMutex as RawMutex_}; use parking_lot_core::{self, ParkResult, SpinWait, UnparkResult, UnparkToken, DEFAULT_PARK_TOKEN}; use std::time::Instant; -#[cfg(has_sized_atomics)] -type U8 = u8; -#[cfg(not(has_sized_atomics))] -type U8 = usize; - // UnparkToken used to indicate that that the target thread should attempt to // lock the mutex again as soon as it is unparked. pub(crate) const TOKEN_NORMAL: UnparkToken = UnparkToken(0); @@ -29,10 +23,10 @@ pub(crate) const TOKEN_NORMAL: UnparkToken = UnparkToken(0); pub(crate) const TOKEN_HANDOFF: UnparkToken = UnparkToken(1); /// This bit is set in the `state` of a `RawMutex` when that mutex is locked by some thread. -const LOCKED_BIT: U8 = 0b01; +const LOCKED_BIT: u8 = 0b01; /// This bit is set in the `state` of a `RawMutex` just before parking a thread. A thread is being /// parked if it wants to lock the mutex, but it is currently being held by some other thread. -const PARKED_BIT: U8 = 0b10; +const PARKED_BIT: u8 = 0b10; /// Raw mutex type backed by the parking lot. pub struct RawMutex { diff --git a/src/util.rs b/src/util.rs index 90e008b9..c5496fc0 100644 --- a/src/util.rs +++ b/src/util.rs @@ -34,10 +34,5 @@ unsafe fn unreachable() -> ! { #[inline] pub fn to_deadline(timeout: Duration) -> Option { - #[cfg(has_checked_instant)] - let deadline = Instant::now().checked_add(timeout); - #[cfg(not(has_checked_instant))] - let deadline = Some(Instant::now() + timeout); - - deadline + Instant::now().checked_add(timeout) }