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

Escape backslash in single_char_pattern.rs #8067

Merged

Conversation

frobiac
Copy link
Contributor

@frobiac frobiac commented Dec 2, 2021

Escape backslash in single_char_pattern.

Previously, the proposed clippy fix for a single backslash in raw strings r"\" or r#"\"# was also only an unescaped, single '\':

warning: single-character string constant used as pattern
2 |     let s = r#"abc\xyz/"#.find(r"\");
  |                                ^^^^ help: try using a `char` instead: `'\'`
  |
  = note: `#[warn(clippy::single_char_pattern)]` on by default

This PR corrects this to a properly escaped double backslash '\\'.
I haven't come up with any other problematic cases, a single quote was already handled.

Closes: #8060

changelog: Escape backslash in [`single_char_pattern`]

@rust-highfive
Copy link

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @giraffate (or someone else) soon.

Please see the contribution instructions for more information.

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Dec 2, 2021
@frobiac frobiac changed the title Escape backslash for singe_char_pattern.rs Escape backslash in single_char_pattern.rs Dec 2, 2021
@giraffate
Copy link
Contributor

@bors r+

It looks good, thanks!

@bors
Copy link
Contributor

bors commented Dec 3, 2021

📌 Commit 5cc451b has been approved by giraffate

@bors
Copy link
Contributor

bors commented Dec 3, 2021

⌛ Testing commit 5cc451b with merge fddef24...

@bors
Copy link
Contributor

bors commented Dec 3, 2021

☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test
Approved by: giraffate
Pushing fddef24 to master...

@bors bors merged commit fddef24 into rust-lang:master Dec 3, 2021
@frobiac frobiac deleted the 8060-backslash_escaped_in_single_char_pattern branch December 3, 2021 11:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties
Projects
None yet
Development

Successfully merging this pull request may close these issues.

clippy --fix fails to escape backslash when replacing r"\" into '\\' E0762
4 participants