Skip to content

Commit 0b766fc

Browse files
committed
Auto merge of rust-lang#138480 - jhpratt:rollup-y3b8wu5, r=jhpratt
Rollup of 16 pull requests Successful merges: - rust-lang#136001 (Overhaul examples for PermissionsExt) - rust-lang#136230 (Reword incorrect documentation about SocketAddr having varying layout) - rust-lang#136892 (Sync Fuchsia target spec with clang Fuchsia driver) - rust-lang#136911 (Add documentation URL to selected jobs) - rust-lang#137870 ( Improve HashMap docs for const and static initializers) - rust-lang#138179 (Add `src/tools/x` to the main workspace) - rust-lang#138389 (use `expect` instead of `allow`) - rust-lang#138396 (Enable metrics and verbose tests in PR CI) - rust-lang#138398 (atomic intrinsics: clarify which types are supported and (if applicable) what happens with provenance) - rust-lang#138432 (fix: remove the check of lld not supporting `@response-file)` - rust-lang#138434 (Visit `PatField` when collecting lint levels) - rust-lang#138441 (update error message) - rust-lang#138442 (EUV: fix place of deref pattern's interior's scrutinee) - rust-lang#138457 (Remove usage of legacy scheme paths on RedoxOS) - rust-lang#138461 (Remove an outdated line from a test comment) - rust-lang#138466 (Remove myself from libs review) Failed merges: - rust-lang#138452 (Remove `RUN_CHECK_WITH_PARALLEL_QUERIES`) r? `@ghost` `@rustbot` modify labels: rollup
2 parents c6020bf + 3c6161f commit 0b766fc

File tree

8 files changed

+275
-82
lines changed

8 files changed

+275
-82
lines changed

core/src/intrinsics/mod.rs

+152-1
Large diffs are not rendered by default.

core/src/net/socket_addr.rs

