Skip to content

Commit ab60d5d

Browse files
author
The Miri Cronjob Bot
committed
Merge from rustc
2 parents d7c61d5 + ca37418 commit ab60d5d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+1686
-1486
lines changed

core/src/macros/mod.rs

+4
Original file line numberDiff line numberDiff line change
@@ -1138,6 +1138,10 @@ pub(crate) mod builtin {
11381138
issue = "29599",
11391139
reason = "`concat_idents` is not stable enough for use and is subject to change"
11401140
)]
1141+
#[deprecated(
1142+
since = "1.88.0",
1143+
note = "use `${concat(...)}` with the `macro_metavar_expr_concat` feature instead"
1144+
)]
11411145
#[rustc_builtin_macro]
11421146
#[macro_export]
11431147
macro_rules! concat_idents {

core/src/option.rs

+27-2
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,14 @@
162162
//! The [`is_some`] and [`is_none`] methods return [`true`] if the [`Option`]
163163
//! is [`Some`] or [`None`], respectively.
164164
//!
165+
//! The [`is_some_and`] and [`is_none_or`] methods apply the provided function
166+
//! to the contents of the [`Option`] to produce a boolean value.
167+
//! If this is [`None`] then a default result is returned instead without executing the function.
168+
//!
165169
//! [`is_none`]: Option::is_none
166170
//! [`is_some`]: Option::is_some
171+
//! [`is_some_and`]: Option::is_some_and
172+
//! [`is_none_or`]: Option::is_none_or
167173
//!
168174
//! ## Adapters for working with references
169175
//!
@@ -177,6 +183,10 @@
177183
//! <code>[Option]<[Pin]<[&]T>></code>
178184
//! * [`as_pin_mut`] converts from <code>[Pin]<[&mut] [Option]\<T>></code> to
179185
//! <code>[Option]<[Pin]<[&mut] T>></code>
186+
//! * [`as_slice`] returns a one-element slice of the contained value, if any.
187+
//! If this is [`None`], an empty slice is returned.
188+
//! * [`as_mut_slice`] returns a mutable one-element slice of the contained value, if any.
189+
//! If this is [`None`], an empty slice is returned.
180190
//!
181191
//! [&]: reference "shared reference"
182192
//! [&mut]: reference "mutable reference"
@@ -187,6 +197,8 @@
187197
//! [`as_pin_mut`]: Option::as_pin_mut
188198
//! [`as_pin_ref`]: Option::as_pin_ref
189199
//! [`as_ref`]: Option::as_ref
200+
//! [`as_slice`]: Option::as_slice
201+
//! [`as_mut_slice`]: Option::as_mut_slice
190202
//!
191203
//! ## Extracting the contained value
192204
//!
@@ -200,12 +212,15 @@
200212
//! (which must implement the [`Default`] trait)
201213
//! * [`unwrap_or_else`] returns the result of evaluating the provided
202214
//! function
215+
//! * [`unwrap_unchecked`] produces *[undefined behavior]*
203216
//!
204217
//! [`expect`]: Option::expect
205218
//! [`unwrap`]: Option::unwrap
206219
//! [`unwrap_or`]: Option::unwrap_or
207220
//! [`unwrap_or_default`]: Option::unwrap_or_default
208221
//! [`unwrap_or_else`]: Option::unwrap_or_else
222+
//! [`unwrap_unchecked`]: Option::unwrap_unchecked
223+
//! [undefined behavior]: https://doc.rust-lang.org/reference/behavior-considered-undefined.html
209224
//!
210225
//! ## Transforming contained values
211226
//!
@@ -230,15 +245,17 @@
230245
//! * [`filter`] calls the provided predicate function on the contained
231246
//! value `t` if the [`Option`] is [`Some(t)`], and returns [`Some(t)`]
232247
//! if the function returns `true`; otherwise, returns [`None`]
233-
//! * [`flatten`] removes one level of nesting from an
234-
//! [`Option<Option<T>>`]
248+
//! * [`flatten`] removes one level of nesting from an [`Option<Option<T>>`]
249+
//! * [`inspect`] method takes ownership of the [`Option`] and applies
250+
//! the provided function to the contained value by reference if [`Some`]
235251
//! * [`map`] transforms [`Option<T>`] to [`Option<U>`] by applying the
236252
//! provided function to the contained value of [`Some`] and leaving
237253
//! [`None`] values unchanged
238254
//!
239255
//! [`Some(t)`]: Some
240256
//! [`filter`]: Option::filter
241257
//! [`flatten`]: Option::flatten
258+
//! [`inspect`]: Option::inspect
242259
//! [`map`]: Option::map
243260
//!
244261
//! These methods transform [`Option<T>`] to a value of a possibly
@@ -621,6 +638,10 @@ impl<T> Option<T> {
621638
///
622639
/// let x: Option<u32> = None;
623640
/// assert_eq!(x.is_some_and(|x| x > 1), false);
641+
///
642+
/// let x: Option<String> = Some("ownership".to_string());
643+
/// assert_eq!(x.as_ref().is_some_and(|x| x.len() > 1), true);
644+
/// println!("still alive {:?}", x);
624645
/// ```
625646
#[must_use]
626647
#[inline]
@@ -665,6 +686,10 @@ impl<T> Option<T> {
665686
///
666687
/// let x: Option<u32> = None;
667688
/// assert_eq!(x.is_none_or(|x| x > 1), true);
689+
///
690+
/// let x: Option<String> = Some("ownership".to_string());
691+
/// assert_eq!(x.as_ref().is_none_or(|x| x.len() > 1), true);
692+
/// println!("still alive {:?}", x);
668693
/// ```
669694
#[must_use]
670695
#[inline]

core/src/prelude/v1.rs

+1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ pub use crate::hash::macros::Hash;
5959

6060
#[stable(feature = "builtin_macro_prelude", since = "1.38.0")]
6161
#[allow(deprecated)]
62+
#[cfg_attr(bootstrap, allow(deprecated_in_future))]
6263
#[doc(no_inline)]
6364
pub use crate::{
6465
assert, cfg, column, compile_error, concat, concat_idents, env, file, format_args,

core/src/result.rs

+30-2
Original file line numberDiff line numberDiff line change
@@ -259,8 +259,14 @@
259259
//! The [`is_ok`] and [`is_err`] methods return [`true`] if the [`Result`]
260260
//! is [`Ok`] or [`Err`], respectively.
261261
//!
262+
//! The [`is_ok_and`] and [`is_err_and`] methods apply the provided function
263+
//! to the contents of the [`Result`] to produce a boolean value. If the [`Result`] does not have the expected variant
264+
//! then [`false`] is returned instead without executing the function.
265+
//!
262266
//! [`is_err`]: Result::is_err
263267
//! [`is_ok`]: Result::is_ok
268+
//! [`is_ok_and`]: Result::is_ok_and
269+
//! [`is_err_and`]: Result::is_err_and
264270
//!
265271
//! ## Adapters for working with references
266272
//!
@@ -287,6 +293,7 @@
287293
//! (which must implement the [`Default`] trait)
288294
//! * [`unwrap_or_else`] returns the result of evaluating the provided
289295
//! function
296+
//! * [`unwrap_unchecked`] produces *[undefined behavior]*
290297
//!
291298
//! The panicking methods [`expect`] and [`unwrap`] require `E` to
292299
//! implement the [`Debug`] trait.
@@ -297,17 +304,22 @@
297304
//! [`unwrap_or`]: Result::unwrap_or
298305
//! [`unwrap_or_default`]: Result::unwrap_or_default
299306
//! [`unwrap_or_else`]: Result::unwrap_or_else
307+
//! [`unwrap_unchecked`]: Result::unwrap_unchecked
308+
//! [undefined behavior]: https://doc.rust-lang.org/reference/behavior-considered-undefined.html
300309
//!
301310
//! These methods extract the contained value in a [`Result<T, E>`] when it
302311
//! is the [`Err`] variant. They require `T` to implement the [`Debug`]
303312
//! trait. If the [`Result`] is [`Ok`]:
304313
//!
305314
//! * [`expect_err`] panics with a provided custom message
306315
//! * [`unwrap_err`] panics with a generic message
316+
//! * [`unwrap_err_unchecked`] produces *[undefined behavior]*
307317
//!
308318
//! [`Debug`]: crate::fmt::Debug
309319
//! [`expect_err`]: Result::expect_err
310320
//! [`unwrap_err`]: Result::unwrap_err
321+
//! [`unwrap_err_unchecked`]: Result::unwrap_err_unchecked
322+
//! [undefined behavior]: https://doc.rust-lang.org/reference/behavior-considered-undefined.html
311323
//!
312324
//! ## Transforming contained values
313325
//!
@@ -330,21 +342,29 @@
330342
//! [`Some(v)`]: Option::Some
331343
//! [`transpose`]: Result::transpose
332344
//!
333-
//! This method transforms the contained value of the [`Ok`] variant:
345+
//! These methods transform the contained value of the [`Ok`] variant:
334346
//!
335347
//! * [`map`] transforms [`Result<T, E>`] into [`Result<U, E>`] by applying
336348
//! the provided function to the contained value of [`Ok`] and leaving
337349
//! [`Err`] values unchanged
350+
//! * [`inspect`] takes ownership of the [`Result`], applies the
351+
//! provided function to the contained value by reference,
352+
//! and then returns the [`Result`]
338353
//!
339354
//! [`map`]: Result::map
355+
//! [`inspect`]: Result::inspect
340356
//!
341-
//! This method transforms the contained value of the [`Err`] variant:
357+
//! These methods transform the contained value of the [`Err`] variant:
342358
//!
343359
//! * [`map_err`] transforms [`Result<T, E>`] into [`Result<T, F>`] by
344360
//! applying the provided function to the contained value of [`Err`] and
345361
//! leaving [`Ok`] values unchanged
362+
//! * [`inspect_err`] takes ownership of the [`Result`], applies the
363+
//! provided function to the contained value of [`Err`] by reference,
364+
//! and then returns the [`Result`]
346365
//!
347366
//! [`map_err`]: Result::map_err
367+
//! [`inspect_err`]: Result::inspect_err
348368
//!
349369
//! These methods transform a [`Result<T, E>`] into a value of a possibly
350370
//! different type `U`:
@@ -578,6 +598,10 @@ impl<T, E> Result<T, E> {
578598
///
579599
/// let x: Result<u32, &str> = Err("hey");
580600
/// assert_eq!(x.is_ok_and(|x| x > 1), false);
601+
///
602+
/// let x: Result<String, &str> = Ok("ownership".to_string());
603+
/// assert_eq!(x.as_ref().is_ok_and(|x| x.len() > 1), true);
604+
/// println!("still alive {:?}", x);
581605
/// ```
582606
#[must_use]
583607
#[inline]
@@ -623,6 +647,10 @@ impl<T, E> Result<T, E> {
623647
///
624648
/// let x: Result<u32, Error> = Ok(123);
625649
/// assert_eq!(x.is_err_and(|x| x.kind() == ErrorKind::NotFound), false);
650+
///
651+
/// let x: Result<u32, String> = Err("ownership".to_string());
652+
/// assert_eq!(x.as_ref().is_err_and(|x| x.len() > 1), true);
653+
/// println!("still alive {:?}", x);
626654
/// ```
627655
#[must_use]
628656
#[inline]

std/Cargo.toml

+6
Original file line numberDiff line numberDiff line change
@@ -163,4 +163,10 @@ check-cfg = [
163163
# and to the `backtrace` crate which messes-up with Cargo list
164164
# of declared features, we therefor expect any feature cfg
165165
'cfg(feature, values(any()))',
166+
# Internal features aren't marked known config by default, we use these to
167+
# gate tests.
168+
'cfg(target_has_reliable_f16)',
169+
'cfg(target_has_reliable_f16_math)',
170+
'cfg(target_has_reliable_f128)',
171+
'cfg(target_has_reliable_f128_math)',
166172
]

std/build.rs

-110
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,6 @@ fn main() {
77
let target_vendor =
88
env::var("CARGO_CFG_TARGET_VENDOR").expect("CARGO_CFG_TARGET_VENDOR was not set");
99
let target_env = env::var("CARGO_CFG_TARGET_ENV").expect("CARGO_CFG_TARGET_ENV was not set");
10-
let target_abi = env::var("CARGO_CFG_TARGET_ABI").expect("CARGO_CFG_TARGET_ABI was not set");
11-
let target_pointer_width: u32 = env::var("CARGO_CFG_TARGET_POINTER_WIDTH")
12-
.expect("CARGO_CFG_TARGET_POINTER_WIDTH was not set")
13-
.parse()
14-
.unwrap();
15-
let is_miri = env::var_os("CARGO_CFG_MIRI").is_some();
1610

1711
println!("cargo:rustc-check-cfg=cfg(netbsd10)");
1812
if target_os == "netbsd" && env::var("RUSTC_STD_NETBSD10").is_ok() {
@@ -80,108 +74,4 @@ fn main() {
8074
println!("cargo:rustc-cfg=backtrace_in_libstd");
8175

8276
println!("cargo:rustc-env=STD_ENV_ARCH={}", env::var("CARGO_CFG_TARGET_ARCH").unwrap());
83-
84-
// Emit these on platforms that have no known ABI bugs, LLVM selection bugs, lowering bugs,
85-
// missing symbols, or other problems, to determine when tests get run.
86-
// If more broken platforms are found, please update the tracking issue at
87-
// <https://github.com/rust-lang/rust/issues/116909>
88-
//
89-
// Some of these match arms are redundant; the goal is to separate reasons that the type is
90-
// unreliable, even when multiple reasons might fail the same platform.
91-
println!("cargo:rustc-check-cfg=cfg(reliable_f16)");
92-
println!("cargo:rustc-check-cfg=cfg(reliable_f128)");
93-
94-
// This is a step beyond only having the types and basic functions available. Math functions
95-
// aren't consistently available or correct.
96-
println!("cargo:rustc-check-cfg=cfg(reliable_f16_math)");
97-
println!("cargo:rustc-check-cfg=cfg(reliable_f128_math)");
98-
99-
let has_reliable_f16 = match (target_arch.as_str(), target_os.as_str()) {
100-
// We can always enable these in Miri as that is not affected by codegen bugs.
101-
_ if is_miri => true,
102-
// Selection failure <https://github.com/llvm/llvm-project/issues/50374>
103-
("s390x", _) => false,
104-
// Unsupported <https://github.com/llvm/llvm-project/issues/94434>
105-
("arm64ec", _) => false,
106-
// MinGW ABI bugs <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115054>
107-
("x86_64", "windows") if target_env == "gnu" && target_abi != "llvm" => false,
108-
// Infinite recursion <https://github.com/llvm/llvm-project/issues/97981>
109-
("csky", _) => false,
110-
("hexagon", _) => false,
111-
("powerpc" | "powerpc64", _) => false,
112-
("sparc" | "sparc64", _) => false,
113-
("wasm32" | "wasm64", _) => false,
114-
// `f16` support only requires that symbols converting to and from `f32` are available. We
115-
// provide these in `compiler-builtins`, so `f16` should be available on all platforms that
116-
// do not have other ABI issues or LLVM crashes.
117-
_ => true,
118-
};
119-
120-
let has_reliable_f128 = match (target_arch.as_str(), target_os.as_str()) {
121-
// We can always enable these in Miri as that is not affected by codegen bugs.
122-
_ if is_miri => true,
123-
// Unsupported <https://github.com/llvm/llvm-project/issues/94434>
124-
("arm64ec", _) => false,
125-
// Selection bug <https://github.com/llvm/llvm-project/issues/96432>
126-
("mips64" | "mips64r6", _) => false,
127-
// Selection bug <https://github.com/llvm/llvm-project/issues/95471>
128-
("nvptx64", _) => false,
129-
// ABI bugs <https://github.com/rust-lang/rust/issues/125109> et al. (full
130-
// list at <https://github.com/rust-lang/rust/issues/116909>)
131-
("powerpc" | "powerpc64", _) => false,
132-
// ABI unsupported <https://github.com/llvm/llvm-project/issues/41838>
133-
("sparc", _) => false,
134-
// Stack alignment bug <https://github.com/llvm/llvm-project/issues/77401>. NB: tests may
135-
// not fail if our compiler-builtins is linked.
136-
("x86", _) => false,
137-
// MinGW ABI bugs <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115054>
138-
("x86_64", "windows") if target_env == "gnu" && target_abi != "llvm" => false,
139-
// There are no known problems on other platforms, so the only requirement is that symbols
140-
// are available. `compiler-builtins` provides all symbols required for core `f128`
141-
// support, so this should work for everything else.
142-
_ => true,
143-
};
144-
145-
// Configure platforms that have reliable basics but may have unreliable math.
146-
147-
// LLVM is currently adding missing routines, <https://github.com/llvm/llvm-project/issues/93566>
148-
let has_reliable_f16_math = has_reliable_f16
149-
&& match (target_arch.as_str(), target_os.as_str()) {
150-
// FIXME: Disabled on Miri as the intrinsics are not implemented yet.
151-
_ if is_miri => false,
152-
// x86 has a crash for `powi`: <https://github.com/llvm/llvm-project/issues/105747>
153-
("x86" | "x86_64", _) => false,
154-
// Assume that working `f16` means working `f16` math for most platforms, since
155-
// operations just go through `f32`.
156-
_ => true,
157-
};
158-
159-
let has_reliable_f128_math = has_reliable_f128
160-
&& match (target_arch.as_str(), target_os.as_str()) {
161-
// FIXME: Disabled on Miri as the intrinsics are not implemented yet.
162-
_ if is_miri => false,
163-
// LLVM lowers `fp128` math to `long double` symbols even on platforms where
164-
// `long double` is not IEEE binary128. See
165-
// <https://github.com/llvm/llvm-project/issues/44744>.
166-
//
167-
// This rules out anything that doesn't have `long double` = `binary128`; <= 32 bits
168-
// (ld is `f64`), anything other than Linux (Windows and MacOS use `f64`), and `x86`
169-
// (ld is 80-bit extended precision).
170-
("x86_64", _) => false,
171-
(_, "linux") if target_pointer_width == 64 => true,
172-
_ => false,
173-
};
174-
175-
if has_reliable_f16 {
176-
println!("cargo:rustc-cfg=reliable_f16");
177-
}
178-
if has_reliable_f128 {
179-
println!("cargo:rustc-cfg=reliable_f128");
180-
}
181-
if has_reliable_f16_math {
182-
println!("cargo:rustc-cfg=reliable_f16_math");
183-
}
184-
if has_reliable_f128_math {
185-
println!("cargo:rustc-cfg=reliable_f128_math");
186-
}
18777
}

std/src/env.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
use crate::error::Error;
1414
use crate::ffi::{OsStr, OsString};
1515
use crate::path::{Path, PathBuf};
16-
use crate::sys::os as os_imp;
16+
use crate::sys::{env as env_imp, os as os_imp};
1717
use crate::{fmt, io, sys};
1818

1919
/// Returns the current working directory as a [`PathBuf`].
@@ -96,7 +96,7 @@ pub struct Vars {
9696
/// [`env::vars_os()`]: vars_os
9797
#[stable(feature = "env", since = "1.0.0")]
9898
pub struct VarsOs {
99-
inner: os_imp::Env,
99+
inner: env_imp::Env,
100100
}
101101

102102
/// Returns an iterator of (variable, value) pairs of strings, for all the
@@ -150,7 +150,7 @@ pub fn vars() -> Vars {
150150
#[must_use]
151151
#[stable(feature = "env", since = "1.0.0")]
152152
pub fn vars_os() -> VarsOs {
153-
VarsOs { inner: os_imp::env() }
153+
VarsOs { inner: env_imp::env() }
154154
}
155155

156156
#[stable(feature = "env", since = "1.0.0")]
@@ -259,7 +259,7 @@ pub fn var_os<K: AsRef<OsStr>>(key: K) -> Option<OsString> {
259259
}
260260

261261
fn _var_os(key: &OsStr) -> Option<OsString> {
262-
os_imp::getenv(key)
262+
env_imp::getenv(key)
263263
}
264264

265265
/// The error type for operations interacting with environment variables.
@@ -363,7 +363,7 @@ impl Error for VarError {
363363
#[stable(feature = "env", since = "1.0.0")]
364364
pub unsafe fn set_var<K: AsRef<OsStr>, V: AsRef<OsStr>>(key: K, value: V) {
365365
let (key, value) = (key.as_ref(), value.as_ref());
366-
unsafe { os_imp::setenv(key, value) }.unwrap_or_else(|e| {
366+
unsafe { env_imp::setenv(key, value) }.unwrap_or_else(|e| {
367367
panic!("failed to set environment variable `{key:?}` to `{value:?}`: {e}")
368368
})
369369
}
@@ -434,7 +434,7 @@ pub unsafe fn set_var<K: AsRef<OsStr>, V: AsRef<OsStr>>(key: K, value: V) {
434434
#[stable(feature = "env", since = "1.0.0")]
435435
pub unsafe fn remove_var<K: AsRef<OsStr>>(key: K) {
436436
let key = key.as_ref();
437-
unsafe { os_imp::unsetenv(key) }
437+
unsafe { env_imp::unsetenv(key) }
438438
.unwrap_or_else(|e| panic!("failed to remove environment variable `{key:?}`: {e}"))
439439
}
440440

0 commit comments

Comments
 (0)