Auto merge of #127840 - tgross35:rollup-jfkg1dq, r=tgross35

Rollup of 9 pull requests

Successful merges:

 - #125206 (Simplify environment variable examples)
 - #126271 (Skip fast path for dec2flt when optimize_for_size)
 - #126776 (Clean up more comments near use declarations)
 - #127444 (`impl Send + Sync` and override `count` for the `CStr::bytes` iterator)
 - #127512 (Terminate `--print link-args` output with newline)
 - #127792 (std: Use `read_unaligned` for reads from DWARF)
 - #127807 (Use futex.rs for Windows thread parking)
 - #127833 (zkvm: add `#[forbid(unsafe_op_in_unsafe_fn)]` in `stdlib`)
 - #127836 (std: Forbid unwrapped unsafe ops in xous and uefi modules)

Failed merges:

 - #127813 (Prevent double reference in generic futex)

r? `@ghost`
`@rustbot` modify labels: rollup
This commit is contained in:
bors 2024-07-17 03:31:18 +00:00
commit a28b35eb35
38 changed files with 126 additions and 97 deletions

View File

@ -750,7 +750,7 @@ fn link_natively(
for print in &sess.opts.prints { for print in &sess.opts.prints {
if print.kind == PrintKind::LinkArgs { if print.kind == PrintKind::LinkArgs {
let content = format!("{cmd:?}"); let content = format!("{cmd:?}\n");
print.out.overwrite(&content, sess); print.out.overwrite(&content, sess);
} }
} }

View File

@ -34,7 +34,6 @@ use super::{
Pointer, Projectable, Scalar, ValueVisitor, Pointer, Projectable, Scalar, ValueVisitor,
}; };
// for the validation errors
use super::InterpError::UndefinedBehavior as Ub; use super::InterpError::UndefinedBehavior as Ub;
use super::InterpError::Unsupported as Unsup; use super::InterpError::Unsupported as Unsup;
use super::UndefinedBehaviorInfo::*; use super::UndefinedBehaviorInfo::*;

View File

@ -120,7 +120,6 @@ use types::*;
use unit_bindings::*; use unit_bindings::*;
use unused::*; use unused::*;
/// Useful for other parts of the compiler / Clippy.
pub use builtin::{MissingDoc, SoftLints}; pub use builtin::{MissingDoc, SoftLints};
pub use context::{CheckLintNameResult, FindLintError, LintStore}; pub use context::{CheckLintNameResult, FindLintError, LintStore};
pub use context::{EarlyContext, LateContext, LintContext}; pub use context::{EarlyContext, LateContext, LintContext};

View File

@ -21,9 +21,7 @@ rustc_fluent_macro::fluent_messages! { "../messages.ftl" }
use std::fmt; use std::fmt;
// Re-exports to avoid rustc_index version issues. pub use rustc_index::{Idx, IndexVec}; // re-exported to avoid rustc_index version issues
pub use rustc_index::Idx;
pub use rustc_index::IndexVec;
#[cfg(feature = "rustc")] #[cfg(feature = "rustc")]
use rustc_middle::ty::Ty; use rustc_middle::ty::Ty;

View File

@ -4,6 +4,7 @@
//! due to incomplete stable coverage. //! due to incomplete stable coverage.
// Prefer importing stable_mir over internal rustc constructs to make this file more readable. // Prefer importing stable_mir over internal rustc constructs to make this file more readable.
use crate::rustc_smir::Tables; use crate::rustc_smir::Tables;
use rustc_middle::ty::{self as rustc_ty, Const as InternalConst, Ty as InternalTy, TyCtxt}; use rustc_middle::ty::{self as rustc_ty, Const as InternalConst, Ty as InternalTy, TyCtxt};
use rustc_span::Symbol; use rustc_span::Symbol;

View File