+21-11
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,15 @@ use crate::net::{IpAddr, Ipv4Addr, Ipv6Addr};
88
/// as possibly some version-dependent additional information. See [`SocketAddrV4`]'s and
99
/// [`SocketAddrV6`]'s respective documentation for more details.
1010
///
11-
/// The size of a `SocketAddr` instance may vary depending on the target operating
12-
/// system.
13-
///
1411
/// [IP address]: IpAddr
1512
///
13+
/// # Portability
14+
///
15+
/// `SocketAddr` is intended to be a portable representation of socket addresses and is likely not
16+
/// the same as the internal socket address type used by the target operating system's API. Like all
17+
/// `repr(Rust)` structs, however, its exact layout remains undefined and should not be relied upon
18+
/// between builds.
19+
///
1620
/// # Examples
1721
///
1822
/// ```
@@ -42,13 +46,16 @@ pub enum SocketAddr {
4246
///
4347
/// See [`SocketAddr`] for a type encompassing both IPv4 and IPv6 socket addresses.
4448
///
45-
/// The size of a `SocketAddrV4` struct may vary depending on the target operating
46-
/// system. Do not assume that this type has the same memory layout as the underlying
47-
/// system representation.
48-
///
4949
/// [IETF RFC 793]: https://tools.ietf.org/html/rfc793
5050
/// [`IPv4` address]: Ipv4Addr
5151
///
52+
/// # Portability
53+
///
54+
/// `SocketAddrV4` is intended to be a portable representation of socket addresses and is likely not
55+
/// the same as the internal socket address type used by the target operating system's API. Like all
56+
/// `repr(Rust)` structs, however, its exact layout remains undefined and should not be relied upon
57+
/// between builds.
58+
///
5259
/// # Textual representation
5360
///
5461
/// `SocketAddrV4` provides a [`FromStr`](crate::str::FromStr) implementation.
@@ -84,13 +91,16 @@ pub struct SocketAddrV4 {
8491
///
8592
/// See [`SocketAddr`] for a type encompassing both IPv4 and IPv6 socket addresses.
8693
///
87-
/// The size of a `SocketAddrV6` struct may vary depending on the target operating
88-
/// system. Do not assume that this type has the same memory layout as the underlying
89-
/// system representation.
90-
///
9194
/// [IETF RFC 2553, Section 3.3]: https://tools.ietf.org/html/rfc2553#section-3.3
9295
/// [`IPv6` address]: Ipv6Addr
9396
///
97+
/// # Portability
98+
///
99+
/// `SocketAddrV6` is intended to be a portable representation of socket addresses and is likely not
100+
/// the same as the internal socket address type used by the target operating system's API. Like all
101+
/// `repr(Rust)` structs, however, its exact layout remains undefined and should not be relied upon
102+
/// between builds.
103+
///
94104
/// # Textual representation
95105
///
96106
/// `SocketAddrV6` provides a [`FromStr`](crate::str::FromStr) implementation,

std/src/collections/hash/map.rs

+19-7
Original file line numberDiff line numberDiff line change
@@ -208,20 +208,32 @@ use crate::ops::Index;
208208
/// # Usage in `const` and `static`
209209
///
210210
/// As explained above, `HashMap` is randomly seeded: each `HashMap` instance uses a different seed,
211-
/// which means that `HashMap::new` cannot be used in const context. To construct a `HashMap` in the
212-
/// initializer of a `const` or `static` item, you will have to use a different hasher that does not
213-
/// involve a random seed, as demonstrated in the following example. **A `HashMap` constructed this
214-
/// way is not resistant against HashDoS!**
211+
/// which means that `HashMap::new` normally cannot be used in a `const` or `static` initializer.
215212
///
213+
/// However, if you need to use a `HashMap` in a `const` or `static` initializer while retaining
214+
/// random seed generation, you can wrap the `HashMap` in [`LazyLock`].
215+
///
216+
/// Alternatively, you can construct a `HashMap` in a `const` or `static` initializer using a different
217+
/// hasher that does not rely on a random seed. **Be aware that a `HashMap` created this way is not
218+
/// resistant to HashDoS attacks!**
219+
///
220+
/// [`LazyLock`]: crate::sync::LazyLock
216221
/// ```rust
217222
/// use std::collections::HashMap;
218223
/// use std::hash::{BuildHasherDefault, DefaultHasher};
219-
/// use std::sync::Mutex;
224+
/// use std::sync::{LazyLock, Mutex};
220225
///
221-
/// const EMPTY_MAP: HashMap<String, Vec<i32>, BuildHasherDefault<DefaultHasher>> =
226+
/// // HashMaps with a fixed, non-random hasher
227+
/// const NONRANDOM_EMPTY_MAP: HashMap<String, Vec<i32>, BuildHasherDefault<DefaultHasher>> =
222228
/// HashMap::with_hasher(BuildHasherDefault::new());
223-
/// static MAP: Mutex<HashMap<String, Vec<i32>, BuildHasherDefault<DefaultHasher>>> =
229+
/// static NONRANDOM_MAP: Mutex<HashMap<String, Vec<i32>, BuildHasherDefault<DefaultHasher>>> =
224230
/// Mutex::new(HashMap::with_hasher(BuildHasherDefault::new()));
231+
///
232+
/// // HashMaps using LazyLock to retain random seeding
233+
/// const RANDOM_EMPTY_MAP: LazyLock<HashMap<String, Vec<i32>>> =
234+
/// LazyLock::new(HashMap::new);
235+
/// static RANDOM_MAP: LazyLock<Mutex<HashMap<String, Vec<i32>>>> =
236+
/// LazyLock::new(|| Mutex::new(HashMap::new()));
225237
/// ```
226238
227239
#[cfg_attr(not(test), rustc_diagnostic_item = "HashMap")]

std/src/os/unix/fs.rs

+75-49
Original file line numberDiff line numberDiff line change
@@ -276,63 +276,89 @@ impl FileExt for fs::File {
276276
}
277277

278278
/// Unix-specific extensions to [`fs::Permissions`].
279+
///
280+
/// # Examples
281+
///
282+
/// ```no_run
283+
/// use std::fs::{File, Permissions};
284+
/// use std::io::{ErrorKind, Result as IoResult};
285+
/// use std::os::unix::fs::PermissionsExt;
286+
///
287+
/// fn main() -> IoResult<()> {
288+
/// let name = "test_file_for_permissions";
289+
///
290+
/// // make sure file does not exist
291+
/// let _ = std::fs::remove_file(name);
292+
/// assert_eq!(
293+
/// File::open(name).unwrap_err().kind(),
294+
/// ErrorKind::NotFound,
295+
/// "file already exists"
296+
/// );
297+
///
298+
/// // full read/write/execute mode bits for owner of file
299+
/// // that we want to add to existing mode bits
300+
/// let my_mode = 0o700;
301+
///
302+
/// // create new file with specified permissions
303+
/// {
304+
/// let file = File::create(name)?;
305+
/// let mut permissions = file.metadata()?.permissions();
306+
/// eprintln!("Current permissions: {:o}", permissions.mode());
307+
///
308+
/// // make sure new permissions are not already set
309+
/// assert!(
310+
/// permissions.mode() & my_mode != my_mode,
311+
/// "permissions already set"
312+
/// );
313+
///
314+
/// // either use `set_mode` to change an existing Permissions struct
315+
/// permissions.set_mode(permissions.mode() | my_mode);
316+
///
317+
/// // or use `from_mode` to construct a new Permissions struct
318+
/// permissions = Permissions::from_mode(permissions.mode() | my_mode);
319+
///
320+
/// // write new permissions to file
321+
/// file.set_permissions(permissions)?;
322+
/// }
323+
///
324+
/// let permissions = File::open(name)?.metadata()?.permissions();
325+
/// eprintln!("New permissions: {:o}", permissions.mode());
326+
///
327+
/// // assert new permissions were set
328+
/// assert_eq!(
329+
/// permissions.mode() & my_mode,
330+
/// my_mode,
331+
/// "new permissions not set"
332+
/// );
333+
/// Ok(())
334+
/// }
335+
/// ```
336+
///
337+
/// ```no_run
338+
/// use std::fs::Permissions;
339+
/// use std::os::unix::fs::PermissionsExt;
340+
///
341+
/// // read/write for owner and read for others
342+
/// let my_mode = 0o644;
343+
/// let mut permissions = Permissions::from_mode(my_mode);
344+
/// assert_eq!(permissions.mode(), my_mode);
345+
///
346+
/// // read/write/execute for owner
347+
/// let other_mode = 0o700;
348+
/// permissions.set_mode(other_mode);
349+
/// assert_eq!(permissions.mode(), other_mode);
350+
/// ```
279351
#[stable(feature = "fs_ext", since = "1.1.0")]
280352
pub trait PermissionsExt {
281-
/// Returns the underlying raw `st_mode` bits that contain the standard
282-
/// Unix permissions for this file.
283-
///
284-
/// # Examples
285-
///
286-
/// ```no_run
287-
/// use std::fs::File;
288-
/// use std::os::unix::fs::PermissionsExt;
289-
///
290-
/// fn main() -> std::io::Result<()> {
291-
/// let f = File::create("foo.txt")?;
292-
/// let metadata = f.metadata()?;
293-
/// let permissions = metadata.permissions();
294-
///
295-
/// println!("permissions: {:o}", permissions.mode());
296-
/// Ok(())
297-
/// }
298-
/// ```
353+
/// Returns the mode permission bits
299354
#[stable(feature = "fs_ext", since = "1.1.0")]
300355
fn mode(&self) -> u32;
301356

302-
/// Sets the underlying raw bits for this set of permissions.
303-
///
304-
/// # Examples
305-
///
306-
/// ```no_run
307-
/// use std::fs::File;
308-
/// use std::os::unix::fs::PermissionsExt;
309-
///
310-
/// fn main() -> std::io::Result<()> {
311-
/// let f = File::create("foo.txt")?;
312-
/// let metadata = f.metadata()?;
313-
/// let mut permissions = metadata.permissions();
314-
///
315-
/// permissions.set_mode(0o644); // Read/write for owner and read for others.
316-
/// assert_eq!(permissions.mode(), 0o644);
317-
/// Ok(())
318-
/// }
319-
/// ```
357+
/// Sets the mode permission bits.
320358
#[stable(feature = "fs_ext", since = "1.1.0")]
321359
fn set_mode(&mut self, mode: u32);
322360

323-
/// Creates a new instance of `Permissions` from the given set of Unix
324-
/// permission bits.
325-
///
326-
/// # Examples
327-
///
328-
/// ```
329-
/// use std::fs::Permissions;
330-
/// use std::os::unix::fs::PermissionsExt;
331-
///
332-
/// // Read/write for owner and read for others.
333-
/// let permissions = Permissions::from_mode(0o644);
334-
/// assert_eq!(permissions.mode(), 0o644);
335-
/// ```
361+
/// Creates a new instance from the given mode permission bits.
336362
#[stable(feature = "fs_ext", since = "1.1.0")]
337363
#[cfg_attr(not(test), rustc_diagnostic_item = "permissions_from_mode")]
338364
fn from_mode(mode: u32) -> Self;

std/src/path.rs

+1-7
Original file line numberDiff line numberDiff line change
@@ -294,11 +294,6 @@ where
294294
}
295295
}
296296

297-
// Detect scheme on Redox
298-
pub(crate) fn has_redox_scheme(s: &[u8]) -> bool {
299-
cfg!(target_os = "redox") && s.contains(&b':')
300-
}
301-
302297
////////////////////////////////////////////////////////////////////////////////
303298
// Cross-platform, iterator-independent parsing
304299
////////////////////////////////////////////////////////////////////////////////
@@ -2834,8 +2829,7 @@ impl Path {
28342829
Components {
28352830
path: self.as_u8_slice(),
28362831
prefix,
2837-
has_physical_root: has_physical_root(self.as_u8_slice(), prefix)
2838-
|| has_redox_scheme(self.as_u8_slice()),
2832+
has_physical_root: has_physical_root(self.as_u8_slice(), prefix),
28392833
front: State::Prefix,
28402834
back: State::Body,
28412835
}

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

+6-1
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,12 @@ pub fn current_exe() -> io::Result<PathBuf> {
484484
}
485485
}
486486

487-
#[cfg(any(target_os = "redox", target_os = "rtems"))]
487+
#[cfg(target_os = "redox")]
488+
pub fn current_exe() -> io::Result<PathBuf> {
489+
crate::fs::read_to_string("/scheme/sys/exe").map(PathBuf::from)
490+
}
491+
492+
#[cfg(target_os = "rtems")]
488493
pub fn current_exe() -> io::Result<PathBuf> {
489494
crate::fs::read_to_string("sys:exe").map(PathBuf::from)
490495
}

std/src/sys/pal/unix/process/process_common.rs

-2
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ use crate::{fmt, io, ptr};
1919
cfg_if::cfg_if! {
2020
if #[cfg(target_os = "fuchsia")] {
2121
// fuchsia doesn't have /dev/null
22-
} else if #[cfg(target_os = "redox")] {
23-
const DEV_NULL: &CStr = c"null:";
2422
} else if #[cfg(target_os = "vxworks")] {
2523
const DEV_NULL: &CStr = c"/null";
2624
} else {

std/src/sys/path/unix.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,7 @@ pub(crate) fn absolute(path: &Path) -> io::Result<PathBuf> {
6262
}
6363

6464
pub(crate) fn is_absolute(path: &Path) -> bool {
65-
if cfg!(target_os = "redox") {
66-
// FIXME: Allow Redox prefixes
67-
path.has_root() || crate::path::has_redox_scheme(path.as_u8_slice())
68-
} else if cfg!(any(unix, target_os = "hermit", target_os = "wasi")) {
65+
if cfg!(any(unix, target_os = "hermit", target_os = "wasi")) {
6966
path.has_root()
7067
} else {
7168
path.has_root() && path.prefix().is_some()

0 commit comments

Comments
 (0)