Skip to content

Commit 1a4ad2c

Browse files
borsgitbot
authored and
gitbot
committed
Auto merge of rust-lang#137397 - matthiaskrgr:rollup-ls2pilo, r=matthiaskrgr
Rollup of 10 pull requests Successful merges: - rust-lang#132876 (rustdoc book: acknowledge --document-hidden-items) - rust-lang#136148 (Optionally add type names to `TypeId`s.) - rust-lang#136609 (libcore/net: `IpAddr::as_octets()`) - rust-lang#137336 (Stabilise `os_str_display`) - rust-lang#137350 (Move methods from Map to TyCtxt, part 3.) - rust-lang#137353 (Implement `read_buf` for WASI stdin) - rust-lang#137361 (Refactor `OperandRef::extract_field` to prep for MCP838) - rust-lang#137367 (Do not exempt nonexistent platforms from platform policy) - rust-lang#137374 (Stacker now handles miri using a noop impl itself) - rust-lang#137392 (remove few unused fields) r? `@ghost` `@rustbot` modify labels: rollup
2 parents fb387be + 3193246 commit 1a4ad2c

File tree

9 files changed

+108
-12
lines changed

9 files changed

+108
-12
lines changed

core/Cargo.toml

+2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ optimize_for_size = []
2323
# Make `RefCell` store additional debugging information, which is printed out when
2424
# a borrow error occurs
2525
debug_refcell = []
26+
# Make `TypeId` store a reference to the name of the type, so that it can print that name.
27+
debug_typeid = []
2628

2729
[lints.rust.unexpected_cfgs]
2830
level = "warn"

core/src/any.rs

+17-3
Original file line numberDiff line numberDiff line change
@@ -711,6 +711,8 @@ pub struct TypeId {
711711
// We avoid using `u128` because that imposes higher alignment requirements on many platforms.
712712
// See issue #115620 for more information.
713713
t: (u64, u64),
714+
#[cfg(feature = "debug_typeid")]
715+
name: &'static str,
714716
}
715717

716718
#[stable(feature = "rust1", since = "1.0.0")]
@@ -741,10 +743,14 @@ impl TypeId {
741743
#[rustc_const_unstable(feature = "const_type_id", issue = "77125")]
742744
pub const fn of<T: ?Sized + 'static>() -> TypeId {
743745
let t: u128 = intrinsics::type_id::<T>();
744-
745746
let t1 = (t >> 64) as u64;
746747
let t2 = t as u64;
747-
TypeId { t: (t1, t2) }
748+
749+
TypeId {
750+
t: (t1, t2),
751+
#[cfg(feature = "debug_typeid")]
752+
name: type_name::<T>(),
753+
}
748754
}
749755

750756
fn as_u128(self) -> u128 {
@@ -775,7 +781,15 @@ impl hash::Hash for TypeId {
775781
#[stable(feature = "rust1", since = "1.0.0")]
776782
impl fmt::Debug for TypeId {
777783
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
778-
write!(f, "TypeId({:#034x})", self.as_u128())
784+
#[cfg(feature = "debug_typeid")]
785+
{
786+
write!(f, "TypeId({:#034x} = {})", self.as_u128(), self.name)?;
787+
}
788+
#[cfg(not(feature = "debug_typeid"))]
789+
{
790+
write!(f, "TypeId({:#034x})", self.as_u128())?;
791+
}
792+
Ok(())
779793
}
780794
}
781795

core/src/net/ip_addr.rs

+60
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,28 @@ impl IpAddr {
451451
IpAddr::V6(v6) => v6.to_canonical(),
452452
}
453453
}
454+
455+
/// Returns the eight-bit integers this address consists of as a slice.
456+
///
457+
/// # Examples
458+
///
459+
/// ```
460+
/// #![feature(ip_as_octets)]
461+
///
462+
/// use std::net::{Ipv4Addr, Ipv6Addr, IpAddr};
463+
///
464+
/// assert_eq!(IpAddr::V4(Ipv4Addr::LOCALHOST).as_octets(), &[127, 0, 0, 1]);
465+
/// assert_eq!(IpAddr::V6(Ipv6Addr::LOCALHOST).as_octets(),
466+
/// &[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1])
467+
/// ```
468+
#[unstable(feature = "ip_as_octets", issue = "137259")]
469+
#[inline]
470+
pub const fn as_octets(&self) -> &[u8] {
471+
match self {
472+
IpAddr::V4(ip) => ip.as_octets().as_slice(),
473+
IpAddr::V6(ip) => ip.as_octets().as_slice(),
474+
}
475+
}
454476
}
455477