@ -1,5 +1,4 @@
// We avoid relying on anything else in the crate, apart from the `Debug` trait. use crate::fmt::Debug; // the `Debug` trait is the only thing we use from `crate::fmt`
use crate::fmt::Debug;
use std::cmp::Ordering; use std::cmp::Ordering;
use std::sync::atomic::{AtomicUsize, Ordering::SeqCst}; use std::sync::atomic::{AtomicUsize, Ordering::SeqCst};

View File

@ -24,7 +24,6 @@ mod convert;
mod decode; mod decode;
mod methods; mod methods;
// stable re-exports
#[stable(feature = "try_from", since = "1.34.0")] #[stable(feature = "try_from", since = "1.34.0")]
pub use self::convert::CharTryFromError; pub use self::convert::CharTryFromError;
#[stable(feature = "char_from_str", since = "1.20.0")] #[stable(feature = "char_from_str", since = "1.20.0")]
@ -32,11 +31,10 @@ pub use self::convert::ParseCharError;
#[stable(feature = "decode_utf16", since = "1.9.0")] #[stable(feature = "decode_utf16", since = "1.9.0")]
pub use self::decode::{DecodeUtf16, DecodeUtf16Error}; pub use self::decode::{DecodeUtf16, DecodeUtf16Error};
// perma-unstable re-exports
#[unstable(feature = "char_internals", reason = "exposed only for libstd", issue = "none")] #[unstable(feature = "char_internals", reason = "exposed only for libstd", issue = "none")]
pub use self::methods::encode_utf16_raw; pub use self::methods::encode_utf16_raw; // perma-unstable
#[unstable(feature = "char_internals", reason = "exposed only for libstd", issue = "none")] #[unstable(feature = "char_internals", reason = "exposed only for libstd", issue = "none")]
pub use self::methods::encode_utf8_raw; pub use self::methods::encode_utf8_raw; // perma-unstable
use crate::ascii; use crate::ascii;
use crate::error::Error; use crate::error::Error;

View File

@ -781,8 +781,15 @@ const unsafe fn strlen(ptr: *const c_char) -> usize {
pub struct Bytes<'a> { pub struct Bytes<'a> {
// since we know the string is nul-terminated, we only need one pointer // since we know the string is nul-terminated, we only need one pointer
ptr: NonNull<u8>, ptr: NonNull<u8>,
phantom: PhantomData<&'a u8>, phantom: PhantomData<&'a [c_char]>,
} }
#[unstable(feature = "cstr_bytes", issue = "112115")]
unsafe impl Send for Bytes<'_> {}
#[unstable(feature = "cstr_bytes", issue = "112115")]
unsafe impl Sync for Bytes<'_> {}
impl<'a> Bytes<'a> { impl<'a> Bytes<'a> {
#[inline] #[inline]
fn new(s: &'a CStr) -> Self { fn new(s: &'a CStr) -> Self {
@ -815,7 +822,7 @@ impl Iterator for Bytes<'_> {
if ret == 0 { if ret == 0 {
None None
} else { } else {
self.ptr = self.ptr.offset(1); self.ptr = self.ptr.add(1);
Some(ret) Some(ret)
} }
} }
@ -825,6 +832,12 @@ impl Iterator for Bytes<'_> {
fn size_hint(&self) -> (usize, Option<usize>) { fn size_hint(&self) -> (usize, Option<usize>) {
if self.is_empty() { (0, Some(0)) } else { (1, None) } if self.is_empty() { (0, Some(0)) } else { (1, None) }
} }
#[inline]
fn count(self) -> usize {
// SAFETY: We always hold a valid pointer to a C string
unsafe { strlen(self.ptr.as_ptr().cast()) }
}
} }
#[unstable(feature = "cstr_bytes", issue = "112115")] #[unstable(feature = "cstr_bytes", issue = "112115")]

View File

