Skip to content

Commit a28b35e

Browse files
committed
Auto merge of rust-lang#127840 - tgross35:rollup-jfkg1dq, r=tgross35
Rollup of 9 pull requests Successful merges: - rust-lang#125206 (Simplify environment variable examples) - rust-lang#126271 (Skip fast path for dec2flt when optimize_for_size) - rust-lang#126776 (Clean up more comments near use declarations) - rust-lang#127444 (`impl Send + Sync` and override `count` for the `CStr::bytes` iterator) - rust-lang#127512 (Terminate `--print link-args` output with newline) - rust-lang#127792 (std: Use `read_unaligned` for reads from DWARF) - rust-lang#127807 (Use futex.rs for Windows thread parking) - rust-lang#127833 (zkvm: add `#[forbid(unsafe_op_in_unsafe_fn)]` in `stdlib`) - rust-lang#127836 (std: Forbid unwrapped unsafe ops in xous and uefi modules) Failed merges: - rust-lang#127813 (Prevent double reference in generic futex) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 1a6e777 + 1a1b44f commit a28b35e

File tree

38 files changed

+127
-98
lines changed

38 files changed

+127
-98
lines changed

compiler/rustc_codegen_ssa/src/back/link.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -750,7 +750,7 @@ fn link_natively(
750750

751751
for print in &sess.opts.prints {
752752
if print.kind == PrintKind::LinkArgs {
753-
let content = format!("{cmd:?}");
753+
let content = format!("{cmd:?}\n");
754754
print.out.overwrite(&content, sess);
755755
}
756756
}

compiler/rustc_const_eval/src/interpret/validity.rs

-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ use super::{
3434
Pointer, Projectable, Scalar, ValueVisitor,
3535
};
3636

37-
// for the validation errors
3837
use super::InterpError::UndefinedBehavior as Ub;
3938
use super::InterpError::Unsupported as Unsup;
4039
use super::UndefinedBehaviorInfo::*;

compiler/rustc_lint/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,6 @@ use types::*;
120120
use unit_bindings::*;
121121
use unused::*;
122122

123-
/// Useful for other parts of the compiler / Clippy.
124123
pub use builtin::{MissingDoc, SoftLints};
125124
pub use context::{CheckLintNameResult, FindLintError, LintStore};
126125
pub use context::{EarlyContext, LateContext, LintContext};

compiler/rustc_pattern_analysis/src/lib.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,7 @@ rustc_fluent_macro::fluent_messages! { "../messages.ftl" }
2121

2222
use std::fmt;
2323

24-
// Re-exports to avoid rustc_index version issues.
25-
pub use rustc_index::Idx;
26-
pub use rustc_index::IndexVec;
24+
pub use rustc_index::{Idx, IndexVec}; // re-exported to avoid rustc_index version issues
2725

2826
#[cfg(feature = "rustc")]
2927
use rustc_middle::ty::Ty;

compiler/rustc_smir/src/rustc_internal/internal.rs

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

library/alloc/src/testing/crash_test.rs

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

library/core/src/char/mod.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,17 @@ mod convert;
2424
mod decode;
2525
mod methods;
2626

27-
// stable re-exports
2827
#[stable(feature = "try_from", since = "1.34.0")]
2928
pub use self::convert::CharTryFromError;
3029
#[stable(feature = "char_from_str", since = "1.20.0")]
3130
pub use self::convert::ParseCharError;
3231
#[stable(feature = "decode_utf16", since = "1.9.0")]
3332
pub use self::decode::{DecodeUtf16, DecodeUtf16Error};
3433

35-
// perma-unstable re-exports
3634
#[unstable(feature = "char_internals", reason = "exposed only for libstd", issue = "none")]
37-
pub use self::methods::encode_utf16_raw;
35+
pub use self::methods::encode_utf16_raw; // perma-unstable
3836
#[unstable(feature = "char_internals", reason = "exposed only for libstd", issue = "none")]
39-
pub use self::methods::encode_utf8_raw;
37+
pub use self::methods::encode_utf8_raw; // perma-unstable
4038

4139
use crate::ascii;
4240
use crate::error::Error;

library/core/src/ffi/c_str.rs

+15-2
Original file line numberDiff line numberDiff line change
@@ -781,8 +781,15 @@ const unsafe fn strlen(ptr: *const c_char) -> usize {
781781
pub struct Bytes<'a> {
782782
// since we know the string is nul-terminated, we only need one pointer
783783
ptr: NonNull<u8>,
784-
phantom: PhantomData<&'a u8>,
784+
phantom: PhantomData<&'a [c_char]>,
785785
}
786+
787+
#[unstable(feature = "cstr_bytes", issue = "112115")]
788+
unsafe impl Send for Bytes<'_> {}
789+
790+
#[unstable(feature = "cstr_bytes", issue = "112115")]
791+
unsafe impl Sync for Bytes<'_> {}
792+
786793
impl<'a> Bytes<'a> {
787794
#[inline]
788795
fn new(s: &'a CStr) -> Self {
@@ -815,7 +822,7 @@ impl Iterator for Bytes<'_> {
815822
if ret == 0 {
816823
None
817824
} else {
818-
self.ptr = self.ptr.offset(1);
825+
self.ptr = self.ptr.add(1);
819826
Some(ret)
820827
}
821828
}
@@ -825,6 +832,12 @@ impl Iterator for Bytes<'_> {
825832
fn size_hint(&self) -> (usize, Option<usize>) {
826833
if self.is_empty() { (0, Some(0)) } else { (1, None) }
827834
}
835+
836+
#[inline]
837+
fn count(self) -> usize {
838+
// SAFETY: We always hold a valid pointer to a C string
839+
unsafe { strlen(self.ptr.as_ptr().cast()) }
840+
}
828841
}
829842

830843
#[unstable(feature = "cstr_bytes", issue = "112115")]

library/core/src/num/dec2flt/mod.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -250,8 +250,10 @@ pub fn dec2flt<F: RawFloat>(s: &str) -> Result<F, ParseFloatError> {
250250
None => return Err(pfe_invalid()),
251251
};
252252
num.negative = negative;
253-
if let Some(value) = num.try_fast_path::<F>() {
254-
return Ok(value);
253+
if !cfg!(feature = "optimize_for_size") {
254+
if let Some(value) = num.try_fast_path::<F>() {
255+
return Ok(value);
256+
}
255257
}
256258

257259
// If significant digits were truncated, then we can have rounding error

library/core/src/prelude/common.rs

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

library/core/src/prelude/mod.rs

+3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
//! This module is imported by default when `#![no_std]` is used in the same
55
//! manner as the standard library's prelude.
66
7+
// No formatting: this file is nothing but re-exports, and their order is worth preserving.
8+
#![cfg_attr(rustfmt, rustfmt::skip)]
9+
710
#![stable(feature = "core_prelude", since = "1.4.0")]
811

912
mod common;

library/core/src/ptr/mod.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1809,10 +1809,9 @@ pub(crate) const unsafe fn align_offset<T: Sized>(p: *const T, a: usize) -> usiz
18091809
// FIXME(#75598): Direct use of these intrinsics improves codegen significantly at opt-level <=
18101810
// 1, where the method versions of these operations are not inlined.
18111811
use intrinsics::{
1812-
assume, cttz_nonzero, exact_div, mul_with_overflow, unchecked_rem, unchecked_sub,
1813-
wrapping_add, wrapping_mul, wrapping_sub,
1812+
assume, cttz_nonzero, exact_div, mul_with_overflow, unchecked_rem, unchecked_shl,
1813+
unchecked_shr, unchecked_sub, wrapping_add, wrapping_mul, wrapping_sub,
18141814
};
1815-
use intrinsics::{unchecked_shl, unchecked_shr};
18161815

18171816
/// Calculate multiplicative modular inverse of `x` modulo `m`.
18181817
///

library/core/src/unicode/mod.rs

+13-13
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,19 @@
11
#![unstable(feature = "unicode_internals", issue = "none")]
22
#![allow(missing_docs)]
33

4+
// The `pub use` ones are for use in alloc, and are not re-exported in std.
5+
6+
pub(crate) use unicode_data::alphabetic::lookup as Alphabetic;
7+
pub use unicode_data::case_ignorable::lookup as Case_Ignorable;
8+
pub use unicode_data::cased::lookup as Cased;
9+
pub(crate) use unicode_data::cc::lookup as Cc;
10+
pub use unicode_data::conversions;
11+
pub(crate) use unicode_data::grapheme_extend::lookup as Grapheme_Extend;
12+
pub(crate) use unicode_data::lowercase::lookup as Lowercase;
13+
pub(crate) use unicode_data::n::lookup as N;
14+
pub(crate) use unicode_data::uppercase::lookup as Uppercase;
15+
pub(crate) use unicode_data::white_space::lookup as White_Space;
16+
417
pub(crate) mod printable;
518
mod unicode_data;
619

@@ -16,16 +29,3 @@ mod unicode_data;
1629
/// [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).
1730
#[stable(feature = "unicode_version", since = "1.45.0")]
1831
pub const UNICODE_VERSION: (u8, u8, u8) = unicode_data::UNICODE_VERSION;
19-
20-
// For use in alloc, not re-exported in std.
21-
pub use unicode_data::{
22-
case_ignorable::lookup as Case_Ignorable, cased::lookup as Cased, conversions,
23-
};
24-
25-
pub(crate) use unicode_data::alphabetic::lookup as Alphabetic;
26-
pub(crate) use unicode_data::cc::lookup as Cc;
27-
pub(crate) use unicode_data::grapheme_extend::lookup as Grapheme_Extend;
28-
pub(crate) use unicode_data::lowercase::lookup as Lowercase;
29-
pub(crate) use unicode_data::n::lookup as N;
30-
pub(crate) use unicode_data::uppercase::lookup as Uppercase;
31-
pub(crate) use unicode_data::white_space::lookup as White_Space;

library/std/src/env.rs

+4-10
Original file line numberDiff line numberDiff line change
@@ -120,11 +120,8 @@ pub struct VarsOs {
120120
/// # Examples
121121
///
122122
/// ```
123-
/// use std::env;
124-
///
125-
/// // We will iterate through the references to the element returned by
126-
/// // env::vars();
127-
/// for (key, value) in env::vars() {
123+
/// // Print all environment variables.
124+
/// for (key, value) in std::env::vars() {
128125
/// println!("{key}: {value}");
129126
/// }
130127
/// ```
@@ -150,11 +147,8 @@ pub fn vars() -> Vars {
150147
/// # Examples
151148
///
152149
/// ```
153-
/// use std::env;
154-
///
155-
/// // We will iterate through the references to the element returned by
156-
/// // env::vars_os();
157-
/// for (key, value) in env::vars_os() {
150+
/// // Print all environment variables.
151+
/// for (key, value) in std::env::vars_os() {
158152
/// println!("{key:?}: {value:?}");
159153
/// }
160154
/// ```

library/std/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,6 @@ pub mod rt;
470470
// The Rust prelude
471471
pub mod prelude;
472472

473-
// Public module declarations and re-exports
474473
#[stable(feature = "rust1", since = "1.0.0")]
475474
pub use alloc_crate::borrow;
476475
#[stable(feature = "rust1", since = "1.0.0")]

library/std/src/os/fortanix_sgx/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ pub mod usercalls {
2828
pub use crate::sys::abi::usercalls::raw::{do_usercall, Usercalls as UsercallNrs};
2929
pub use crate::sys::abi::usercalls::raw::{Register, RegisterArgument, ReturnValue};
3030

31-
// fortanix-sgx-abi re-exports
3231
pub use crate::sys::abi::usercalls::raw::Error;
3332
pub use crate::sys::abi::usercalls::raw::{
3433
ByteBuffer, Cancel, FifoDescriptor, Return, Usercall,

library/std/src/os/uefi/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
33
#![unstable(feature = "uefi_std", issue = "100499")]
44
#![doc(cfg(target_os = "uefi"))]
5+
#![forbid(unsafe_op_in_unsafe_fn)]
56

67
pub mod env;
78
#[path = "../windows/ffi.rs"]

library/std/src/os/xous/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#![stable(feature = "rust1", since = "1.0.0")]
22
#![doc(cfg(target_os = "xous"))]
3+
#![forbid(unsafe_op_in_unsafe_fn)]
34

45
pub mod ffi;
56

library/std/src/prelude/common.rs

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

library/std/src/prelude/mod.rs

+3
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@
9595
//! [book-enums]: ../../book/ch06-01-defining-an-enum.html
9696
//! [book-iter]: ../../book/ch13-02-iterators.html
9797
98+
// No formatting: this file is nothing but re-exports, and their order is worth preserving.
99+
#![cfg_attr(rustfmt, rustfmt::skip)]
100+
98101
#![stable(feature = "rust1", since = "1.0.0")]
99102

100103
mod common;

library/std/src/rt.rs

-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
#![deny(unsafe_op_in_unsafe_fn)]
1717
#![allow(unused_macros)]
1818

19-
// Re-export some of our utilities which are expected by other crates.
2019
pub use crate::panicking::{begin_panic, panic_count};
2120
pub use core::panicking::{panic_display, panic_fmt};
2221

library/std/src/sys/pal/hermit/futex.rs

+5
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ use crate::ptr::null;
33
use crate::sync::atomic::AtomicU32;
44
use crate::time::Duration;
55

6+
/// An atomic for use as a futex that is at least 8-bits but may be larger.
7+
pub type SmallAtomic = AtomicU32;
8+
/// Must be the underlying type of SmallAtomic
9+
pub type SmallPrimitive = u32;
10+
611
pub fn futex_wait(futex: &AtomicU32, expected: u32, timeout: Option<Duration>) -> bool {
712
// Calculate the timeout as a relative timespec.
813
//

library/std/src/sys/pal/uefi/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
//!
1212
//! [`OsStr`]: crate::ffi::OsStr
1313
//! [`OsString`]: crate::ffi::OsString
14+
#![forbid(unsafe_op_in_unsafe_fn)]
1415

1516
pub mod alloc;
1617
pub mod args;

library/std/src/sys/pal/unix/futex.rs

+5
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@
1111
use crate::sync::atomic::AtomicU32;
1212
use crate::time::Duration;
1313

14+
/// An atomic for use as a futex that is at least 8-bits but may be larger.
15+
pub type SmallAtomic = AtomicU32;
16+
/// Must be the underlying type of SmallAtomic
17+
pub type SmallPrimitive = u32;
18+
1419
/// Wait for a futex_wake operation to wake us.
1520
///
1621
/// Returns directly if the futex doesn't hold the expected value.

library/std/src/sys/pal/wasi/mod.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,15 @@ pub mod time;
3939
#[deny(unsafe_op_in_unsafe_fn)]
4040
#[allow(unused)]
4141
mod common;
42+
4243
pub use common::*;
4344

4445
mod helpers;
45-
// These exports are listed individually to work around Rust's glob import
46-
// conflict rules. If we glob export `helpers` and `common` together, then
47-
// the compiler complains about conflicts.
46+
47+
// The following exports are listed individually to work around Rust's glob
48+
// import conflict rules. If we glob export `helpers` and `common` together,
49+
// then the compiler complains about conflicts.
50+
4851
pub use helpers::abort_internal;
4952
pub use helpers::decode_error_kind;
5053
use helpers::err2io;

library/std/src/sys/pal/wasip2/mod.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,16 @@ pub mod time;
4141
#[deny(unsafe_op_in_unsafe_fn)]
4242
#[allow(unused)]
4343
mod common;
44+
4445
pub use common::*;
4546

4647
#[path = "../wasi/helpers.rs"]
4748
mod helpers;
48-
// These exports are listed individually to work around Rust's glob import
49-
// conflict rules. If we glob export `helpers` and `common` together, then
50-
// the compiler complains about conflicts.
49+
50+
// The following exports are listed individually to work around Rust's glob
51+
// import conflict rules. If we glob export `helpers` and `common` together,
52+
// then the compiler complains about conflicts.
53+
5154
pub use helpers::abort_internal;
5255
pub use helpers::decode_error_kind;
5356
use helpers::err2io;

library/std/src/sys/pal/wasm/atomics/futex.rs

+5
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ use core::arch::wasm64 as wasm;
66
use crate::sync::atomic::AtomicU32;
77
use crate::time::Duration;
88

9+
/// An atomic for use as a futex that is at least 8-bits but may be larger.
10+
pub type SmallAtomic = AtomicU32;
11+
/// Must be the underlying type of SmallAtomic
12+
pub type SmallPrimitive = u32;
13+
914
/// Wait for a futex_wake operation to wake us.
1015
///
1116
/// Returns directly if the futex doesn't hold the expected value.

library/std/src/sys/pal/windows/futex.rs

+5
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ use core::sync::atomic::{
1010
};
1111
use core::time::Duration;
1212

13+
/// An atomic for use as a futex that is at least 8-bits but may be larger.
14+
pub type SmallAtomic = AtomicU8;
15+
/// Must be the underlying type of SmallAtomic
16+
pub type SmallPrimitive = u8;
17+
1318
pub unsafe trait Waitable {
1419
type Atomic;
1520
}

library/std/src/sys/pal/xous/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![deny(unsafe_op_in_unsafe_fn)]
1+
#![forbid(unsafe_op_in_unsafe_fn)]
22

33
pub mod alloc;
44
#[path = "../unsupported/args.rs"]

0 commit comments

Comments
 (0)