-
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
Reset Formatter flags on exit from pad_integral #67784
Conversation
This fixes a bug where after calling pad_integral with appropriate flags, the fill and alignment flags would be set to '0' and 'Right' and left as such even after exiting pad_integral, which meant that future calls on the same Formatter would get incorrect flags reported. This is quite difficult to observe in practice, as almost all formatting implementations in practice don't call `Display::fmt` directly, but rather use `write!` or a similar macro, which means that they cannot observe the effects of the wrong flags (as `write!` creates a fresh Formatter instance). However, we include a test case.
r? @cramertj (rust_highfive has picked a reviewer for you, use r? to override) |
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.
Note that this is technically a breaking change, but I think it's a reasonable one (unlikely that someone is genuinely hoping for this). We can run crater, but I personally lean towards not doing so.
post_padding.write(self.buf) | ||
post_padding.write(self.buf)?; | ||
self.fill = old_fill; | ||
self.align = old_align; |
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.
It's not obvious just where we should be resetting the flags, but this seems like a "not wrong" place at least.
} | ||
} | ||
|
||
assert_eq!(format!("{:<03}", Bar), "1 0051 "); |
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.
Diff from before this PR:
-1 005001
+1 0051
Let's r? @Amanieu tentatively here as this is likely to need some libs team attention with regards to the breakage here |
I'm going to defer this to someone more familiar with the formatting code. r? @dtolnay |
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.
Thanks! This looks good to me. I don't think we need to treat this as a breaking change.
@bors r+ |
📌 Commit 73996df has been approved by |
…al, r=dtolnay Reset Formatter flags on exit from pad_integral This fixes a bug where after calling pad_integral with appropriate flags, the fill and alignment flags would be set to '0' and 'Right' and left as such even after exiting pad_integral, which meant that future calls on the same Formatter would get incorrect flags reported. This is quite difficult to observe in practice, as almost all formatting implementations in practice don't call `Display::fmt` directly, but rather use `write!` or a similar macro, which means that they cannot observe the effects of the wrong flags (as `write!` creates a fresh Formatter instance). However, we include a test case. A manual check leads me to believe this is the only case where we failed to reset the flags appropriately, but I could have missed something.
…al, r=dtolnay Reset Formatter flags on exit from pad_integral This fixes a bug where after calling pad_integral with appropriate flags, the fill and alignment flags would be set to '0' and 'Right' and left as such even after exiting pad_integral, which meant that future calls on the same Formatter would get incorrect flags reported. This is quite difficult to observe in practice, as almost all formatting implementations in practice don't call `Display::fmt` directly, but rather use `write!` or a similar macro, which means that they cannot observe the effects of the wrong flags (as `write!` creates a fresh Formatter instance). However, we include a test case. A manual check leads me to believe this is the only case where we failed to reset the flags appropriately, but I could have missed something.
…al, r=dtolnay Reset Formatter flags on exit from pad_integral This fixes a bug where after calling pad_integral with appropriate flags, the fill and alignment flags would be set to '0' and 'Right' and left as such even after exiting pad_integral, which meant that future calls on the same Formatter would get incorrect flags reported. This is quite difficult to observe in practice, as almost all formatting implementations in practice don't call `Display::fmt` directly, but rather use `write!` or a similar macro, which means that they cannot observe the effects of the wrong flags (as `write!` creates a fresh Formatter instance). However, we include a test case. A manual check leads me to believe this is the only case where we failed to reset the flags appropriately, but I could have missed something.
Rollup of 12 pull requests Successful merges: - #67784 (Reset Formatter flags on exit from pad_integral) - #67914 (Don't run const propagation on items with inconsistent bounds) - #68141 (use winapi for non-stdlib Windows bindings) - #68211 (Add failing example for E0170 explanation) - #68219 (Untangle ZST validation from integer validation and generalize it to all zsts) - #68222 (Update the wasi-libc bundled with libstd) - #68226 (Avoid calling tcx.hir().get() on CRATE_HIR_ID) - #68227 (Update to a version of cmake with windows arm64 support) - #68229 (Update iovec to a version with no winapi dependency) - #68230 (Update libssh2-sys to a version that can build for aarch64-pc-windows…) - #68231 (Better support for cross compilation on Windows.) - #68233 (Update compiler_builtins with changes to fix 128 bit integer remainder for aarch64 windows.) Failed merges: r? @ghost
This fixes a bug where after calling pad_integral with appropriate flags, the
fill and alignment flags would be set to '0' and 'Right' and left as such even
after exiting pad_integral, which meant that future calls on the same Formatter
would get incorrect flags reported.
This is quite difficult to observe in practice, as almost all formatting
implementations in practice don't call
Display::fmt
directly, but rather usewrite!
or a similar macro, which means that they cannot observe the effects ofthe wrong flags (as
write!
creates a fresh Formatter instance). However, weinclude a test case.
A manual check leads me to believe this is the only case where we failed to reset the flags appropriately, but I could have missed something.