456478
impl Ipv4Addr {
@@ -616,6 +638,25 @@ impl Ipv4Addr {
616638
Ipv4Addr { octets }
617639
}
618640

641+
/// Returns the four eight-bit integers that make up this address
642+
/// as a slice.
643+
///
644+
/// # Examples
645+
///
646+
/// ```
647+
/// #![feature(ip_as_octets)]
648+
///
649+
/// use std::net::Ipv4Addr;
650+
///
651+
/// let addr = Ipv4Addr::new(127, 0, 0, 1);
652+
/// assert_eq!(addr.as_octets(), &[127, 0, 0, 1]);
653+
/// ```
654+
#[unstable(feature = "ip_as_octets", issue = "137259")]
655+
#[inline]
656+
pub const fn as_octets(&self) -> &[u8; 4] {
657+
&self.octets
658+
}
659+
619660
/// Returns [`true`] for the special 'unspecified' address (`0.0.0.0`).
620661
///
621662
/// This property is defined in _UNIX Network Programming, Second Edition_,
@@ -2001,6 +2042,25 @@ impl Ipv6Addr {
20012042
pub const fn from_octets(octets: [u8; 16]) -> Ipv6Addr {
20022043
Ipv6Addr { octets }
20032044
}
2045+
2046+
/// Returns the sixteen eight-bit integers the IPv6 address consists of
2047+
/// as a slice.
2048+
///
2049+
/// # Examples
2050+
///
2051+
/// ```
2052+
/// #![feature(ip_as_octets)]
2053+
///
2054+
/// use std::net::Ipv6Addr;
2055+
///
2056+
/// assert_eq!(Ipv6Addr::new(0xff00, 0, 0, 0, 0, 0, 0, 0).as_octets(),
2057+
/// &[255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
2058+
/// ```
2059+
#[unstable(feature = "ip_as_octets", issue = "137259")]
2060+
#[inline]
2061+
pub const fn as_octets(&self) -> &[u8; 16] {
2062+
&self.octets
2063+
}
20042064
}
20052065

20062066
/// Writes an Ipv6Addr, conforming to the canonical style described by

coretests/tests/any.rs

+8
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,14 @@ fn any_unsized() {
118118
is_any::<[i32]>();
119119
}
120120

121+
#[cfg(feature = "debug_typeid")]
122+
#[test]
123+
fn debug_typeid_includes_name() {
124+
let type_id = TypeId::of::<[usize; 2]>();
125+
let debug_str = format!("{type_id:?}");
126+
assert!(debug_str.ends_with("= [usize; 2])"), "{debug_str:?} did not match");
127+
}
128+
121129
#[test]
122130
fn distinct_type_names() {
123131
// https://github.com/rust-lang/rust/issues/84666

std/Cargo.toml

+7
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,13 @@ panic_immediate_abort = [
110110
# Choose algorithms that are optimized for binary size instead of runtime performance
111111
optimize_for_size = ["core/optimize_for_size", "alloc/optimize_for_size"]
112112

113+
# Make `RefCell` store additional debugging information, which is printed out when
114+
# a borrow error occurs
115+
debug_refcell = ["core/debug_refcell"]
116+
# Make `TypeId` store a reference to the name of the type, so that it can print that name.
117+
debug_typeid = ["core/debug_typeid"]
118+
119+
113120
# Enable std_detect default features for stdarch/crates/std_detect:
114121
# https://github.com/rust-lang/stdarch/blob/master/crates/std_detect/Cargo.toml
115122
std_detect_file_io = ["std_detect/std_detect_file_io"]

std/src/ffi/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -201,5 +201,5 @@ pub use self::c_str::{CStr, CString};
201201
#[doc(inline)]
202202
pub use self::os_str::{OsStr, OsString};
203203

204-
#[unstable(feature = "os_str_display", issue = "120048")]
204+
#[stable(feature = "os_str_display", since = "CURRENT_RUSTC_VERSION")]
205205
pub mod os_str;

std/src/ffi/os_str.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -1204,13 +1204,12 @@ impl OsStr {
12041204
/// # Examples
12051205
///
12061206
/// ```
1207-
/// #![feature(os_str_display)]
12081207
/// use std::ffi::OsStr;
12091208
///
12101209
/// let s = OsStr::new("Hello, world!");
12111210
/// println!("{}", s.display());
12121211
/// ```
1213-
#[unstable(feature = "os_str_display", issue = "120048")]
1212+
#[stable(feature = "os_str_display", since = "CURRENT_RUSTC_VERSION")]
12141213
#[must_use = "this does not display the `OsStr`; \
12151214
it returns an object that can be displayed"]
12161215
#[inline]
@@ -1559,7 +1558,6 @@ impl fmt::Debug for OsStr {
15591558
/// # Examples
15601559
///
15611560
/// ```
1562-
/// #![feature(os_str_display)]
15631561
/// use std::ffi::OsStr;
15641562
///
15651563
/// let s = OsStr::new("Hello, world!");
@@ -1568,19 +1566,19 @@ impl fmt::Debug for OsStr {
15681566
///
15691567
/// [`Display`]: fmt::Display
15701568
/// [`format!`]: crate::format
1571-
#[unstable(feature = "os_str_display", issue = "120048")]
1569+
#[stable(feature = "os_str_display", since = "CURRENT_RUSTC_VERSION")]
15721570
pub struct Display<'a> {
15731571
os_str: &'a OsStr,
15741572
}
15751573

1576-
#[unstable(feature = "os_str_display", issue = "120048")]
1574+
#[stable(feature = "os_str_display", since = "CURRENT_RUSTC_VERSION")]
15771575
impl fmt::Debug for Display<'_> {
15781576
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
15791577
fmt::Debug::fmt(&self.os_str, f)
15801578
}
15811579
}
15821580

1583-
#[unstable(feature = "os_str_display", issue = "120048")]
1581+
#[stable(feature = "os_str_display", since = "CURRENT_RUSTC_VERSION")]
15841582
impl fmt::Display for Display<'_> {
15851583
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
15861584
fmt::Display::fmt(&self.os_str.inner, f)

std/src/sys/pal/wasi/stdio.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#![forbid(unsafe_op_in_unsafe_fn)]
22

33
use super::fd::WasiFd;
4-
use crate::io::{self, IoSlice, IoSliceMut};
4+
use crate::io::{self, BorrowedCursor, IoSlice, IoSliceMut};
55
use crate::mem::ManuallyDrop;
66
use crate::os::raw;
77
use crate::os::wasi::io::{AsRawFd, FromRawFd};
@@ -28,6 +28,10 @@ impl io::Read for Stdin {
2828
self.read_vectored(&mut [IoSliceMut::new(data)])
2929
}
3030

31+
fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> io::Result<()> {
32+
ManuallyDrop::new(unsafe { WasiFd::from_raw_fd(self.as_raw_fd()) }).read_buf(buf)
33+
}
34+
3135
fn read_vectored(&mut self, data: &mut [IoSliceMut<'_>]) -> io::Result<usize> {
3236
ManuallyDrop::new(unsafe { WasiFd::from_raw_fd(self.as_raw_fd()) }).read(data)
3337
}
@@ -64,6 +68,7 @@ impl io::Write for Stdout {
6468
fn is_write_vectored(&self) -> bool {
6569
true
6670
}
71+
6772
fn flush(&mut self) -> io::Result<()> {
6873
Ok(())
6974
}

sysroot/Cargo.toml

+3-1
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,13 @@ compiler-builtins-mem = ["std/compiler-builtins-mem"]
1919
compiler-builtins-no-asm = ["std/compiler-builtins-no-asm"]
2020
compiler-builtins-no-f16-f128 = ["std/compiler-builtins-no-f16-f128"]
2121
compiler-builtins-mangled-names = ["std/compiler-builtins-mangled-names"]
22+
debug_refcell = ["std/debug_refcell"]
23+
debug_typeid = ["std/debug_typeid"]
2224
llvm-libunwind = ["std/llvm-libunwind"]
2325
system-llvm-libunwind = ["std/system-llvm-libunwind"]
26+
optimize_for_size = ["std/optimize_for_size"]
2427
panic-unwind = ["std/panic_unwind"]
2528
panic_immediate_abort = ["std/panic_immediate_abort"]
26-
optimize_for_size = ["std/optimize_for_size"]
2729
profiler = ["dep:profiler_builtins"]
2830
std_detect_file_io = ["std/std_detect_file_io"]
2931
std_detect_dlsym_getauxval = ["std/std_detect_dlsym_getauxval"]

0 commit comments

Comments
 (0)