Skip to content

Clarify how Rust treats backslashes at end of line in string literals #30727

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

Merged
merged 1 commit into from
Jan 7, 2016

Conversation

tbu-
Copy link
Contributor

@tbu- tbu- commented Jan 5, 2016

Rust differs in that behavior from C: In C, the newline escapes are resolved
before anything else, and in Rust this depends on whether the backslash is
escaped itself.

A difference can be observed in the following two programs:

#include <stdio.h>
int main()
{
    printf("\\
n\n");
    return 0;
}
fn main() {
    println!("\\
n");
}

The first program prints two newlines, the second one prints a backslash, a
newline, the latin character n and a final newline.

@rust-highfive
Copy link
Contributor

r? @steveklabnik

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

Rust differs in that behavior from C: In C, the newline escapes are resolved
before anything else, and in Rust this depends on whether the backslash is
escaped itself.

A difference can be observed in the following two programs:

```c
#include <stdio.h>
int main()
{
	printf("\\
n\n");
	return 0;
}
```

```rust
fn main() {
	println!("\\
n");
}
```

The first program prints two newlines, the second one prints a backslash, a
newline, the latin character n and a final newline.
@tbu- tbu- force-pushed the pr_doc_escaped_newline branch from 824dae9 to ce6baa7 Compare January 5, 2016 23:04
@steveklabnik
Copy link
Member

@bors: r+ rollup

thanks!

@bors
Copy link
Collaborator

bors commented Jan 5, 2016

📌 Commit ce6baa7 has been approved by steveklabnik

steveklabnik added a commit to steveklabnik/rust that referenced this pull request Jan 6, 2016
…eklabnik

Rust differs in that behavior from C: In C, the newline escapes are resolved
before anything else, and in Rust this depends on whether the backslash is
escaped itself.

A difference can be observed in the following two programs:

```c
int main()
{
	printf("\\
n\n");
	return 0;
}
```

```rust
fn main() {
	println!("\\
n");
}
```

The first program prints two newlines, the second one prints a backslash, a
newline, the latin character n and a final newline.
bors added a commit that referenced this pull request Jan 6, 2016
@bors bors merged commit ce6baa7 into rust-lang:master Jan 7, 2016
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.

4 participants