Skip to content

String/character escape rules do not match the reference #29470

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

Closed
keleshev opened this issue Oct 30, 2015 · 7 comments
Closed

String/character escape rules do not match the reference #29470

keleshev opened this issue Oct 30, 2015 · 7 comments

Comments

@keleshev
Copy link

The reference does not allow \' escape inside strings, and neither \" inside character literals. This makes sense, as the backslash is redundant in these cases. However, the compiler accepts both: http://is.gd/CDBzp1

@petrochenkov
Copy link
Contributor

The reference is incomplete, the full list is

\xFF (exactly 2 hex digits)
\u{FFFF} (from 1 to 6 (inclusively) hex digits)
\n
\r
\t
\0
\"
\'
\\

@keleshev
Copy link
Author

keleshev commented Nov 6, 2015

@petrochenkov the reference includes all of your examples, except:

  1. no \0
  2. \' is restricted to character literals
  3. \" is restricted to string literals

screen shot 2015-11-06 at 14 23 40

@keleshev
Copy link
Author

keleshev commented Nov 6, 2015

And I think this restriction is made on purpose. It does not make sense to have \' inside string literal, because ' (single quote) works fine.

@steveklabnik
Copy link
Member

cc @rust-lang/lang is the compiler too accepting here, or is this a docs bug?

@nrc
Copy link
Member

nrc commented Nov 11, 2015

/me shrugs
seems either position is reasonable. I don't think it's worth a breaking change to 'fix' the compiler unless there is an example of this being dangerous. I guess it might be bad if the user expects \' to be \' not ' and so doesn't escape the \

@nikomatsakis
Copy link
Contributor

I agree with @nrc. I think it'd actually be more confusing to have the same sequence (e.g., \") mean different things in character vs string literals. Or at least I'd find it confusing.

@steveklabnik
Copy link
Member

Okay! Moving to docs bug then.

steveklabnik added a commit to steveklabnik/rust that referenced this issue Nov 17, 2015
steveklabnik added a commit to steveklabnik/rust that referenced this issue Nov 17, 2015

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
steveklabnik added a commit to steveklabnik/rust that referenced this issue Nov 17, 2015
dlrobertson pushed a commit to dlrobertson/rust that referenced this issue Nov 29, 2018
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

No branches or pull requests

5 participants