Skip to content

single_char_pattern produces incorrect suggestion for double quote character #11973

@mondeja

Description

@mondeja

Summary

When the char to replace is a double quote ", clippy suggests to replace it using the escape character, but in this case the escape character is not needed.

Reproducer

error: single-character string constant used as pattern
  --> crates/.../src/lib.rs:79:92
   |
79 | ...                   let clean_string = lit.to_string().replace("\"", "");
   |                                                                  ^^^^ help: try using a `char` instead: `'\"'`

The message should be:

try using a `char` instead: `'"'`

Version

rustc 1.73.0-nightly (0d95f9132 2023-07-26)
binary: rustc
commit-hash: 0d95f9132909ae7c5f2456748d0ffd1c3ba4a8e8
commit-date: 2023-07-26
host: x86_64-unknown-linux-gnu
release: 1.73.0-nightly
LLVM version: 16.0.5

Additional Labels

No response

Metadata

Metadata

Assignees

Labels

C-bugCategory: Clippy is not doing the correct thing

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions