Skip to content

Commit ed3b774

Browse files
committed
Apply udd/idd documentation to usize/isize as well
1 parent 47f497d commit ed3b774

File tree

1 file changed

+36
-26
lines changed

1 file changed

+36
-26
lines changed

library/core/src/num/mod.rs

Lines changed: 36 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1561,30 +1561,40 @@ from_str_radix! { signed i8 i16 i32 i64 i128 }
15611561
// Re-use the relevant implementation of from_str_radix for isize and usize to avoid outputting two
15621562
// identical functions.
15631563
macro_rules! from_str_radix_size_impl {
1564-
($($t:ident $size:ty),*) => {$(
1564+
($($signedness:ident $t:ident $size:ty),*) => {$(
15651565
impl $size {
1566-
/// Converts a string slice in a given base to an integer.
1567-
///
1568-
/// The string is expected to be an optional `+` sign
1569-
/// followed by digits.
1570-
/// Leading and trailing whitespace represent an error.
1571-
/// Digits are a subset of these characters, depending on `radix`:
1572-
///
1573-
/// * `0-9`
1574-
/// * `a-z`
1575-
/// * `A-Z`
1576-
///
1577-
/// # Panics
1578-
///
1579-
/// This function panics if `radix` is not in the range from 2 to 36.
1580-
///
1581-
/// # Examples
1582-
///
1583-
/// Basic usage:
1584-
///
1585-
/// ```
1586-
#[doc = concat!("assert_eq!(", stringify!($size), "::from_str_radix(\"A\", 16), Ok(10));")]
1587-
/// ```
1566+
/// Converts a string slice in a given base to an integer.
1567+
///
1568+
/// The string is expected to be an optional
1569+
#[doc = sign_dependent_expr!{
1570+
$signedness ?
1571+
if signed {
1572+
" `+` or `-` "
1573+
}
1574+
if unsigned {
1575+
" `+` "
1576+
}
1577+
}]
1578+
/// sign followed by only digits. Leading and trailing non-digit characters (including
1579+
/// whitespace) represent an error. Underscores (which are accepted in rust literals)
1580+
/// also represent an error.
1581+
///
1582+
/// Digits are a subset of these characters, depending on `radix`:
1583+
/// * `0-9`
1584+
/// * `a-z`
1585+
/// * `A-Z`
1586+
///
1587+
/// # Panics
1588+
///
1589+
/// This function panics if `radix` is not in the range from 2 to 36.
1590+
///
1591+
/// # Examples
1592+
///
1593+
/// Basic usage:
1594+
///
1595+
/// ```
1596+
#[doc = concat!("assert_eq!(", stringify!($int_ty), "::from_str_radix(\"A\", 16), Ok(10));")]
1597+
/// ```
15881598
#[stable(feature = "rust1", since = "1.0.0")]
15891599
#[rustc_const_unstable(feature = "const_int_from_str", issue = "59133")]
15901600
pub const fn from_str_radix(src: &str, radix: u32) -> Result<$size, ParseIntError> {
@@ -1597,8 +1607,8 @@ macro_rules! from_str_radix_size_impl {
15971607
}
15981608

15991609
#[cfg(target_pointer_width = "16")]
1600-
from_str_radix_size_impl! { i16 isize, u16 usize }
1610+
from_str_radix_size_impl! { signed i16 isize, unsigned u16 usize }
16011611
#[cfg(target_pointer_width = "32")]
1602-
from_str_radix_size_impl! { i32 isize, u32 usize }
1612+
from_str_radix_size_impl! { signed i32 isize, unsigned u32 usize }
16031613
#[cfg(target_pointer_width = "64")]
1604-
from_str_radix_size_impl! { i64 isize, u64 usize }
1614+
from_str_radix_size_impl! { signed i64 isize, unsigned u64 usize }

0 commit comments

Comments
 (0)