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

lint_single_char_pattern shows extra quotation mark and number sign with raw string literal #4356

Closed
IgaguriMK opened this issue Aug 8, 2019 · 1 comment · Fixed by #4361
Labels
C-bug Category: Clippy is not doing the correct thing I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied

Comments

@IgaguriMK
Copy link

Problem

With the following code,

fn main() {
    for s in "try using a char instead".split(r"a") {
        println!("{}", s);
    }

    for s in "try using a char instead".split(r#"a"#) {
        println!("{}", s);
    }
}

clippy shows invalid char literals: '"a' and '#"a"' .

warning: single-character string constant used as pattern
 --> src\main.rs:2:47
  |
2 |     for s in "try using a char instead".split(r"a") {
  |                                               ^^^^ help: try using a char instead: `'"a'`
  |
  = note: #[warn(clippy::single_char_pattern)] on by default
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#single_char_pattern

warning: single-character string constant used as pattern
 --> src\main.rs:6:47
  |
6 |     for s in "try using a char instead".split(r#"a"#) {
  |                                               ^^^^^^ help: try using a char instead: `'#"a"'`
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#single_char_pattern

Clippy version

clippy 0.0.212 (082cfa79 2019-06-07)
@phansch phansch added C-bug Category: Clippy is not doing the correct thing I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied labels Aug 8, 2019
@phansch
Copy link
Member

phansch commented Aug 8, 2019

Thanks for the report! On first glance, it looks like the lint suggestion currently doesn't handle raw strings at all:

let c = &snip[1..snip.len() - 1];
let hint = format!("'{}'", if c == "'" { "\\'" } else { c });

bors added a commit that referenced this issue Aug 9, 2019
…=phansch

Fix lint_single_char_pattern on raw string literal

Closes #4356
changelog: Handle raw string literal on `single_char_literal` lint.
@bors bors closed this as completed in #4361 Aug 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants