Rollup merge of #146326 - cyrgani:int-module-1, r=jhpratt

simplify the declaration of the legacy integer modules (`std::u32` etc.)

This PR removes some duplicated code from the declaration of the legacy integer modules by expanding the macro which is already used to generate `MIN` and `MAX` to now generate the whole module.
This would also make the remaining steps listed in rust-lang/rust#68490 such as fully deprecating the modules or placing `#[doc(hidden)]` on them easier.
This commit is contained in:
Stuart Cook 2025-09-09 14:35:06 +10:00 committed by GitHub
commit fde2ef616d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
15 changed files with 81 additions and 219 deletions

View file

@ -252,47 +252,16 @@ pub use crate::macros::cfg_select;
#[macro_use]
mod internal_macros;
#[path = "num/shells/int_macros.rs"]
#[macro_use]
mod int_macros;
#[rustc_diagnostic_item = "i128_legacy_mod"]
#[path = "num/shells/i128.rs"]
pub mod i128;
#[rustc_diagnostic_item = "i16_legacy_mod"]
#[path = "num/shells/i16.rs"]
pub mod i16;
#[rustc_diagnostic_item = "i32_legacy_mod"]
#[path = "num/shells/i32.rs"]
pub mod i32;
#[rustc_diagnostic_item = "i64_legacy_mod"]
#[path = "num/shells/i64.rs"]
pub mod i64;
#[rustc_diagnostic_item = "i8_legacy_mod"]
#[path = "num/shells/i8.rs"]
pub mod i8;
#[rustc_diagnostic_item = "isize_legacy_mod"]
#[path = "num/shells/isize.rs"]
pub mod isize;
#[rustc_diagnostic_item = "u128_legacy_mod"]
#[path = "num/shells/u128.rs"]
pub mod u128;
#[rustc_diagnostic_item = "u16_legacy_mod"]
#[path = "num/shells/u16.rs"]
pub mod u16;
#[rustc_diagnostic_item = "u32_legacy_mod"]
#[path = "num/shells/u32.rs"]
pub mod u32;
#[rustc_diagnostic_item = "u64_legacy_mod"]
#[path = "num/shells/u64.rs"]
pub mod u64;
#[rustc_diagnostic_item = "u8_legacy_mod"]
#[path = "num/shells/u8.rs"]
pub mod u8;
#[rustc_diagnostic_item = "usize_legacy_mod"]
#[path = "num/shells/usize.rs"]
pub mod usize;
#[path = "num/shells/legacy_int_modules.rs"]
mod legacy_int_modules;
#[stable(feature = "rust1", since = "1.0.0")]
#[allow(clippy::useless_attribute)] // FIXME false positive (https://github.com/rust-lang/rust-clippy/issues/15636)
#[allow(deprecated_in_future)]
pub use legacy_int_modules::{i8, i16, i32, i64, isize, u8, u16, u32, u64, usize};
#[stable(feature = "i128", since = "1.26.0")]
#[allow(clippy::useless_attribute)] // FIXME false positive (https://github.com/rust-lang/rust-clippy/issues/15636)
#[allow(deprecated_in_future)]
pub use legacy_int_modules::{i128, u128};
#[path = "num/f128.rs"]
pub mod f128;

View file

@ -1,11 +0,0 @@
//! Redundant constants module for the [`i128` primitive type][i128].
//!
//! New code should use the associated constants directly on the primitive type.
#![stable(feature = "i128", since = "1.26.0")]
#![deprecated(
since = "TBD",
note = "all constants in this module replaced by associated constants on `i128`"
)]
int_module! { i128, #[stable(feature = "i128", since="1.26.0")] }

View file

@ -1,11 +0,0 @@
//! Redundant constants module for the [`i16` primitive type][i16].
//!
//! New code should use the associated constants directly on the primitive type.
#![stable(feature = "rust1", since = "1.0.0")]
#![deprecated(
since = "TBD",
note = "all constants in this module replaced by associated constants on `i16`"
)]
int_module! { i16 }

