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

Disallow newlines in strings #7053

Closed
brson opened this issue Jun 11, 2013 · 8 comments
Closed

Disallow newlines in strings #7053

brson opened this issue Jun 11, 2013 · 8 comments
Labels
A-grammar Area: The grammar of Rust

Comments

@brson
Copy link
Contributor

brson commented Jun 11, 2013

From LWN:

The modern trend seems to be to disallow literal newlines inside quoted strings, so that missing quote characters can be quickly detected by the compiler or interpreter. Go follows this trend and, like D, uses the back quote (rather than the Python triple-quote) to surround "raw" strings in which escapes are not recognized and newlines are permitted. Rust bucks the trend by allowing literal newlines in strings and does not provide for uninterpreted strings at all.

Is detecting missing quote characters important? We may already want raw strings so perhaps there's there's no need to 'buck the trend' here.

@bstrie
Copy link
Contributor

bstrie commented Jun 11, 2013

I agree that we need raw strings, but that's no reason to disallow newlines in normal strings.

Firstly, it's such an unlikely error that crippling strings just to prevent it is silly.

Secondly, any editor with syntax highlighting (read: 99.9999996% of all editors) will immediately make this error apparent. Rob Pike may abhor syntax highlighting, but we have no such aversion.

Thirdly, we already give a good error here:

fn main() {
    let c = "foo;
    let d = "bar";
}
nl.rs:3:13: 3:16 error: unterminated double quote string: ";
}
nl.rs:3     let d = "bar";
                     ^~~

@bstrie
Copy link
Contributor

bstrie commented Jun 11, 2013

Also note that restricting newlines to raw strings would mean that we wouldn't be able to use \ to gobble up whitespace, as we do currently. Rust's support for newlines in strings is awesome, don't mess it up! :)

@msullivan
Copy link
Contributor

I tend to agree with @bstrie here.

@SiegeLord
Copy link
Contributor

The LWN article is wrong about D, as it does allow literal newlines inside all of the string literals it supports.

@jesseray
Copy link

When I use strings, ~90% of the time I want normal (i.e., non-raw) strings that support newlines. I do not want to rewrite huge swathes of code to use raw strings in order to have the compiler respect my decision to hit the Enter key. That would drive me batty.

@emberian
Copy link
Member

We have raw strings. We have newlines. I don't think anything needs to change.

@emberian
Copy link
Member

(Nominating)

@pnkfelix
Copy link
Member

notabug! closing!

flip1995 pushed a commit to flip1995/rust that referenced this issue Apr 22, 2021
…, r=camsteffen,flip1995

Fixing FPs for the `branches_sharing_code` lint

Fixes rust-lang#7053
Fixes rust-lang#7054
And an additional CSS adjustment to support dark mode for every inline code. It currently only works in paragraphs, which was an oversight on my part 😅. [Current Example](https://rust-lang.github.io/rust-clippy/master/index.html#blacklisted_name)

This also includes ~50 lines of doc comments and is therefor not as big as the changes would indicate. 🐧

---

changelog: none

All of these bugs were introduced in this dev version and are therefor not worth a change log entry.

r? `@phansch`
cc: `@camsteffen` since you have a pretty good overview of the `SpanlessEq` implementation 🙃
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-grammar Area: The grammar of Rust
Projects
None yet
Development

No branches or pull requests

7 participants