Skip to content

Commit f283d3f

Browse files
committed
Auto merge of rust-lang#77436 - JohnTitor:rollup-65dh7rp, r=JohnTitor
Rollup of 11 pull requests Successful merges: - rust-lang#76851 (Fix 'FIXME' about using NonZeroU32 instead of u32.) - rust-lang#76979 (Improve std::sys::windows::compat) - rust-lang#77111 (Stabilize slice_ptr_range.) - rust-lang#77147 (Split sys_common::Mutex in StaticMutex and MovableMutex.) - rust-lang#77312 (Remove outdated line from `publish_toolstate` hook) - rust-lang#77362 (Fix is_absolute on WASI) - rust-lang#77375 (rustc_metadata: Do not forget to encode inherent impls for foreign types) - rust-lang#77385 (Improve the example for ptr::copy) - rust-lang#77389 (Fix some clippy lints) - rust-lang#77399 (BTreeMap: use Unique::from to avoid a cast where type information exists) - rust-lang#77429 (Link `new` method in `DefautHasher`s doc) Failed merges: r? `@ghost`
2 parents 66936de + 5a72180 commit f283d3f

File tree

36 files changed

+228
-227
lines changed

36 files changed

+228
-227
lines changed

compiler/rustc_feature/src/accepted.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! List of the accepted feature gates.
22
3-
use super::{Feature, State};
3+
use super::{to_nonzero, Feature, State};
44
use rustc_span::symbol::sym;
55