View file

@ -1,11 +0,0 @@
//! Redundant constants module for the [`i32` primitive type][i32].
//!
//! New code should use the associated constants directly on the primitive type.
#![stable(feature = "rust1", since = "1.0.0")]
#![deprecated(
since = "TBD",
note = "all constants in this module replaced by associated constants on `i32`"
)]
int_module! { i32 }

View file

@ -1,11 +0,0 @@
//! Redundant constants module for the [`i64` primitive type][i64].
//!
//! New code should use the associated constants directly on the primitive type.
#![stable(feature = "rust1", since = "1.0.0")]
#![deprecated(
since = "TBD",
note = "all constants in this module replaced by associated constants on `i64`"
)]
int_module! { i64 }

View file

@ -1,11 +0,0 @@
//! Redundant constants module for the [`i8` primitive type][i8].
//!
//! New code should use the associated constants directly on the primitive type.
#![stable(feature = "rust1", since = "1.0.0")]
#![deprecated(
since = "TBD",
note = "all constants in this module replaced by associated constants on `i8`"
)]
int_module! { i8 }

View file

@ -1,46 +0,0 @@
#![doc(hidden)]
macro_rules! int_module {
($T:ident) => (int_module!($T, #[stable(feature = "rust1", since = "1.0.0")]););
($T:ident, #[$attr:meta]) => (
#[doc = concat!(
"The smallest value that can be represented by this integer type. Use ",
"[`", stringify!($T), "::MIN", "`] instead."
)]
///
/// # Examples
///
/// ```rust
/// // deprecated way
#[doc = concat!("let min = std::", stringify!($T), "::MIN;")]
///
/// // intended way
#[doc = concat!("let min = ", stringify!($T), "::MIN;")]
/// ```
///
#[$attr]
#[deprecated(since = "TBD", note = "replaced by the `MIN` associated constant on this type")]
#[rustc_diagnostic_item = concat!(stringify!($T), "_legacy_const_min")]
pub const MIN: $T = $T::MIN;
#[doc = concat!(
"The largest value that can be represented by this integer type. Use ",
"[`", stringify!($T), "::MAX", "`] instead."
)]
///
/// # Examples
///
/// ```rust
/// // deprecated way
#[doc = concat!("let max = std::", stringify!($T), "::MAX;")]
///
/// // intended way
#[doc = concat!("let max = ", stringify!($T), "::MAX;")]
/// ```
///
#[$attr]
#[deprecated(since = "TBD", note = "replaced by the `MAX` associated constant on this type")]
#[rustc_diagnostic_item = concat!(stringify!($T), "_legacy_const_max")]
pub const MAX: $T = $T::MAX;
)
}

View file

@ -1,11 +0,0 @@
//! Redundant constants module for the [`isize` primitive type][isize].
//!
//! New code should use the associated constants directly on the primitive type.
#![stable(feature = "rust1", since = "1.0.0")]
#![deprecated(
since = "TBD",
note = "all constants in this module replaced by associated constants on `isize`"
)]
int_module! { isize }

View file

