mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-27 15:11:30 +00:00
Merge pull request #2497 from waywardmonkeys/single-char-pattern
Fix single_char_pattern for \n, \t, etc.
This commit is contained in:
commit
598acba7d5
3 changed files with 14 additions and 2 deletions
|
@ -1763,7 +1763,11 @@ fn lint_single_char_pattern<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx hi
|
|||
}) = ConstContext::new(cx.tcx, cx.param_env.and(substs), cx.tables).eval(arg)
|
||||
{
|
||||
if r.len() == 1 {
|
||||
let hint = snippet(cx, expr.span, "..").replace(&format!("\"{}\"", r), &format!("'{}'", r));
|
||||
let c = r.chars().next().unwrap();
|
||||
let snip = snippet(cx, expr.span, "..");
|
||||
let hint = snip.replace(
|
||||
&format!("\"{}\"", c.escape_default()),
|
||||
&format!("'{}'", c.escape_default()));
|
||||
span_lint_and_then(
|
||||
cx,
|
||||
SINGLE_CHAR_PATTERN,
|
||||
|
|
|
@ -35,6 +35,8 @@ fn main() {
|
|||
x.rmatch_indices("x");
|
||||
x.trim_left_matches("x");
|
||||
x.trim_right_matches("x");
|
||||
// Make sure we escape characters correctly.
|
||||
x.split("\n");
|
||||
|
||||
let h = HashSet::<String>::new();
|
||||
h.contains("X"); // should not warn
|
||||
|
|
|
@ -102,5 +102,11 @@ error: single-character string constant used as pattern
|
|||
37 | x.trim_right_matches("x");
|
||||
| ---------------------^^^- help: try using a char instead: `x.trim_right_matches('x')`
|
||||
|
||||
error: aborting due to 17 previous errors
|
||||
error: single-character string constant used as pattern
|
||||
--> $DIR/single_char_pattern.rs:39:13
|
||||
|
|
||||
39 | x.split("/n");
|
||||
| --------^^^^- help: try using a char instead: `x.split('/n')`
|
||||
|
||||
error: aborting due to 18 previous errors
|
||||
|
||||
|
|
Loading…
Reference in a new issue