From 2fb617ca0f1edd42116ebe8e8175b4abb2042a9b Mon Sep 17 00:00:00 2001 From: George Bateman Date: Thu, 27 Jan 2022 22:13:01 +0000 Subject: [PATCH 1/2] Clarify documentation on char::MAX --- library/core/src/char/methods.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/library/core/src/char/methods.rs b/library/core/src/char/methods.rs index 7250dca2adfe4..62ef1ca788549 100644 --- a/library/core/src/char/methods.rs +++ b/library/core/src/char/methods.rs @@ -9,11 +9,11 @@ use super::*; #[lang = "char"] impl char { - /// The highest valid code point a `char` can have. + /// The highest valid code point a `char` can have, 0x10FFFF. /// - /// A `char` is a [Unicode Scalar Value], which means that it is a [Code - /// Point], but only ones within a certain range. `MAX` is the highest valid - /// code point that's a valid [Unicode Scalar Value]. + /// A [Code Point] is any value between zero and `char::MAX`, inclusive. A + /// `char` is a [Unicode Scalar Value], which is a Code Point that is not + /// in the range `0xD800..=0xDFFF`. /// /// [Unicode Scalar Value]: https://www.unicode.org/glossary/#unicode_scalar_value /// [Code Point]: https://www.unicode.org/glossary/#code_point From 9aaf52b66a920f286bf235e6d5ba8c72099b1273 Mon Sep 17 00:00:00 2001 From: George Bateman Date: Sun, 30 Jan 2022 19:41:52 +0000 Subject: [PATCH 2/2] (#93392) Update char::MAX docs and core::char::MAX --- library/core/src/char/methods.rs | 17 +++++++++++------ library/core/src/char/mod.rs | 17 +++++++++++------ 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/library/core/src/char/methods.rs b/library/core/src/char/methods.rs index 62ef1ca788549..c4c0a5a6c78ad 100644 --- a/library/core/src/char/methods.rs +++ b/library/core/src/char/methods.rs @@ -9,14 +9,19 @@ use super::*; #[lang = "char"] impl char { - /// The highest valid code point a `char` can have, 0x10FFFF. + /// The highest valid code point a `char` can have, `'\u{10FFFF}'`. /// - /// A [Code Point] is any value between zero and `char::MAX`, inclusive. A - /// `char` is a [Unicode Scalar Value], which is a Code Point that is not - /// in the range `0xD800..=0xDFFF`. + /// # Examples + /// + /// ``` + /// # fn something_which_returns_char() -> char { 'a' } + /// let c: char = something_which_returns_char(); + /// assert!(c <= char::MAX); /// - /// [Unicode Scalar Value]: https://www.unicode.org/glossary/#unicode_scalar_value - /// [Code Point]: https://www.unicode.org/glossary/#code_point + /// let value_at_max = char::MAX as u32; + /// assert_eq!(char::from_u32(value_at_max), Some('\u{10FFFF}')); + /// assert_eq!(char::from_u32(value_at_max + 1), None); + /// ``` #[stable(feature = "assoc_char_consts", since = "1.52.0")] pub const MAX: char = '\u{10ffff}'; diff --git a/library/core/src/char/mod.rs b/library/core/src/char/mod.rs index f65f84e93aebe..9364ac4f3ec1f 100644 --- a/library/core/src/char/mod.rs +++ b/library/core/src/char/mod.rs @@ -89,14 +89,19 @@ const MAX_THREE_B: u32 = 0x10000; Cn Unassigned a reserved unassigned code point or a noncharacter */ -/// The highest valid code point a `char` can have. +/// The highest valid code point a `char` can have, `'\u{10FFFF}'`. /// -/// A [`char`] is a [Unicode Scalar Value], which means that it is a [Code -/// Point], but only ones within a certain range. `MAX` is the highest valid -/// code point that's a valid [Unicode Scalar Value]. +/// # Examples /// -/// [Unicode Scalar Value]: https://www.unicode.org/glossary/#unicode_scalar_value -/// [Code Point]: https://www.unicode.org/glossary/#code_point +/// ``` +/// # fn something_which_returns_char() -> char { 'a' } +/// let c: char = something_which_returns_char(); +/// assert!(c <= char::MAX); +/// +/// let value_at_max = char::MAX as u32; +/// assert_eq!(char::from_u32(value_at_max), Some('\u{10FFFF}')); +/// assert_eq!(char::from_u32(value_at_max + 1), None); +/// ``` #[stable(feature = "rust1", since = "1.0.0")] pub const MAX: char = char::MAX;