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

document behavior of \r\n in string literals #676

Merged
merged 1 commit into from
Sep 12, 2019

Conversation

matklad
Copy link
Member

@matklad matklad commented Sep 12, 2019

No description provided.

@matklad
Copy link
Member Author

matklad commented Sep 12, 2019

Note that the current implementation works by converting \r\n -> \n at the file loading time, but I think the current wording is equivalent to the implementation.

src/tokens.md Outdated Show resolved Hide resolved
@Havvy Havvy merged commit 580a194 into rust-lang:master Sep 12, 2019
@Havvy
Copy link
Contributor

Havvy commented Sep 12, 2019

💟 Thanks!

@matklad matklad deleted the carriage-return branch September 12, 2019 22:03
@ehuss
Copy link
Contributor

ehuss commented Sep 12, 2019

This looks good, but I was wondering (as noted in #626) if we should instead note how CRLF translation happens in one place. As it stands, it's not clear how other things like byte literals handle it. If it is noted in one place, then it wouldn't need to be repeated anywhere else. Does that sound like a good idea?

I haven't delved too deep into it yet, but the things I'd like to see:

  • does all source text unconditionally translate CRLF to LF?
  • how exactly bare CRs are handled.
  • what is the interaction with include_str!/include_bytes!/include! (presumably that would be in the std docs).

@matklad
Copy link
Member Author

matklad commented Sep 13, 2019

@ehuss yeah, that makes sense. I'm not sure I'll manage to send a follow-up PR, so here's an unedited summary of things:

does all source text unconditionally translate CRLF to LF?

Yes, with only two possible exceptions of include_bytes and include_str.

This in general is not observable, except for literals and doc comments.

how exactly bare CRs are handled.

They are not translated, \r\r\n turns into \r\n, and the lexer treats only \n as a new line. However, we treat isolated \r in a string literal as an error. Argubly, the latter should be downgraded to a warning, but also warn about other control characters: rust-lang/rust#63682

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.

3 participants