@ -250,8 +250,10 @@ pub fn dec2flt<F: RawFloat>(s: &str) -> Result<F, ParseFloatError> {
None => return Err(pfe_invalid()), None => return Err(pfe_invalid()),
}; };
num.negative = negative; num.negative = negative;
if let Some(value) = num.try_fast_path::<F>() { if !cfg!(feature = "optimize_for_size") {
return Ok(value); if let Some(value) = num.try_fast_path::<F>() {
return Ok(value);
}
} }
// If significant digits were truncated, then we can have rounding error // If significant digits were truncated, then we can have rounding error

View File

@ -2,6 +2,9 @@
//! //!
//! See the [module-level documentation](super) for more. //! See the [module-level documentation](super) for more.
// No formatting: this file is nothing but re-exports, and their order is worth preserving.
#![cfg_attr(rustfmt, rustfmt::skip)]
// Re-exported core operators // Re-exported core operators
#[stable(feature = "core_prelude", since = "1.4.0")] #[stable(feature = "core_prelude", since = "1.4.0")]
#[doc(no_inline)] #[doc(no_inline)]
@ -33,10 +36,7 @@ pub use crate::convert::{AsMut, AsRef, From, Into};
pub use crate::default::Default; pub use crate::default::Default;
#[stable(feature = "core_prelude", since = "1.4.0")] #[stable(feature = "core_prelude", since = "1.4.0")]
#[doc(no_inline)] #[doc(no_inline)]
pub use crate::iter::{DoubleEndedIterator, ExactSizeIterator}; pub use crate::iter::{DoubleEndedIterator, ExactSizeIterator, Extend, IntoIterator, Iterator};
#[stable(feature = "core_prelude", since = "1.4.0")]
#[doc(no_inline)]
pub use crate::iter::{Extend, IntoIterator, Iterator};
#[stable(feature = "core_prelude", since = "1.4.0")] #[stable(feature = "core_prelude", since = "1.4.0")]
#[doc(no_inline)] #[doc(no_inline)]
pub use crate::option::Option::{self, None, Some}; pub use crate::option::Option::{self, None, Some};

View File

@ -4,6 +4,9 @@
//! This module is imported by default when `#![no_std]` is used in the same //! This module is imported by default when `#![no_std]` is used in the same
//! manner as the standard library's prelude. //! manner as the standard library's prelude.
// No formatting: this file is nothing but re-exports, and their order is worth preserving.
#![cfg_attr(rustfmt, rustfmt::skip)]
#![stable(feature = "core_prelude", since = "1.4.0")] #![stable(feature = "core_prelude", since = "1.4.0")]
mod common; mod common;

View File

@ -1809,10 +1809,9 @@ pub(crate) const unsafe fn align_offset<T: Sized>(p: *const T, a: usize) -> usiz
// FIXME(#75598): Direct use of these intrinsics improves codegen significantly at opt-level <= // FIXME(#75598): Direct use of these intrinsics improves codegen significantly at opt-level <=
// 1, where the method versions of these operations are not inlined. // 1, where the method versions of these operations are not inlined.
use intrinsics::{ use intrinsics::{
assume, cttz_nonzero, exact_div, mul_with_overflow, unchecked_rem, unchecked_sub, assume, cttz_nonzero, exact_div, mul_with_overflow, unchecked_rem, unchecked_shl,
wrapping_add, wrapping_mul, wrapping_sub, unchecked_shr, unchecked_sub, wrapping_add, wrapping_mul, wrapping_sub,
}; };
use intrinsics::{unchecked_shl, unchecked_shr};
/// Calculate multiplicative modular inverse of `x` modulo `m`. /// Calculate multiplicative modular inverse of `x` modulo `m`.
/// ///

View File

