Skip to content
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

Closed
wants to merge 1 commit into from

Conversation

tamird
Copy link
Contributor

@tamird tamird commented Apr 22, 2015

No description provided.

@rust-highfive
Copy link
Contributor

r? @nrc

(rust_highfive has picked a reviewer for you, use r? to override)

@tamird
Copy link
Contributor Author

tamird commented Apr 22, 2015

r? @alexcrichton

@rust-highfive rust-highfive assigned alexcrichton and unassigned nrc Apr 22, 2015
const NEWLINE: &'static str = "\r\n";

#[cfg(not(windows))]
const NEWLINE: &'static str = "\n";
Copy link
Member

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)

Copy link
Contributor Author

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;

?

Copy link
Member

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()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

Copy link
Contributor Author

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

@alexcrichton
Copy link
Member

@bors: r+ 7dcb1bd

@tamird
Copy link
Contributor Author

tamird commented Apr 23, 2015

OK, this should work.

@alexcrichton
Copy link
Member

@bors: r+ bad285c

@bors
Copy link
Collaborator

bors commented Apr 23, 2015

⌛ Testing commit bad285c with merge a025675...

@bors
Copy link
Collaborator

bors commented Apr 23, 2015

💔 Test failed - auto-win-64-nopt-t

@klutzy
Copy link
Contributor

klutzy commented Apr 23, 2015

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.
Also, we already have backlog of various CRLF bugs: e.g. #7723, #8731, and #12471. These bugs are sometimes hard to fix (or even hard to figure out what's wrong).
Actually the test failed during run-make due to extra \r.

@azurespace
Copy link

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.

@tamird
Copy link
Contributor Author

tamird commented Apr 23, 2015

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?

@alexcrichton
Copy link
Member

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants