-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Add cfg(no_128_bit) to core: removes u128/i128 formatting #103126
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ macro_rules! int_impl { | |
$rot:expr, $rot_op:expr, $rot_result:expr, $swap_op:expr, $swapped:expr, | ||
$reversed:expr, $le_bytes:expr, $be_bytes:expr, | ||
$to_xe_bytes_doc:expr, $from_xe_bytes_doc:expr, | ||
$bound_condition:expr) => { | ||
$bound_condition:expr $(, #[$intrinsics_cfg:meta])?) => { | ||
/// The smallest value that can be represented by this integer type | ||
#[doc = concat!("(−2<sup>", $BITS_MINUS_ONE, "</sup>", $bound_condition, ")")] | ||
/// | ||
|
@@ -62,6 +62,7 @@ macro_rules! int_impl { | |
#[doc = concat!("assert_eq!(", stringify!($SelfT), "::from_str_radix(\"A\", 16), Ok(10));")] | ||
/// ``` | ||
#[stable(feature = "rust1", since = "1.0.0")] | ||
$( #[$intrinsics_cfg] )? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is doing more than just controlling the removal of formatting: this function is about parsing. If not called, the function should not be included by the linker, different to what's happening to stuff called by the fmt machinery that is always included the moment anything that uses the fmt machinery is included. |
||
pub fn from_str_radix(src: &str, radix: u32) -> Result<Self, ParseIntError> { | ||
from_str_radix(src, radix) | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,7 +23,7 @@ macro_rules! impl_nonzero_fmt { | |
} | ||
|
||
macro_rules! nonzero_integers { | ||
( $( #[$stability: meta] #[$const_new_unchecked_stability: meta] $Ty: ident($Int: ty); )+ ) => { | ||
( $( #[$stability: meta] #[$const_new_unchecked_stability: meta] $(#[$cfg: meta])? $Ty: ident($Int: ty); )+ ) => { | ||
$( | ||
/// An integer that is known not to equal zero. | ||
/// | ||
|
@@ -154,9 +154,12 @@ macro_rules! nonzero_integers { | |
} | ||
} | ||
|
||
$(#[$cfg])? | ||
impl_nonzero_fmt! { | ||
#[$stability] (Debug, Display, Binary, Octal, LowerHex, UpperHex) for $Ty | ||
#[$stability] (Display, Binary, Octal, LowerHex, UpperHex) for $Ty | ||
} | ||
|
||
impl_nonzero_fmt!(#[$stability] (Debug) for $Ty); | ||
)+ | ||
} | ||
} | ||
|
@@ -166,13 +169,15 @@ nonzero_integers! { | |
#[stable(feature = "nonzero", since = "1.28.0")] #[rustc_const_stable(feature = "nonzero", since = "1.28.0")] NonZeroU16(u16); | ||
#[stable(feature = "nonzero", since = "1.28.0")] #[rustc_const_stable(feature = "nonzero", since = "1.28.0")] NonZeroU32(u32); | ||
#[stable(feature = "nonzero", since = "1.28.0")] #[rustc_const_stable(feature = "nonzero", since = "1.28.0")] NonZeroU64(u64); | ||
#[stable(feature = "nonzero", since = "1.28.0")] #[rustc_const_stable(feature = "nonzero", since = "1.28.0")] NonZeroU128(u128); | ||
#[stable(feature = "nonzero", since = "1.28.0")] #[rustc_const_stable(feature = "nonzero", since = "1.28.0")] | ||
#[cfg(not(no_128_bit))] NonZeroU128(u128); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here, I don't think it should be cfg'd out in this PR. |
||
#[stable(feature = "nonzero", since = "1.28.0")] #[rustc_const_stable(feature = "nonzero", since = "1.28.0")] NonZeroUsize(usize); | ||
#[stable(feature = "signed_nonzero", since = "1.34.0")] #[rustc_const_stable(feature = "signed_nonzero", since = "1.34.0")] NonZeroI8(i8); | ||
#[stable(feature = "signed_nonzero", since = "1.34.0")] #[rustc_const_stable(feature = "signed_nonzero", since = "1.34.0")] NonZeroI16(i16); | ||
#[stable(feature = "signed_nonzero", since = "1.34.0")] #[rustc_const_stable(feature = "signed_nonzero", since = "1.34.0")] NonZeroI32(i32); | ||
#[stable(feature = "signed_nonzero", since = "1.34.0")] #[rustc_const_stable(feature = "signed_nonzero", since = "1.34.0")] NonZeroI64(i64); | ||
#[stable(feature = "signed_nonzero", since = "1.34.0")] #[rustc_const_stable(feature = "signed_nonzero", since = "1.34.0")] NonZeroI128(i128); | ||
#[stable(feature = "signed_nonzero", since = "1.34.0")] #[rustc_const_stable(feature = "signed_nonzero", since = "1.34.0")] | ||
#[cfg(not(no_128_bit))] NonZeroI128(i128); | ||
#[stable(feature = "signed_nonzero", since = "1.34.0")] #[rustc_const_stable(feature = "signed_nonzero", since = "1.34.0")] NonZeroIsize(isize); | ||
} | ||
|
||
|
@@ -191,8 +196,11 @@ macro_rules! from_str_radix_nzint_impl { | |
)*} | ||
} | ||
|
||
from_str_radix_nzint_impl! { NonZeroU8 NonZeroU16 NonZeroU32 NonZeroU64 NonZeroU128 NonZeroUsize | ||
NonZeroI8 NonZeroI16 NonZeroI32 NonZeroI64 NonZeroI128 NonZeroIsize } | ||
from_str_radix_nzint_impl! { NonZeroU8 NonZeroU16 NonZeroU32 NonZeroU64 NonZeroUsize | ||
NonZeroI8 NonZeroI16 NonZeroI32 NonZeroI64 NonZeroIsize } | ||
|
||
#[cfg(not(no_128_bit))] | ||
from_str_radix_nzint_impl! { NonZeroU128 NonZeroI128 } | ||
|
||
macro_rules! nonzero_leading_trailing_zeros { | ||
( $( $Ty: ident($Uint: ty) , $LeadingTestExpr:expr ;)+ ) => { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
include ../tools.mk | ||
|
||
all: | ||
$(RUSTC) --edition=2021 --crate-type=rlib --crate-name=core ../../../library/core/src/lib.rs --cfg no_128_bit | ||
$(RUSTC) --edition=2021 --crate-type=staticlib --crate-name=demo --sysroot=. -C panic=abort lib.rs | ||
# Expect that objdump succeeds and grep fails. The grep pattern is for names like __multi3. | ||
# There is no pipefail on dash so echo a string that will fail the test if objump fails. | ||
(objdump -t $(TMPDIR)/libdemo.a || echo __objdumpfailedti) | (! grep -w '__[a-z]\+ti[0-9]\?') |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#![feature(no_core)] | ||
|
||
#![no_std] | ||
#![no_core] // supress compiler-builtins | ||
extern crate core; | ||
use core::prelude::rust_2021::*; | ||
use core::fmt::Write; | ||
|
||
// An empty file might be sufficient here, but since formatting is one of the | ||
// features affected by no_128_bit it seems worth including some. | ||
|
||
struct X(pub usize); | ||
impl core::fmt::Write for X { | ||
fn write_str(&mut self, s: &str) -> core::fmt::Result { | ||
self.0 += s.len(); | ||
Ok(()) | ||
} | ||
} | ||
|
||
#[no_mangle] | ||
extern "C" fn demo() -> usize { | ||
let mut x = X(0); | ||
// Writes "i128 u128 foo" due to the removal of u/i128 formatting. | ||
core::write!(x, "{:?} {:?} {}", i128::MAX, u128::MIN, "foo").unwrap(); | ||
x.0 | ||
} | ||
|
||
#[panic_handler] | ||
fn panic(_: &core::panic::PanicInfo) -> ! { | ||
loop {} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is an i128/u128 impl necessary in the first place?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good question; I haven’t tried removing it. I think it’s conventional to provide
Debug
for everything public in the standard library; not sure if that could be waived in this case?