@ -1,6 +1,19 @@
#![unstable(feature = "unicode_internals", issue = "none")] #![unstable(feature = "unicode_internals", issue = "none")]
#![allow(missing_docs)] #![allow(missing_docs)]
// The `pub use` ones are for use in alloc, and are not re-exported in std.
pub(crate) use unicode_data::alphabetic::lookup as Alphabetic;
pub use unicode_data::case_ignorable::lookup as Case_Ignorable;
pub use unicode_data::cased::lookup as Cased;
pub(crate) use unicode_data::cc::lookup as Cc;
pub use unicode_data::conversions;
pub(crate) use unicode_data::grapheme_extend::lookup as Grapheme_Extend;
pub(crate) use unicode_data::lowercase::lookup as Lowercase;
pub(crate) use unicode_data::n::lookup as N;
pub(crate) use unicode_data::uppercase::lookup as Uppercase;
pub(crate) use unicode_data::white_space::lookup as White_Space;
pub(crate) mod printable; pub(crate) mod printable;
mod unicode_data; mod unicode_data;
@ -16,16 +29,3 @@ mod unicode_data;
/// [Unicode 11.0 or later, Section 3.1 Versions of the Unicode Standard](https://www.unicode.org/versions/Unicode11.0.0/ch03.pdf#page=4). /// [Unicode 11.0 or later, Section 3.1 Versions of the Unicode Standard](https://www.unicode.org/versions/Unicode11.0.0/ch03.pdf#page=4).
#[stable(feature = "unicode_version", since = "1.45.0")] #[stable(feature = "unicode_version", since = "1.45.0")]
pub const UNICODE_VERSION: (u8, u8, u8) = unicode_data::UNICODE_VERSION; pub const UNICODE_VERSION: (u8, u8, u8) = unicode_data::UNICODE_VERSION;
// For use in alloc, not re-exported in std.
pub use unicode_data::{
case_ignorable::lookup as Case_Ignorable, cased::lookup as Cased, conversions,
};
pub(crate) use unicode_data::alphabetic::lookup as Alphabetic;
pub(crate) use unicode_data::cc::lookup as Cc;
pub(crate) use unicode_data::grapheme_extend::lookup as Grapheme_Extend;
pub(crate) use unicode_data::lowercase::lookup as Lowercase;
pub(crate) use unicode_data::n::lookup as N;
pub(crate) use unicode_data::uppercase::lookup as Uppercase;
pub(crate) use unicode_data::white_space::lookup as White_Space;

View File

