Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #66099 - Added the upper and lower bounds to the documentation of all integer types. #66664

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/libcore/internal_macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,11 @@ macro_rules! impl_fn_for_zst {
)+
}
}

/// Create a dynamic doc comment.
macro_rules! doc_comment {
($x:expr, $($tt:tt)*) => {
#[doc = $x]
$($tt)*
};
}
7 changes: 6 additions & 1 deletion src/libcore/num/i128.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,9 @@

#![stable(feature = "i128", since = "1.26.0")]

int_module! { i128, #[stable(feature = "i128", since="1.26.0")] }
int_module! {
i128,
-170141183460469231731687303715884105728,
170141183460469231731687303715884105727,
#[stable(feature = "i128", since="1.26.0")]
}
2 changes: 1 addition & 1 deletion src/libcore/num/i16.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@

#![stable(feature = "rust1", since = "1.0.0")]

int_module! { i16 }
int_module! { i16, -32768, 32767 }
2 changes: 1 addition & 1 deletion src/libcore/num/i32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@

#![stable(feature = "rust1", since = "1.0.0")]

int_module! { i32 }
int_module! { i32, -2147483648, 2147483647 }
2 changes: 1 addition & 1 deletion src/libcore/num/i64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@

#![stable(feature = "rust1", since = "1.0.0")]

int_module! { i64 }
int_module! { i64, -9223372036854775808, 9223372036854775807 }
2 changes: 1 addition & 1 deletion src/libcore/num/i8.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@

#![stable(feature = "rust1", since = "1.0.0")]

int_module! { i8 }
int_module! { i8, -128, 127 }
36 changes: 28 additions & 8 deletions src/libcore/num/int_macros.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,33 @@
#![doc(hidden)]

macro_rules! int_module {
($T:ident) => (int_module!($T, #[stable(feature = "rust1", since = "1.0.0")]););
($T:ident, #[$attr:meta]) => (
/// The smallest value that can be represented by this integer type.
#[$attr]
pub const MIN: $T = $T::min_value();
/// The largest value that can be represented by this integer type.
#[$attr]
pub const MAX: $T = $T::max_value();
($T:ident, $Min:expr, $Max:expr) => (
int_module!(
$T,
$Min,
$Max,
#[stable(feature = "rust1", since = "1.0.0")]
);
);
($T:ident, $Min:expr, $Max:expr, #[$attr:meta]) => (
doc_comment! {
concat!(
"The smallest value that can be represented by this integer type, which is ",
stringify!($Min),
"."
),
#[$attr]
pub const MIN: $T = $T::min_value();
}

doc_comment! {
concat!(
"The largest value that can be represented by this integer type, which is ",
stringify!($Max),
"."
),
#[$attr]
pub const MAX: $T = $T::max_value();
}
)
}
9 changes: 8 additions & 1 deletion src/libcore/num/isize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,11 @@

#![stable(feature = "rust1", since = "1.0.0")]

int_module! { isize }
#[cfg(target_pointer_width = "16")]
int_module! { isize, -32768, 32767 }

#[cfg(target_pointer_width = "32")]
int_module! { isize, -2147483648, 2147483647 }

#[cfg(target_pointer_width = "64")]
int_module! { isize, -9223372036854775808, 9223372036854775807 }
6 changes: 5 additions & 1 deletion src/libcore/num/u128.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,8 @@
//! *[See also the `u128` primitive type](../../std/primitive.u128.html).*

#![stable(feature = "i128", since = "1.26.0")]
uint_module! { u128, #[stable(feature = "i128", since="1.26.0")] }
uint_module! {
u128,
340282366920938463463374607431768211455,
#[stable(feature = "i128", since="1.26.0")]
}
2 changes: 1 addition & 1 deletion src/libcore/num/u16.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@

#![stable(feature = "rust1", since = "1.0.0")]

uint_module! { u16 }
uint_module! { u16, 65535 }
2 changes: 1 addition & 1 deletion src/libcore/num/u32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@

#![stable(feature = "rust1", since = "1.0.0")]

uint_module! { u32 }
uint_module! { u32, 4294967295 }
2 changes: 1 addition & 1 deletion src/libcore/num/u64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@

#![stable(feature = "rust1", since = "1.0.0")]

uint_module! { u64 }
uint_module! { u64, 18446744073709551615 }
2 changes: 1 addition & 1 deletion src/libcore/num/u8.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@

#![stable(feature = "rust1", since = "1.0.0")]

uint_module! { u8 }
uint_module! { u8, 255 }
30 changes: 22 additions & 8 deletions src/libcore/num/uint_macros.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,27 @@
#![doc(hidden)]

macro_rules! uint_module {
($T:ident) => (uint_module!($T, #[stable(feature = "rust1", since = "1.0.0")]););
($T:ident, #[$attr:meta]) => (
/// The smallest value that can be represented by this integer type.
#[$attr]
pub const MIN: $T = $T::min_value();
/// The largest value that can be represented by this integer type.
#[$attr]
pub const MAX: $T = $T::max_value();
($T:ident, $Max:expr) => (
uint_module!(
$T,
$Max,
#[stable(feature = "rust1", since = "1.0.0")]
);
);
($T:ident, $Max:expr, #[$attr:meta]) => (
doc_comment! {
"The smallest value that can be represented by this integer type, which is 0.",
#[$attr]
pub const MIN: $T = $T::min_value();
}
doc_comment! {
concat!(
"The largest value that can be represented by this integer type, which is ",
stringify!($Max),
"."
),
#[$attr]
pub const MAX: $T = $T::max_value();
}
)
}
10 changes: 9 additions & 1 deletion src/libcore/num/usize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,12 @@

#![stable(feature = "rust1", since = "1.0.0")]

uint_module! { usize }

#[cfg(target_pointer_width = "16")]
uint_module! { usize, 65535 }

#[cfg(target_pointer_width = "32")]
uint_module! { usize, 4294967295 }

#[cfg(target_pointer_width = "64")]
uint_module! { usize, 18446744073709551615 }