-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Marked Debug implementations for primitive types as #[inline] #47840
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
Changes from 1 commit
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 |
---|---|---|
|
@@ -1558,10 +1558,12 @@ macro_rules! fmt_refs { | |
$( | ||
#[stable(feature = "rust1", since = "1.0.0")] | ||
impl<'a, T: ?Sized + $tr> $tr for &'a T { | ||
#[inline] | ||
fn fmt(&self, f: &mut Formatter) -> Result { $tr::fmt(&**self, f) } | ||
} | ||
#[stable(feature = "rust1", since = "1.0.0")] | ||
impl<'a, T: ?Sized + $tr> $tr for &'a mut T { | ||
#[inline] | ||
fn fmt(&self, f: &mut Formatter) -> Result { $tr::fmt(&**self, f) } | ||
} | ||
)* | ||
|
@@ -1586,6 +1588,7 @@ impl Display for ! { | |
|
||
#[stable(feature = "rust1", since = "1.0.0")] | ||
impl Debug for bool { | ||
#[inline] | ||
fn fmt(&self, f: &mut Formatter) -> Result { | ||
Display::fmt(self, f) | ||
} | ||
|
@@ -1600,6 +1603,7 @@ impl Display for bool { | |
|
||
#[stable(feature = "rust1", since = "1.0.0")] | ||
impl Debug for str { | ||
#[inline] | ||
fn fmt(&self, f: &mut Formatter) -> Result { | ||
f.write_char('"')?; | ||
let mut from = 0; | ||
|
@@ -1628,6 +1632,7 @@ impl Display for str { | |
|
||
#[stable(feature = "rust1", since = "1.0.0")] | ||
impl Debug for char { | ||
#[inline] | ||
fn fmt(&self, f: &mut Formatter) -> Result { | ||
f.write_char('\'')?; | ||
for c in self.escape_debug() { | ||
|
@@ -1701,10 +1706,12 @@ impl<'a, T: ?Sized> Pointer for &'a mut T { | |
|
||
#[stable(feature = "rust1", since = "1.0.0")] | ||
impl<T: ?Sized> Debug for *const T { | ||
#[inline] | ||
fn fmt(&self, f: &mut Formatter) -> Result { Pointer::fmt(self, f) } | ||
} | ||
#[stable(feature = "rust1", since = "1.0.0")] | ||
impl<T: ?Sized> Debug for *mut T { | ||
#[inline] | ||
fn fmt(&self, f: &mut Formatter) -> Result { Pointer::fmt(self, f) } | ||
} | ||
|
||
|
@@ -1718,6 +1725,7 @@ macro_rules! tuple { | |
#[stable(feature = "rust1", since = "1.0.0")] | ||
impl<$($name:Debug),*> Debug for ($($name,)*) where last_type!($($name,)+): ?Sized { | ||
#[allow(non_snake_case, unused_assignments, deprecated)] | ||
#[inline] | ||
fn fmt(&self, f: &mut Formatter) -> Result { | ||
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 an example of one we don't need to mark inline. We want to mark those that are not generic and forwarding directly to another non-generic function as inline. 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. Thanks! With those conditions, should the only ones that I mark inline be non-float numbers, the unit type and bools? Just making sure. 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. Yes, I agree. I'm not 100% sure which trade off is the best for the function pointers, ideas welcome. 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. I'd even skip the unit type if pad is a method that inlines. We don't want to inline a bigger function with this PR. 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. The unit type's pad method doesn't inline, so I think I'll inline the unit type's fmt function. For function pointers, I think I'll avoid marking them as inline them for now. |
||
let mut builder = f.debug_tuple(""); | ||
let ($(ref $name,)*) = *self; | ||
|
@@ -1741,13 +1749,15 @@ tuple! { T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, } | |
|
||
#[stable(feature = "rust1", since = "1.0.0")] | ||
impl<T: Debug> Debug for [T] { | ||
#[inline] | ||
fn fmt(&self, f: &mut Formatter) -> Result { | ||
f.debug_list().entries(self.iter()).finish() | ||
} | ||
} | ||
|
||
#[stable(feature = "rust1", since = "1.0.0")] | ||
impl Debug for () { | ||
#[inline] | ||
fn fmt(&self, f: &mut Formatter) -> Result { | ||
f.pad("()") | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -157,6 +157,7 @@ macro_rules! debug { | |
($T:ident) => { | ||
#[stable(feature = "rust1", since = "1.0.0")] | ||
impl fmt::Debug for $T { | ||
#[inline] | ||
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 one, definitely |
||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
fmt::Display::fmt(self, f) | ||
} | ||
|
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.
For example, this one should not be inline.