Skip to content

Commit 1b4eac3

Browse files
committed
Auto merge of rust-lang#140298 - matthiaskrgr:rollup-5tc1gvb, r=matthiaskrgr
Rollup of 8 pull requests Successful merges: - rust-lang#137683 (Add a tidy check for GCC submodule version) - rust-lang#138968 (Update the index of Result to make the summary more comprehensive) - rust-lang#139572 (docs(std): mention const blocks in const keyword doc page) - rust-lang#140152 (Unify the format of rustc cli flags) - rust-lang#140193 (fix ICE in `#[naked]` attribute validation) - rust-lang#140205 (Tidying up UI tests [2/N]) - rust-lang#140284 (remove expect() in `unnecessary_transmutes`) - rust-lang#140290 (rustdoc: fix typo change from equivelent to equivalent) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 0cc7fb1 + 7cab094 commit 1b4eac3

File tree

2 files changed

+38
-3
lines changed

2 files changed

+38
-3
lines changed

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/src/keyword_docs.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ mod break_keyword {}
119119

120120
#[doc(keyword = "const")]
121121
//
122-
/// Compile-time constants, compile-time evaluable functions, and raw pointers.
122+
/// Compile-time constants, compile-time blocks, compile-time evaluable functions, and raw pointers.
123123
///
124124
/// ## Compile-time constants
125125
///
@@ -166,6 +166,12 @@ mod break_keyword {}
166166
///
167167
/// For more detail on `const`, see the [Rust Book] or the [Reference].
168168
///
169+
/// ## Compile-time blocks
170+
///
171+
/// The `const` keyword can also be used to define a block of code that is evaluated at compile time.
172+
/// This is useful for ensuring certain computations are completed before optimizations happen, as well as
173+
/// before runtime. For more details, see the [Reference][const-blocks].
174+
///
169175
/// ## Compile-time evaluable functions
170176
///
171177
/// The other main use of the `const` keyword is in `const fn`. This marks a function as being
@@ -184,6 +190,7 @@ mod break_keyword {}
184190
/// [pointer primitive]: pointer
185191
/// [Rust Book]: ../book/ch03-01-variables-and-mutability.html#constants
186192
/// [Reference]: ../reference/items/constant-items.html
193+
/// [const-blocks]: ../reference/expressions/block-expr.html#const-blocks
187194
/// [const-eval]: ../reference/const_eval.html
188195
mod const_keyword {}
189196

0 commit comments

Comments
 (0)