-
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
Pretty-printing uses CRLF on Windows. Closes #14808. #24696
Conversation
r? @nrc (rust_highfive has picked a reviewer for you, use r? to override) |
const NEWLINE: &'static str = "\r\n"; | ||
|
||
#[cfg(not(windows))] | ||
const NEWLINE: &'static str = "\n"; |
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.
Could you use cfg!
here instead of #[cfg]
as well? (helps weed out compile errors on all platforms at once)
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.
Do you mean:
diff --git a/src/libsyntax/print/pp.rs b/src/libsyntax/print/pp.rs
index 15aaf9c..c0d68ef 100644
--- a/src/libsyntax/print/pp.rs
+++ b/src/libsyntax/print/pp.rs
@@ -507,8 +507,13 @@ impl<'a> Printer<'a> {
}
}
pub fn print_newline(&mut self, amount: isize) -> io::Result<()> {
+ let newline = if cfg!(windows) {
+ "\r\n"
+ } else {
+ "\n"
+ };
debug!("NEWLINE {}", amount);
- let ret = write!(self.out, "\n");
+ let ret = self.out.write_all(newline.as_bytes());
self.pending_indentation = 0;
self.indent(amount);
return ret;
?
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.
Yeah that'd do the trick! You could also use b"\n"
to avoid the call to .as_bytes()
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.
Done!
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.
Gah, that doesn't typecheck. Sec
OK, this should work. |
💔 Test failed - auto-win-64-nopt-t |
I'm against this change. If the output depends on OS, it leads to subtle bugs which can't be fixed by non-Windows users. |
I also think this change must not be merged without enough concern. If this feature is needed for some situation, it should not be solved such a way. It would be more suitable solution to add an environmental variable EVERY platform as a flag to enable/disable. |
I'm fine with this not going in - I was just looking to close #14808. Perhaps that issue should be closed in favour of an RFC? |
Sure, sounds like there's not consensus on this issue. I don't think this necessarily needs an RFC, but it would probably be best to reach consensus on the issue first before pursuing this. Thanks regardless though @tamird! |
No description provided.