66
macro_rules! declare_features {
@@ -14,7 +14,7 @@ macro_rules! declare_features {
1414
state: State::Accepted,
1515
name: sym::$feature,
1616
since: $ver,
17-
issue: $issue,
17+
issue: to_nonzero($issue),
1818
edition: None,
1919
description: concat!($($doc,)*),
2020
}

compiler/rustc_feature/src/active.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! List of the active feature gates.
22
3-
use super::{Feature, State};
3+
use super::{to_nonzero, Feature, State};
44

55
use rustc_span::edition::Edition;
66
use rustc_span::symbol::{sym, Symbol};
@@ -29,7 +29,7 @@ macro_rules! declare_features {
2929
state: State::Active { set: set!($feature) },
3030
name: sym::$feature,
3131
since: $ver,
32-
issue: $issue,
32+
issue: to_nonzero($issue),
3333
edition: $edition,
3434
description: concat!($($doc,)*),
3535
}

compiler/rustc_feature/src/lib.rs

+13-10
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,11 @@ pub struct Feature {
4646
pub state: State,
4747
pub name: Symbol,
4848
pub since: &'static str,
49-
issue: Option<u32>, // FIXME: once #58732 is done make this an Option<NonZeroU32>
49+
issue: Option<NonZeroU32>,
5050
pub edition: Option<Edition>,
5151
description: &'static str,
5252
}
5353

54-
impl Feature {
55-
fn issue(&self) -> Option<NonZeroU32> {
56-
self.issue.and_then(NonZeroU32::new)
57-
}
58-
}
59-
6054
#[derive(Copy, Clone, Debug)]
6155
pub enum Stability {
6256
Unstable,
@@ -102,8 +96,8 @@ impl UnstableFeatures {
10296
fn find_lang_feature_issue(feature: Symbol) -> Option<NonZeroU32> {
10397
if let Some(info) = ACTIVE_FEATURES.iter().find(|t| t.name == feature) {
10498
// FIXME (#28244): enforce that active features have issue numbers
105-
// assert!(info.issue().is_some())
106-
info.issue()
99+
// assert!(info.issue.is_some())
100+
info.issue
107101
} else {
108102
// search in Accepted, Removed, or Stable Removed features
109103
let found = ACCEPTED_FEATURES
@@ -112,12 +106,21 @@ fn find_lang_feature_issue(feature: Symbol) -> Option<NonZeroU32> {
112106
.chain(STABLE_REMOVED_FEATURES)
113107
.find(|t| t.name == feature);
114108
match found {
115-
Some(found) => found.issue(),
109+
Some(found) => found.issue,
116110
None => panic!("feature `{}` is not declared anywhere", feature),
117111
}
118112
}
119113
}
120114

115+
const fn to_nonzero(n: Option<u32>) -> Option<NonZeroU32> {
116+
// Can be replaced with `n.and_then(NonZeroU32::new)` if that is ever usable
117+
// in const context. Requires https://github.com/rust-lang/rfcs/pull/2632.
118+
match n {
119+
None => None,
120+
Some(n) => NonZeroU32::new(n),
121+
}
122+
}
123+
121124
pub enum GateIssue {
122125
Language,
123126
Library(Option<NonZeroU32>),

compiler/rustc_feature/src/removed.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! List of the removed feature gates.
22
3-
use super::{Feature, State};
3+
use super::{to_nonzero, Feature, State};
44
use rustc_span::symbol::sym;
55

66
macro_rules! declare_features {
@@ -14,7 +14,7 @@ macro_rules! declare_features {
1414
state: State::Removed { reason: $reason },
1515
name: sym::$feature,
1616
since: $ver,
17-
issue: $issue,
17+
issue: to_nonzero($issue),
1818
edition: None,
1919
description: concat!($($doc,)*),
2020
}
@@ -32,7 +32,7 @@ macro_rules! declare_features {
3232
state: State::Stabilized { reason: None },
3333
name: sym::$feature,
3434
since: $ver,
35-
issue: $issue,
35+
issue: to_nonzero($issue),
3636
edition: None,
3737
description: concat!($($doc,)*),
3838
}

compiler/rustc_metadata/src/rmeta/encoder.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1753,6 +1753,7 @@ impl EncodeContext<'a, 'tcx> {
17531753
self.encode_const_stability(def_id);
17541754
self.encode_deprecation(def_id);
17551755
self.encode_item_type(def_id);
1756+
self.encode_inherent_implementations(def_id);
17561757
if let hir::ForeignItemKind::Fn(..) = nitem.kind {
17571758
record!(self.tables.fn_sig[def_id] <- tcx.fn_sig(def_id));
17581759
self.encode_variances_of(def_id);

library/alloc/src/collections/btree/node.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ impl<K, V> BoxedNode<K, V> {
128128
}
129129

130130
fn from_internal(node: Box<InternalNode<K, V>>) -> Self {
131-
BoxedNode { ptr: Box::into_unique(node).cast() }
131+
BoxedNode { ptr: Unique::from(&mut Box::leak(node).data) }
132132
}
133133

134134
unsafe fn from_ptr(ptr: NonNull<LeafNode<K, V>>) -> Self {

library/core/src/intrinsics.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -1901,11 +1901,21 @@ pub unsafe fn copy_nonoverlapping<T>(src: *const T, dst: *mut T, count: usize) {
19011901
/// ```
19021902
/// use std::ptr;
19031903
///
1904+
/// /// # Safety:
1905+
/// /// * `ptr` must be correctly aligned for its type and non-zero.
1906+
/// /// * `ptr` must be valid for reads of `elts` contiguous objects of type `T`.
1907+
/// /// * Those elements must not be used after calling this function unless `T: Copy`.
19041908
/// # #[allow(dead_code)]
19051909
/// unsafe fn from_buf_raw<T>(ptr: *const T, elts: usize) -> Vec<T> {
19061910
/// let mut dst = Vec::with_capacity(elts);
1907-
/// dst.set_len(elts);
1911+
///
1912+
/// // SAFETY: Our precondition ensures the source is aligned and valid,
1913+
/// // and `Vec::with_capacity` ensures that we have usable space to write them.
19081914
/// ptr::copy(ptr, dst.as_mut_ptr(), elts);
1915+
///
1916+
/// // SAFETY: We created it with this much capacity earlier,
1917+
/// // and the previous `copy` has initialized these elements.
1918+
/// dst.set_len(elts);
19091919
/// dst
19101920
/// }
19111921
/// ```

library/core/src/slice/mod.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -458,8 +458,6 @@ impl<T> [T] {
458458
/// element of this slice:
459459
///
460460
/// ```
461-
/// #![feature(slice_ptr_range)]
462-
///
463461
/// let a = [1, 2, 3];
464462
/// let x = &a[1] as *const _;
465463
/// let y = &5 as *const _;
@@ -469,7 +467,7 @@ impl<T> [T] {
469467
/// ```
470468
///
471469
/// [`as_ptr`]: #method.as_ptr
472-
#[unstable(feature = "slice_ptr_range", issue = "65807")]
470+
#[stable(feature = "slice_ptr_range", since = "1.48.0")]
473471
#[rustc_const_unstable(feature = "const_ptr_offset", issue = "71499")]
474472
#[inline]
475473
pub const fn as_ptr_range(&self) -> Range<*const T> {
@@ -511,7 +509,7 @@ impl<T> [T] {
511509
/// common in C++.
512510
///
513511
/// [`as_mut_ptr`]: #method.as_mut_ptr
514-
#[unstable(feature = "slice_ptr_range", issue = "65807")]
512+
#[stable(feature = "slice_ptr_range", since = "1.48.0")]
515513
#[rustc_const_unstable(feature = "const_ptr_offset", issue = "71499")]
516514
#[inline]
517515
pub const fn as_mut_ptr_range(&mut self) -> Range<*mut T> {

library/std/src/collections/hash/map.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -2836,11 +2836,10 @@ impl DefaultHasher {
28362836

28372837
#[stable(feature = "hashmap_default_hasher", since = "1.13.0")]
28382838
impl Default for DefaultHasher {
2839-
// FIXME: here should link `new` to [DefaultHasher::new], but it occurs intra-doc link
2840-
// resolution failure when re-exporting libstd items. When #56922 fixed,
2841-
// link `new` to [DefaultHasher::new] again.
2842-
/// Creates a new `DefaultHasher` using `new`.
2839+
/// Creates a new `DefaultHasher` using [`new`].
28432840
/// See its documentation for more.
2841+
///
2842+
/// [`new`]: DefaultHasher::new
28442843
fn default() -> DefaultHasher {
28452844
DefaultHasher::new()
28462845
}

library/std/src/path.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1838,7 +1838,7 @@ impl Path {
18381838
// FIXME: Allow Redox prefixes
18391839
self.has_root() || has_redox_scheme(self.as_u8_slice())
18401840
} else {
1841-
self.has_root() && (cfg!(unix) || self.prefix().is_some())
1841+
self.has_root() && (cfg!(any(unix, target_os = "wasi")) || self.prefix().is_some())
18421842
}
18431843
}
18441844

library/std/src/sync/condvar.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -553,8 +553,8 @@ impl Condvar {
553553
unsafe { self.inner.notify_all() }
554554
}
555555

556-
fn verify(&self, mutex: &sys_mutex::Mutex) {
557-
let addr = mutex as *const _ as usize;
556+
fn verify(&self, mutex: &sys_mutex::MovableMutex) {
557+
let addr = mutex.raw() as *const _ as usize;
558558
match self.mutex.compare_and_swap(0, addr, Ordering::SeqCst) {
559559
// If we got out 0, then we have successfully bound the mutex to
560560
// this cvar.

library/std/src/sync/mutex.rs

+4-26
Original file line numberDiff line numberDiff line change
@@ -166,12 +166,7 @@ use crate::sys_common::poison::{self, LockResult, TryLockError, TryLockResult};
166166
#[stable(feature = "rust1", since = "1.0.0")]
167167
#[cfg_attr(not(test), rustc_diagnostic_item = "mutex_type")]
168168
pub struct Mutex<T: ?Sized> {
169-
// Note that this mutex is in a *box*, not inlined into the struct itself.
170-
// Once a native mutex has been used once, its address can never change (it
171-
// can't be moved). This mutex type can be safely moved at any time, so to
172-
// ensure that the native mutex is used correctly we box the inner mutex to
173-
// give it a constant address.
174-
inner: Box<sys::Mutex>,
169+
inner: sys::MovableMutex,
175170
poison: poison::Flag,
176171
data: UnsafeCell<T>,
177172
}
@@ -218,15 +213,11 @@ impl<T> Mutex<T> {
218213
/// ```
219214
#[stable(feature = "rust1", since = "1.0.0")]
220215
pub fn new(t: T) -> Mutex<T> {
221-
let mut m = Mutex {
222-
inner: box sys::Mutex::new(),
216+
Mutex {
217+
inner: sys::MovableMutex::new(),
223218
poison: poison::Flag::new(),
224219
data: UnsafeCell::new(t),
225-
};
226-
unsafe {
227-
m.inner.init();
228220
}
229-
m
230221
}
231222
}
232223

@@ -378,7 +369,6 @@ impl<T: ?Sized> Mutex<T> {
378369
(ptr::read(inner), ptr::read(poison), ptr::read(data))
379370
};
380371
mem::forget(self);
381-
inner.destroy(); // Keep in sync with the `Drop` impl.
382372
drop(inner);
383373

384374
poison::map_result(poison.borrow(), |_| data.into_inner())
@@ -411,18 +401,6 @@ impl<T: ?Sized> Mutex<T> {
411401
}
412402
}
413403

414-
#[stable(feature = "rust1", since = "1.0.0")]
415-
unsafe impl<#[may_dangle] T: ?Sized> Drop for Mutex<T> {
416-
fn drop(&mut self) {
417-
// This is actually safe b/c we know that there is no further usage of
418-
// this mutex (it's up to the user to arrange for a mutex to get
419-
// dropped, that's not our job)
420-
//
421-
// IMPORTANT: This code must be kept in sync with `Mutex::into_inner`.
422-
unsafe { self.inner.destroy() }
423-
}
424-
}
425-
426404
#[stable(feature = "mutex_from", since = "1.24.0")]
427405
impl<T> From<T> for Mutex<T> {
428406
/// Creates a new mutex in an unlocked state ready for use.
@@ -509,7 +487,7 @@ impl<T: ?Sized + fmt::Display> fmt::Display for MutexGuard<'_, T> {
509487
}
510488
}
511489

512-
pub fn guard_lock<'a, T: ?Sized>(guard: &MutexGuard<'a, T>) -> &'a sys::Mutex {
490+
pub fn guard_lock<'a, T: ?Sized>(guard: &MutexGuard<'a, T>) -> &'a sys::MovableMutex {
513491
&guard.lock.inner
514492
}
515493

library/std/src/sys/hermit/args.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,11 @@ mod imp {
5757
use crate::ptr;
5858
use crate::sys_common::os_str_bytes::*;
5959

60-
use crate::sys_common::mutex::Mutex;
60+
use crate::sys_common::mutex::StaticMutex;
6161

6262
static mut ARGC: isize = 0;
6363
static mut ARGV: *const *const u8 = ptr::null();
64-
static LOCK: Mutex = Mutex::new();
64+
static LOCK: StaticMutex = StaticMutex::new();
6565

6666
pub unsafe fn init(argc: isize, argv: *const *const u8) {
6767
let _guard = LOCK.lock();

library/std/src/sys/unix/args.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,13 @@ mod imp {
8080
use crate::ptr;
8181
use crate::sync::atomic::{AtomicIsize, AtomicPtr, Ordering};
8282

83-
use crate::sys_common::mutex::Mutex;
83+
use crate::sys_common::mutex::StaticMutex;
8484

8585
static ARGC: AtomicIsize = AtomicIsize::new(0);
8686
static ARGV: AtomicPtr<*const u8> = AtomicPtr::new(ptr::null_mut());
8787
// We never call `ENV_LOCK.init()`, so it is UB to attempt to
8888
// acquire this mutex reentrantly!
89-
static LOCK: Mutex = Mutex::new();
89+
static LOCK: StaticMutex = StaticMutex::new();
9090

9191
unsafe fn really_init(argc: isize, argv: *const *const u8) {
9292
let _guard = LOCK.lock();

library/std/src/sys/unix/os.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use crate::slice;
2121
use crate::str;
2222
use crate::sys::cvt;
2323
use crate::sys::fd;
24-
use crate::sys_common::mutex::{Mutex, MutexGuard};
24+
use crate::sys_common::mutex::{StaticMutex, StaticMutexGuard};
2525
use crate::vec;
2626

2727
use libc::{c_char, c_int, c_void};
@@ -470,10 +470,9 @@ pub unsafe fn environ() -> *mut *const *const c_char {
470470
&mut environ
471471
}
472472

473-
pub unsafe fn env_lock() -> MutexGuard<'static> {
474-
// We never call `ENV_LOCK.init()`, so it is UB to attempt to
475-
// acquire this mutex reentrantly!
476-
static ENV_LOCK: Mutex = Mutex::new();
473+
pub unsafe fn env_lock() -> StaticMutexGuard<'static> {
474+
// It is UB to attempt to acquire this mutex reentrantly!
475+
static ENV_LOCK: StaticMutex = StaticMutex::new();
477476
ENV_LOCK.lock()
478477
}
479478

library/std/src/sys/vxworks/args.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,11 @@ mod imp {
5757
use crate::marker::PhantomData;
5858
use crate::ptr;
5959

60-
use crate::sys_common::mutex::Mutex;
60+
use crate::sys_common::mutex::StaticMutex;
6161

6262
static mut ARGC: isize = 0;
6363
static mut ARGV: *const *const u8 = ptr::null();
64-
static LOCK: Mutex = Mutex::new();
64+
static LOCK: StaticMutex = StaticMutex::new();
6565

6666
pub unsafe fn init(argc: isize, argv: *const *const u8) {
6767
let _guard = LOCK.lock();

library/std/src/sys/vxworks/os.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use crate::path::{self, Path, PathBuf};
1010
use crate::slice;
1111
use crate::str;
1212
use crate::sys::cvt;
13-
use crate::sys_common::mutex::{Mutex, MutexGuard};
13+
use crate::sys_common::mutex::{StaticMutex, StaticMutexGuard};
1414
use libc::{self, c_char /*,c_void */, c_int};
1515
/*use sys::fd; this one is probably important */
1616
use crate::vec;
@@ -212,10 +212,9 @@ pub unsafe fn environ() -> *mut *const *const c_char {
212212
&mut environ
213213
}
214214

215-
pub unsafe fn env_lock() -> MutexGuard<'static> {
216-
// We never call `ENV_LOCK.init()`, so it is UB to attempt to
217-
// acquire this mutex reentrantly!
218-
static ENV_LOCK: Mutex = Mutex::new();
215+
pub unsafe fn env_lock() -> StaticMutexGuard<'static> {
216+
// It is UB to attempt to acquire this mutex reentrantly!
217+
static ENV_LOCK: StaticMutex = StaticMutex::new();
219218
ENV_LOCK.lock()
220219
}
221220

library/std/src/sys/windows/c.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1032,7 +1032,7 @@ extern "system" {
10321032
// Functions that aren't available on every version of Windows that we support,
10331033
// but we still use them and just provide some form of a fallback implementation.
10341034
compat_fn! {
1035-
kernel32:
1035+
"kernel32":
10361036

10371037
pub fn CreateSymbolicLinkW(_lpSymlinkFileName: LPCWSTR,
10381038
_lpTargetFileName: LPCWSTR,

0 commit comments

Comments
 (0)