Skip to content

Commit c03bf54

Browse files
authored
Rollup merge of rust-lang#93392 - GKFX:char-docs, r=scottmcm
Clarify documentation on char::MAX As mentioned in rust-lang#91836 (comment), the documentation on `char::MAX` is not quite correct – USVs are not "only ones within a certain range", they are code points _outside_ a certain range. I have corrected this and given the actual numbers as there is no reason to hide them.
2 parents 76857fb + 9aaf52b commit c03bf54

File tree

2 files changed

+22
-12
lines changed

2 files changed

+22
-12
lines changed

library/core/src/char/methods.rs

+11-6
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,19 @@ use super::*;
99

1010
#[lang = "char"]
1111
impl char {
12-
/// The highest valid code point a `char` can have.
12+
/// The highest valid code point a `char` can have, `'\u{10FFFF}'`.
1313
///
14-
/// A `char` is a [Unicode Scalar Value], which means that it is a [Code
15-
/// Point], but only ones within a certain range. `MAX` is the highest valid
16-
/// code point that's a valid [Unicode Scalar Value].
14+
/// # Examples
15+
///
16+
/// ```
17+
/// # fn something_which_returns_char() -> char { 'a' }
18+
/// let c: char = something_which_returns_char();
19+
/// assert!(c <= char::MAX);
1720
///
18-
/// [Unicode Scalar Value]: https://www.unicode.org/glossary/#unicode_scalar_value
19-
/// [Code Point]: https://www.unicode.org/glossary/#code_point
21+
/// let value_at_max = char::MAX as u32;
22+
/// assert_eq!(char::from_u32(value_at_max), Some('\u{10FFFF}'));
23+
/// assert_eq!(char::from_u32(value_at_max + 1), None);
24+
/// ```
2025
#[stable(feature = "assoc_char_consts", since = "1.52.0")]
2126
pub const MAX: char = '\u{10ffff}';
2227

library/core/src/char/mod.rs

+11-6
Original file line numberDiff line numberDiff line change
@@ -89,14 +89,19 @@ const MAX_THREE_B: u32 = 0x10000;
8989
Cn Unassigned a reserved unassigned code point or a noncharacter
9090
*/
9191

92-
/// The highest valid code point a `char` can have.
92+
/// The highest valid code point a `char` can have, `'\u{10FFFF}'`.
9393
///
94-
/// A [`char`] is a [Unicode Scalar Value], which means that it is a [Code
95-
/// Point], but only ones within a certain range. `MAX` is the highest valid
96-
/// code point that's a valid [Unicode Scalar Value].
94+
/// # Examples
9795
///
98-
/// [Unicode Scalar Value]: https://www.unicode.org/glossary/#unicode_scalar_value
99-
/// [Code Point]: https://www.unicode.org/glossary/#code_point
96+
/// ```
97+
/// # fn something_which_returns_char() -> char { 'a' }
98+
/// let c: char = something_which_returns_char();
99+
/// assert!(c <= char::MAX);
100+
///
101+
/// let value_at_max = char::MAX as u32;
102+
/// assert_eq!(char::from_u32(value_at_max), Some('\u{10FFFF}'));
103+
/// assert_eq!(char::from_u32(value_at_max + 1), None);
104+
/// ```
100105
#[stable(feature = "rust1", since = "1.0.0")]
101106
pub const MAX: char = char::MAX;
102107

0 commit comments

Comments
 (0)