-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
rustfmt the libcore/num #29113
rustfmt the libcore/num #29113
Conversation
mkpankov
commented
Oct 16, 2015
r? @aturon (rust_highfive has picked a reviewer for you, use r? to override) |
r? @nrc |
https://github.com/nrc/rustfmt/issues/476 and https://github.com/nrc/rustfmt/issues/477 are filed in the process |
@@ -425,26 +488,40 @@ pub fn to_shortest_str<'a, T, F>(mut format_shortest: F, v: T, | |||
match full_decoded { | |||
FullDecoded::Nan => { | |||
parts[0] = Part::Copy(b"NaN"); | |||
Formatted { sign: sign, parts: &parts[..1] } |
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.
nrc/rustfmt#418
This and many other struct literals in the diff look better on a single line IMHO.
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.
This is a separate issue. By default, structs that have bodies longer than 20 chars are formatted on multiple lines. This can be changed in the configuration file.
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.
Right, separate issue, but what do you think about increasing that threshold (or otherwise altering the heuristic)?
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.
I am not opposed to the idea. You could open an issue for it.
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.
Ok, should I revert some of such changes then?
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.
This alone shouldn't block the PR in my opinion. When and if this rustfmt default changes, a lot of code formatted earlier will have to be re-rustfmt'd anyway.
When I tentatively ran rustfmt over some of these files, it also changed the formatting of the auto-generated |
@rkruppe I just discarded those changes from the commit. Thought there's no sane heuristics to not touch such files. |
tidy also says this:
I didn't touch these files, and the diff with master shows nothing. Should I be concerned with these messages? |
@mkpankov don't worry about the SNAP lines, they have been around for a while, they're not due to your changes. |
Better to use git rebase on your local branch rather than merging. |
@@ -430,7 +481,7 @@ pub fn format_shortest_opt(d: &Decoded, | |||
/// The shortest mode implementation for Grisu with Dragon fallback. | |||
/// | |||
/// This should be used for most cases. | |||
pub fn format_shortest(d: &Decoded, buf: &mut [u8]) -> (/*#digits*/ usize, /*exp*/ i16) { | |||
pub fn format_shortest(d: &Decoded, buf: &mut [u8]) -> (usize, i16) { |
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.
Lost comments here, they should be moved outside the decl, I guess (although a very recent change to rustfmt might have fixed this).
re num/dec2flt/table.rs, you should be able to add |
Probably worth re-formatting with the latest version of rustfmt, it should fix a few minor issues. r+ with the issues I commented on addressed. |
@nrc Amended with results of latest rustfmt; there were much more changes than we probably expected, because of comments reformatting. I'm still resolving issues you commented on, please hold on commenting :) Also, as for rebase: I will take that into account in future. Now I decided to continue to use merge as rebase would screw up the previously made merge. |
Changes I explicitly discarded are below. Maybe some of them are worth filing a bug. diff --git a/src/libcore/num/bignum.rs b/src/libcore/num/bignum.rs
index dac7193..ca3419b 100644
--- a/src/libcore/num/bignum.rs
+++ b/src/libcore/num/bignum.rs
@@ -104,11 +104,7 @@ impl_full_ops! {
/// Table of powers of 5 representable in digits. Specifically, the largest {u8, u16, u32} value
/// that's a power of five, plus the corresponding exponent. Used in `mul_pow5`.
-const SMALL_POW5: [(u64, usize); 3] = [
- (125, 3),
- (15625, 6),
- (1_220_703_125, 13),
-];
+const SMALL_POW5: [(u64, usize); 3] = [(125, 3), (15625, 6), (1_220_703_125, 13)];
macro_rules! define_bignum {
($name:ident: type=$ty:ty, n=$n:expr) => (
diff --git a/src/libcore/num/diy_float.rs b/src/libcore/num/diy_float.rs
index 4a8332b..01fbcdc 100644
--- a/src/libcore/num/diy_float.rs
+++ b/src/libcore/num/diy_float.rs
@@ -40,7 +40,7 @@ impl Fp {
let bc = b * c;
let ad = a * d;
let bd = b * d;
- let tmp = (bd >> 32) + (ad & MASK) + (bc & MASK) + (1 << 31) /* round */;
+ let tmp = (bd >> 32) + (ad & MASK) + (bc & MASK) + (1 << 31);
let f = ac + (ad >> 32) + (bc >> 32) + (tmp >> 32);
let e = self.e + other.e + 64;
Fp { f: f, e: e }
diff --git a/src/libcore/num/flt2dec/strategy/grisu.rs b/src/libcore/num/flt2dec/strategy/grisu.rs
index e026f3c..dcc3980 100644
--- a/src/libcore/num/flt2dec/strategy/grisu.rs
+++ b/src/libcore/num/flt2dec/strategy/grisu.rs
@@ -144,14 +144,14 @@ pub fn max_pow10_no_more_than(x: u32) -> (u8, u32) {
debug_assert!(x > 0);
const X9: u32 = 10_0000_0000;
- const X8: u32 = 1_0000_0000;
- const X7: u32 = 1000_0000;
- const X6: u32 = 100_0000;
- const X5: u32 = 10_0000;
- const X4: u32 = 1_0000;
- const X3: u32 = 1000;
- const X2: u32 = 100;
- const X1: u32 = 10;
+ const X8: u32 = 1_0000_0000;
+ const X7: u32 = 1000_0000;
+ const X6: u32 = 100_0000;
+ const X5: u32 = 10_0000;
+ const X4: u32 = 1_0000;
+ const X3: u32 = 1000;
+ const X2: u32 = 100;
+ const X1: u32 = 10;
if x < X4 {
if x < X2 { |
Now all the issues should have been addressed. If I forgot something, please ping me! 😉 |
@mkpankov The comments look pretty bad, I'd be reluctant to land like this. We'll fixup rustfmt to do better here asap. |
Oh... How do I deal with this?
|
You'll need to add
To the crate root. |
What should I do with comments being wrapped in a strange way? I couldn't find an issue about that in rustfmt. |
Okay, seems I should just drop whatever changes there are and re-run |
Ah, moreover, seems I should wait on https://github.com/nrc/rustfmt/issues/503 as it's the reason comments break in the first place. |
That may not be fixed very soon. In the mean time, you could repair the offending comments by hand. Once comments obey the character limits, rustfmt generally won't touch them. -----Original Message----- Ah, moreover, seems I should wait on nrc/rustfmt#503 as it's the reason comments break in the first place. |
Comments issue: https://github.com/nrc/rustfmt/issues/535 |
@mkpankov you could either fixup the comments or wait until we have an option to not touch comments, which shouldn't be too long in coming (as opposed to a proper fix, which might take a while). |
☔ The latest upstream changes (presumably #29316) made this pull request unmergeable. Please resolve the merge conflicts. |
Is this PR still active? |
Closing due to inactivity, but feel free to resubmit with a rebase! |