@ -0,0 +1,71 @@
#![doc(hidden)]
macro_rules! legacy_int_module {
($T:ident) => (legacy_int_module!($T, #[stable(feature = "rust1", since = "1.0.0")]););
($T:ident, #[$attr:meta]) => (
#[$attr]
#[deprecated(
since = "TBD",
note = "all constants in this module replaced by associated constants on the type"
)]
#[rustc_diagnostic_item = concat!(stringify!($T), "_legacy_mod")]
pub mod $T {
#![doc = concat!("Redundant constants module for the [`", stringify!($T), "` primitive type][", stringify!($T), "].")]
//!
//! New code should use the associated constants directly on the primitive type.
#[doc = concat!(
"The smallest value that can be represented by this integer type. Use ",
"[`", stringify!($T), "::MIN", "`] instead."
)]
///
/// # Examples
///
/// ```rust
/// // deprecated way
#[doc = concat!("let min = std::", stringify!($T), "::MIN;")]
///
/// // intended way
#[doc = concat!("let min = ", stringify!($T), "::MIN;")]
/// ```
///
#[$attr]
#[deprecated(since = "TBD", note = "replaced by the `MIN` associated constant on this type")]
#[rustc_diagnostic_item = concat!(stringify!($T), "_legacy_const_min")]
pub const MIN: $T = $T::MIN;
#[doc = concat!(
"The largest value that can be represented by this integer type. Use ",
"[`", stringify!($T), "::MAX", "`] instead."
)]
///
/// # Examples
///
/// ```rust
/// // deprecated way
#[doc = concat!("let max = std::", stringify!($T), "::MAX;")]
///
/// // intended way
#[doc = concat!("let max = ", stringify!($T), "::MAX;")]
/// ```
///
#[$attr]
#[deprecated(since = "TBD", note = "replaced by the `MAX` associated constant on this type")]
#[rustc_diagnostic_item = concat!(stringify!($T), "_legacy_const_max")]
pub const MAX: $T = $T::MAX;
}
)
}
legacy_int_module! { i128, #[stable(feature = "i128", since = "1.26.0")] }
legacy_int_module! { i16 }
legacy_int_module! { i32 }
legacy_int_module! { i64 }
legacy_int_module! { i8 }
legacy_int_module! { isize }
legacy_int_module! { u128, #[stable(feature = "i128", since = "1.26.0")] }
legacy_int_module! { u16 }
legacy_int_module! { u32 }
legacy_int_module! { u64 }
legacy_int_module! { u8 }
legacy_int_module! { usize }

View file

@ -1,11 +0,0 @@
//! Redundant constants module for the [`u128` primitive type][u128].
//!
//! New code should use the associated constants directly on the primitive type.
#![stable(feature = "i128", since = "1.26.0")]
#![deprecated(
since = "TBD",
note = "all constants in this module replaced by associated constants on `u128`"
)]
int_module! { u128, #[stable(feature = "i128", since="1.26.0")] }

View file

@ -1,11 +0,0 @@
//! Redundant constants module for the [`u16` primitive type][u16].
//!
//! New code should use the associated constants directly on the primitive type.
#![stable(feature = "rust1", since = "1.0.0")]
#![deprecated(
since = "TBD",
note = "all constants in this module replaced by associated constants on `u16`"
)]
int_module! { u16 }

View file

@ -1,11 +0,0 @@
//! Redundant constants module for the [`u32` primitive type][u32].
//!
//! New code should use the associated constants directly on the primitive type.
#![stable(feature = "rust1", since = "1.0.0")]
#![deprecated(
since = "TBD",
note = "all constants in this module replaced by associated constants on `u32`"
)]
int_module! { u32 }

View file

@ -1,11 +0,0 @@
//! Redundant constants module for the [`u64` primitive type][u64].
//!
//! New code should use the associated constants directly on the primitive type.
#![stable(feature = "rust1", since = "1.0.0")]
#![deprecated(
since = "TBD",
note = "all constants in this module replaced by associated constants on `u64`"
)]
int_module! { u64 }

View file

@ -1,11 +0,0 @@
//! Redundant constants module for the [`u8` primitive type][u8].
//!
//! New code should use the associated constants directly on the primitive type.
#![stable(feature = "rust1", since = "1.0.0")]
#![deprecated(
since = "TBD",
note = "all constants in this module replaced by associated constants on `u8`"
)]
int_module! { u8 }

View file

@ -1,11 +0,0 @@
//! Redundant constants module for the [`usize` primitive type][usize].
//!
//! New code should use the associated constants directly on the primitive type.
#![stable(feature = "rust1", since = "1.0.0")]
#![deprecated(
since = "TBD",
note = "all constants in this module replaced by associated constants on `usize`"
)]
int_module! { usize }