@ -120,11 +120,8 @@ pub struct VarsOs {
/// # Examples /// # Examples
/// ///
/// ``` /// ```
/// use std::env; /// // Print all environment variables.
/// /// for (key, value) in std::env::vars() {
/// // We will iterate through the references to the element returned by
/// // env::vars();
/// for (key, value) in env::vars() {
/// println!("{key}: {value}"); /// println!("{key}: {value}");
/// } /// }
/// ``` /// ```
@ -150,11 +147,8 @@ pub fn vars() -> Vars {
/// # Examples /// # Examples
/// ///
/// ``` /// ```
/// use std::env; /// // Print all environment variables.
/// /// for (key, value) in std::env::vars_os() {
/// // We will iterate through the references to the element returned by
/// // env::vars_os();
/// for (key, value) in env::vars_os() {
/// println!("{key:?}: {value:?}"); /// println!("{key:?}: {value:?}");
/// } /// }
/// ``` /// ```

View File

@ -470,7 +470,6 @@ pub mod rt;
// The Rust prelude // The Rust prelude
pub mod prelude; pub mod prelude;
// Public module declarations and re-exports
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
pub use alloc_crate::borrow; pub use alloc_crate::borrow;
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]

View File

@ -28,7 +28,6 @@ pub mod usercalls {
pub use crate::sys::abi::usercalls::raw::{do_usercall, Usercalls as UsercallNrs}; pub use crate::sys::abi::usercalls::raw::{do_usercall, Usercalls as UsercallNrs};
pub use crate::sys::abi::usercalls::raw::{Register, RegisterArgument, ReturnValue}; pub use crate::sys::abi::usercalls::raw::{Register, RegisterArgument, ReturnValue};
// fortanix-sgx-abi re-exports
pub use crate::sys::abi::usercalls::raw::Error; pub use crate::sys::abi::usercalls::raw::Error;
pub use crate::sys::abi::usercalls::raw::{ pub use crate::sys::abi::usercalls::raw::{
ByteBuffer, Cancel, FifoDescriptor, Return, Usercall, ByteBuffer, Cancel, FifoDescriptor, Return, Usercall,

View File

@ -2,6 +2,7 @@
#![unstable(feature = "uefi_std", issue = "100499")] #![unstable(feature = "uefi_std", issue = "100499")]
#![doc(cfg(target_os = "uefi"))] #![doc(cfg(target_os = "uefi"))]
#![forbid(unsafe_op_in_unsafe_fn)]
pub mod env; pub mod env;
#[path = "../windows/ffi.rs"] #[path = "../windows/ffi.rs"]

View File

@ -1,5 +1,6 @@
#![stable(feature = "rust1", since = "1.0.0")] #![stable(feature = "rust1", since = "1.0.0")]
#![doc(cfg(target_os = "xous"))] #![doc(cfg(target_os = "xous"))]
#![forbid(unsafe_op_in_unsafe_fn)]
pub mod ffi; pub mod ffi;

View File

@ -2,6 +2,9 @@
//! //!
//! See the [module-level documentation](super) for more. //! See the [module-level documentation](super) for more.
// No formatting: this file is nothing but re-exports, and their order is worth preserving.
#![cfg_attr(rustfmt, rustfmt::skip)]
// Re-exported core operators // Re-exported core operators
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
#[doc(no_inline)] #[doc(no_inline)]

View File

@ -95,6 +95,9 @@
//! [book-enums]: ../../book/ch06-01-defining-an-enum.html //! [book-enums]: ../../book/ch06-01-defining-an-enum.html
//! [book-iter]: ../../book/ch13-02-iterators.html //! [book-iter]: ../../book/ch13-02-iterators.html
// No formatting: this file is nothing but re-exports, and their order is worth preserving.
#![cfg_attr(rustfmt, rustfmt::skip)]
#![stable(feature = "rust1", since = "1.0.0")] #![stable(feature = "rust1", since = "1.0.0")]
mod common; mod common;

View File

@ -16,7 +16,6 @@
#![deny(unsafe_op_in_unsafe_fn)] #![deny(unsafe_op_in_unsafe_fn)]
#![allow(unused_macros)] #![allow(unused_macros)]
// Re-export some of our utilities which are expected by other crates.
pub use crate::panicking::{begin_panic, panic_count}; pub use crate::panicking::{begin_panic, panic_count};
pub use core::panicking::{panic_display, panic_fmt}; pub use core::panicking::{panic_display, panic_fmt};

View File

@ -3,6 +3,11 @@ use crate::ptr::null;
use crate::sync::atomic::AtomicU32; use crate::sync::atomic::AtomicU32;
use crate::time::Duration; use crate::time::Duration;
/// An atomic for use as a futex that is at least 8-bits but may be larger.
pub type SmallAtomic = AtomicU32;
/// Must be the underlying type of SmallAtomic
pub type SmallPrimitive = u32;
pub fn futex_wait(futex: &AtomicU32, expected: u32, timeout: Option<Duration>) -> bool { pub fn futex_wait(futex: &AtomicU32, expected: u32, timeout: Option<Duration>) -> bool {
// Calculate the timeout as a relative timespec. // Calculate the timeout as a relative timespec.
// //

View File

@ -11,6 +11,7 @@
//! //!
//! [`OsStr`]: crate::ffi::OsStr //! [`OsStr`]: crate::ffi::OsStr
//! [`OsString`]: crate::ffi::OsString //! [`OsString`]: crate::ffi::OsString
#![forbid(unsafe_op_in_unsafe_fn)]
pub mod alloc; pub mod alloc;
pub mod args; pub mod args;

View File

@ -11,6 +11,11 @@
use crate::sync::atomic::AtomicU32; use crate::sync::atomic::AtomicU32;
use crate::time::Duration; use crate::time::Duration;
/// An atomic for use as a futex that is at least 8-bits but may be larger.
pub type SmallAtomic = AtomicU32;
/// Must be the underlying type of SmallAtomic
pub type SmallPrimitive = u32;
/// Wait for a futex_wake operation to wake us. /// Wait for a futex_wake operation to wake us.
/// ///
/// Returns directly if the futex doesn't hold the expected value. /// Returns directly if the futex doesn't hold the expected value.

View File

@ -39,12 +39,15 @@ pub mod time;
#[deny(unsafe_op_in_unsafe_fn)] #[deny(unsafe_op_in_unsafe_fn)]
#[allow(unused)] #[allow(unused)]
mod common; mod common;
pub use common::*; pub use common::*;
mod helpers; mod helpers;
// These exports are listed individually to work around Rust's glob import
// conflict rules. If we glob export `helpers` and `common` together, then // The following exports are listed individually to work around Rust's glob
// the compiler complains about conflicts. // import conflict rules. If we glob export `helpers` and `common` together,
// then the compiler complains about conflicts.
pub use helpers::abort_internal; pub use helpers::abort_internal;
pub use helpers::decode_error_kind; pub use helpers::decode_error_kind;
use helpers::err2io; use helpers::err2io;

View File

@ -41,13 +41,16 @@ pub mod time;
#[deny(unsafe_op_in_unsafe_fn)] #[deny(unsafe_op_in_unsafe_fn)]
#[allow(unused)] #[allow(unused)]
mod common; mod common;
pub use common::*; pub use common::*;
#[path = "../wasi/helpers.rs"] #[path = "../wasi/helpers.rs"]
mod helpers; mod helpers;
// These exports are listed individually to work around Rust's glob import
// conflict rules. If we glob export `helpers` and `common` together, then // The following exports are listed individually to work around Rust's glob
// the compiler complains about conflicts. // import conflict rules. If we glob export `helpers` and `common` together,
// then the compiler complains about conflicts.
pub use helpers::abort_internal; pub use helpers::abort_internal;
pub use helpers::decode_error_kind; pub use helpers::decode_error_kind;
use helpers::err2io; use helpers::err2io;

View File

@ -6,6 +6,11 @@ use core::arch::wasm64 as wasm;
use crate::sync::atomic::AtomicU32; use crate::sync::atomic::AtomicU32;
use crate::time::Duration; use crate::time::Duration;
/// An atomic for use as a futex that is at least 8-bits but may be larger.
pub type SmallAtomic = AtomicU32;
/// Must be the underlying type of SmallAtomic
pub type SmallPrimitive = u32;
/// Wait for a futex_wake operation to wake us. /// Wait for a futex_wake operation to wake us.
/// ///
/// Returns directly if the futex doesn't hold the expected value. /// Returns directly if the futex doesn't hold the expected value.

View File

@ -10,6 +10,11 @@ use core::sync::atomic::{
}; };
use core::time::Duration; use core::time::Duration;
/// An atomic for use as a futex that is at least 8-bits but may be larger.
pub type SmallAtomic = AtomicU8;
/// Must be the underlying type of SmallAtomic
pub type SmallPrimitive = u8;
pub unsafe trait Waitable { pub unsafe trait Waitable {
type Atomic; type Atomic;
} }

View File

@ -1,4 +1,4 @@
#![deny(unsafe_op_in_unsafe_fn)] #![forbid(unsafe_op_in_unsafe_fn)]
pub mod alloc; pub mod alloc;
#[path = "../unsupported/args.rs"] #[path = "../unsupported/args.rs"]

View File

@ -5,7 +5,7 @@ use crate::alloc::{GlobalAlloc, Layout, System};
unsafe impl GlobalAlloc for System { unsafe impl GlobalAlloc for System {
#[inline] #[inline]
unsafe fn alloc(&self, layout: Layout) -> *mut u8 { unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
abi::sys_alloc_aligned(layout.size(), layout.align()) unsafe { abi::sys_alloc_aligned(layout.size(), layout.align()) }
} }
#[inline] #[inline]

View File

@ -6,6 +6,7 @@
//! This is all super highly experimental and not actually intended for //! This is all super highly experimental and not actually intended for
//! wide/production use yet, it's still all in the experimental category. This //! wide/production use yet, it's still all in the experimental category. This
//! will likely change over time. //! will likely change over time.
#![forbid(unsafe_op_in_unsafe_fn)]
const WORD_SIZE: usize = core::mem::size_of::<u32>(); const WORD_SIZE: usize = core::mem::size_of::<u32>();

View File

@ -17,32 +17,30 @@ pub struct DwarfReader {
pub ptr: *const u8, pub ptr: *const u8,
} }
#[repr(C, packed)] #[forbid(unsafe_op_in_unsafe_fn)]
struct Unaligned<T>(T);
impl DwarfReader { impl DwarfReader {
pub fn new(ptr: *const u8) -> DwarfReader { pub fn new(ptr: *const u8) -> DwarfReader {
DwarfReader { ptr } DwarfReader { ptr }
} }
// DWARF streams are packed, so e.g., a u32 would not necessarily be aligned /// Read a type T and then bump the pointer by that amount.
// on a 4-byte boundary. This may cause problems on platforms with strict ///
// alignment requirements. By wrapping data in a "packed" struct, we are /// DWARF streams are "packed", so all types must be read at align 1.
// telling the backend to generate "misalignment-safe" code.
pub unsafe fn read<T: Copy>(&mut self) -> T { pub unsafe fn read<T: Copy>(&mut self) -> T {
let Unaligned(result) = *(self.ptr as *const Unaligned<T>); unsafe {
self.ptr = self.ptr.add(mem::size_of::<T>()); let result = self.ptr.cast::<T>().read_unaligned();
result self.ptr = self.ptr.byte_add(mem::size_of::<T>());
result
}
} }
// ULEB128 and SLEB128 encodings are defined in Section 7.6 - "Variable /// ULEB128 and SLEB128 encodings are defined in Section 7.6 - "Variable Length Data".
// Length Data".
pub unsafe fn read_uleb128(&mut self) -> u64 { pub unsafe fn read_uleb128(&mut self) -> u64 {
let mut shift: usize = 0; let mut shift: usize = 0;
let mut result: u64 = 0; let mut result: u64 = 0;
let mut byte: u8; let mut byte: u8;
loop { loop {
byte = self.read::<u8>(); byte = unsafe { self.read::<u8>() };
result |= ((byte & 0x7F) as u64) << shift; result |= ((byte & 0x7F) as u64) << shift;
shift += 7; shift += 7;
if byte & 0x80 == 0 { if byte & 0x80 == 0 {
@ -57,7 +55,7 @@ impl DwarfReader {
let mut result: u64 = 0; let mut result: u64 = 0;
let mut byte: u8; let mut byte: u8;
loop { loop {
byte = self.read::<u8>(); byte = unsafe { self.read::<u8>() };
result |= ((byte & 0x7F) as u64) << shift; result |= ((byte & 0x7F) as u64) << shift;
shift += 7; shift += 7;
if byte & 0x80 == 0 { if byte & 0x80 == 0 {

View File

@ -1,19 +1,8 @@
use crate::sync::atomic::{ use crate::sync::atomic::Ordering::{Acquire, Relaxed, Release};
self, use crate::sys::futex::{self, futex_wait, futex_wake};
Ordering::{Acquire, Relaxed, Release},
};
use crate::sys::futex::{futex_wait, futex_wake};
cfg_if::cfg_if! { type Atomic = futex::SmallAtomic;
if #[cfg(windows)] { type State = futex::SmallPrimitive;
// On Windows we can have a smol futex
type Atomic = atomic::AtomicU8;
type State = u8;
} else {
type Atomic = atomic::AtomicU32;
type State = u32;
}
}
pub struct Mutex { pub struct Mutex {
futex: Atomic, futex: Atomic,

View File

@ -1,15 +1,18 @@
#![forbid(unsafe_op_in_unsafe_fn)]
use crate::pin::Pin; use crate::pin::Pin;
use crate::sync::atomic::AtomicU32;
use crate::sync::atomic::Ordering::{Acquire, Release}; use crate::sync::atomic::Ordering::{Acquire, Release};
use crate::sys::futex::{futex_wait, futex_wake}; use crate::sys::futex::{self, futex_wait, futex_wake};
use crate::time::Duration; use crate::time::Duration;
const PARKED: u32 = u32::MAX; type Atomic = futex::SmallAtomic;
const EMPTY: u32 = 0; type State = futex::SmallPrimitive;
const NOTIFIED: u32 = 1;
const PARKED: State = State::MAX;
const EMPTY: State = 0;
const NOTIFIED: State = 1;
pub struct Parker { pub struct Parker {
state: AtomicU32, state: Atomic,
} }
// Notes about memory ordering: // Notes about memory ordering:
@ -36,7 +39,7 @@ impl Parker {
/// Construct the futex parker. The UNIX parker implementation /// Construct the futex parker. The UNIX parker implementation
/// requires this to happen in-place. /// requires this to happen in-place.
pub unsafe fn new_in_place(parker: *mut Parker) { pub unsafe fn new_in_place(parker: *mut Parker) {
parker.write(Self { state: AtomicU32::new(EMPTY) }); unsafe { parker.write(Self { state: Atomic::new(EMPTY) }) };
} }
// Assumes this is only called by the thread that owns the Parker, // Assumes this is only called by the thread that owns the Parker,

View File

@ -1,5 +1,6 @@
cfg_if::cfg_if! { cfg_if::cfg_if! {
if #[cfg(any( if #[cfg(any(
all(target_os = "windows", not(target_vendor = "win7")),
target_os = "linux", target_os = "linux",
target_os = "android", target_os = "android",
all(target_arch = "wasm32", target_feature = "atomics"), all(target_arch = "wasm32", target_feature = "atomics"),
@ -18,9 +19,9 @@ cfg_if::cfg_if! {
))] { ))] {
mod id; mod id;
pub use id::Parker; pub use id::Parker;
} else if #[cfg(target_os = "windows")] { } else if #[cfg(target_vendor = "win7")] {
mod windows; mod windows7;
pub use windows::Parker; pub use windows7::Parker;
} else if #[cfg(all(target_vendor = "apple", not(miri)))] { } else if #[cfg(all(target_vendor = "apple", not(miri)))] {
mod darwin; mod darwin;
pub use darwin::Parker; pub use darwin::Parker;

View File

@ -25,7 +25,6 @@
#![feature(test)] #![feature(test)]
#![allow(internal_features)] #![allow(internal_features)]
// Public reexports
pub use self::bench::{black_box, Bencher}; pub use self::bench::{black_box, Bencher};
pub use self::console::run_tests_console; pub use self::console::run_tests_console;
pub use self::options::{ColorConfig, Options, OutputFormat, RunIgnored, ShouldPanic}; pub use self::options::{ColorConfig, Options, OutputFormat, RunIgnored, ShouldPanic};

View File

@ -17,4 +17,5 @@ fn main() {
.run_unchecked(); .run_unchecked();
out.assert_stdout_contains("lfoo"); out.assert_stdout_contains("lfoo");
out.assert_stdout_contains("lbar"); out.assert_stdout_contains("lbar");
assert!(out.stdout_utf8().ends_with('\n'));
} }