Skip to content

' \" ' works in char literals #32249

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
Robbepop opened this issue Mar 14, 2016 · 3 comments
Closed

' \" ' works in char literals #32249

Robbepop opened this issue Mar 14, 2016 · 3 comments
Labels
T-lang Relevant to the language team, which will review and decide on the PR/issue.

Comments

@Robbepop
Copy link
Contributor

To write a double-quote (") in a string literal, once needs to escape with with a backslash like so:

let s = "double-quote: \"";

This is because it is also the delimiter of a string.
However, in character literals a single-quote (') is the delimiter and still, '"' works without warnings:

assert_eq!('\"', '"'); // always true

I think this might be a bug since it is not really needed to have an escaped double-quote in character literals or was it implemented as a helpful routine?

The same is true for strings and a single-quote!

assert_eq!("\'", "'"); // always true

I am very sorry if this was explicitly wanted behaviour!

@steveklabnik
Copy link
Member

/cc @rust-lang/lang

@petrochenkov
Copy link
Contributor

Duplicate of #29470

@brson
Copy link
Contributor

brson commented Mar 15, 2016

Working as intended per #29470. Thanks for the report.

@brson brson closed this as completed Mar 15, 2016
@steveklabnik steveklabnik added the T-lang Relevant to the language team, which will review and decide on the PR/issue. label Mar 24, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-lang Relevant to the language team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants