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

single_char_pattern doesn't recognize scape sequences #3075

Open
gnzlbg opened this issue Aug 23, 2018 · 1 comment
Open

single_char_pattern doesn't recognize scape sequences #3075

gnzlbg opened this issue Aug 23, 2018 · 1 comment
Labels
L-suggestion Lint: Improving, adding or fixing lint suggestions

Comments

@gnzlbg
Copy link
Contributor

gnzlbg commented Aug 23, 2018

Example (playground):

string.find("\"");

errors with

  |
3 |     string.find("\"");
  |                ^^^^ help: try using a char instead: `'\"'`
  |
  = note: #[warn(single_char_pattern)] on by default
  = help: for further information visit https://rust-lang-nursery.github.io/rust-clippy/v0.0.212/index.html#single_char_pattern

However, the appropriate char to use is '"' without the escape: \.

@flip1995 flip1995 added the L-suggestion Lint: Improving, adding or fixing lint suggestions label Aug 23, 2018
@ghost
Copy link

ghost commented Aug 28, 2018

The question is whether Clippy should use '"' over '\"' in suggestions.

It looks like the stdlib prefers the redundant escape form:

fn main() {
    println!("{:?}", '"');
    println!("{}", '"'.escape_debug());
    println!("{}", '"'.escape_default());
}

produces

'\"'
\"
\"

If '"' is better, we should also have a style lint for recommending '\"' to '"'.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
L-suggestion Lint: Improving, adding or fixing lint suggestions
Projects
None yet
Development

No branches or pull requests

2 participants