about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMichael Goulet <michael@errs.io>2023-02-03 14:15:24 -0800
committerGitHub <noreply@github.com>2023-02-03 14:15:24 -0800
commit13bd75f425f084d63817336db5ca433bc0655786 (patch)
tree4bd560ab45691d951ce6a3b70229091e093a69b7
parentef520bd82a43caed2bd28f05d8dd29a74d23ba04 (diff)
parentb384692f4c7fa61b36f9314d6e597154914f4957 (diff)
downloadrust-13bd75f425f084d63817336db5ca433bc0655786.tar.gz
rust-13bd75f425f084d63817336db5ca433bc0655786.zip
Rollup merge of #107632 - ameknite:issue-107622-fix, r=jyn514
Clarifying that .map() returns None if None.

Fix #107622
-rw-r--r--library/core/src/option.rs6
1 files changed, 4 insertions, 2 deletions
diff --git a/library/core/src/option.rs b/library/core/src/option.rs
index c43b728022d..5d5e9559034 100644
--- a/library/core/src/option.rs
+++ b/library/core/src/option.rs
@@ -943,7 +943,7 @@ impl<T> Option<T> {
     // Transforming contained values
     /////////////////////////////////////////////////////////////////////////
 
-    /// Maps an `Option<T>` to `Option<U>` by applying a function to a contained value.
+    /// Maps an `Option<T>` to `Option<U>` by applying a function to a contained value (if `Some`) or returns `None` (if `None`).
     ///
     /// # Examples
     ///
@@ -955,8 +955,10 @@ impl<T> Option<T> {
     /// let maybe_some_string = Some(String::from("Hello, World!"));
     /// // `Option::map` takes self *by value*, consuming `maybe_some_string`
     /// let maybe_some_len = maybe_some_string.map(|s| s.len());
-    ///
     /// assert_eq!(maybe_some_len, Some(13));
+    ///
+    /// let x: Option<&str> = None;
+    /// assert_eq!(x.map(|s| s.len()), None);
     /// ```
     #[inline]
     #[stable(feature = "rust1", since = "1.0.0")]