Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Cameron Steffen
authored and
Cameron Steffen
committed
Oct 10, 2017
1 parent
c1a147f
commit 18717ae
Showing
4 changed files
with
151 additions
and
150 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
use std::collections::HashSet; | ||
|
||
fn main() { | ||
let x = "foo"; | ||
x.split("x"); | ||
x.split("xx"); | ||
x.split('x'); | ||
|
||
let y = "x"; | ||
x.split(y); | ||
// Not yet testing for multi-byte characters | ||
// Changing `r.len() == 1` to `r.chars().count() == 1` in `lint_single_char_pattern` | ||
// should have done this but produced an ICE | ||
// | ||
// We may not want to suggest changing these anyway | ||
// See: https://github.com/rust-lang-nursery/rust-clippy/issues/650#issuecomment-184328984 | ||
x.split("ß"); | ||
x.split("ℝ"); | ||
x.split("💣"); | ||
// Can't use this lint for unicode code points which don't fit in a char | ||
x.split("❤️"); | ||
x.contains("x"); | ||
x.starts_with("x"); | ||
x.ends_with("x"); | ||
x.find("x"); | ||
x.rfind("x"); | ||
x.rsplit("x"); | ||
x.split_terminator("x"); | ||
x.rsplit_terminator("x"); | ||
x.splitn(0, "x"); | ||
x.rsplitn(0, "x"); | ||
x.matches("x"); | ||
x.rmatches("x"); | ||
x.match_indices("x"); | ||
x.rmatch_indices("x"); | ||
x.trim_left_matches("x"); | ||
x.trim_right_matches("x"); | ||
|
||
let h = HashSet::<String>::new(); | ||
h.contains("X"); // should not warn | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
error: single-character string constant used as pattern | ||
--> $DIR/single_char_pattern.rs:5:13 | ||
| | ||
5 | x.split("x"); | ||
| --------^^^- help: try using a char instead: `x.split('x')` | ||
| | ||
= note: `-D single-char-pattern` implied by `-D warnings` | ||
|
||
error: single-character string constant used as pattern | ||
--> $DIR/single_char_pattern.rs:22:16 | ||
| | ||
22 | x.contains("x"); | ||
| -----------^^^- help: try using a char instead: `x.contains('x')` | ||
|
||
error: single-character string constant used as pattern | ||
--> $DIR/single_char_pattern.rs:23:19 | ||
| | ||
23 | x.starts_with("x"); | ||
| --------------^^^- help: try using a char instead: `x.starts_with('x')` | ||
|
||
error: single-character string constant used as pattern | ||
--> $DIR/single_char_pattern.rs:24:17 | ||
| | ||
24 | x.ends_with("x"); | ||
| ------------^^^- help: try using a char instead: `x.ends_with('x')` | ||
|
||
error: single-character string constant used as pattern | ||
--> $DIR/single_char_pattern.rs:25:12 | ||
| | ||
25 | x.find("x"); | ||
| -------^^^- help: try using a char instead: `x.find('x')` | ||
|
||
error: single-character string constant used as pattern | ||
--> $DIR/single_char_pattern.rs:26:13 | ||
| | ||
26 | x.rfind("x"); | ||
| --------^^^- help: try using a char instead: `x.rfind('x')` | ||
|
||
error: single-character string constant used as pattern | ||
--> $DIR/single_char_pattern.rs:27:14 | ||
| | ||
27 | x.rsplit("x"); | ||
| ---------^^^- help: try using a char instead: `x.rsplit('x')` | ||
|
||
error: single-character string constant used as pattern | ||
--> $DIR/single_char_pattern.rs:28:24 | ||
| | ||
28 | x.split_terminator("x"); | ||
| -------------------^^^- help: try using a char instead: `x.split_terminator('x')` | ||
|
||
error: single-character string constant used as pattern | ||
--> $DIR/single_char_pattern.rs:29:25 | ||
| | ||
29 | x.rsplit_terminator("x"); | ||
| --------------------^^^- help: try using a char instead: `x.rsplit_terminator('x')` | ||
|
||
error: single-character string constant used as pattern | ||
--> $DIR/single_char_pattern.rs:30:17 | ||
| | ||
30 | x.splitn(0, "x"); | ||
| ------------^^^- help: try using a char instead: `x.splitn(0, 'x')` | ||
|
||
error: single-character string constant used as pattern | ||
--> $DIR/single_char_pattern.rs:31:18 | ||
| | ||
31 | x.rsplitn(0, "x"); | ||
| -------------^^^- help: try using a char instead: `x.rsplitn(0, 'x')` | ||
|
||
error: single-character string constant used as pattern | ||
--> $DIR/single_char_pattern.rs:32:15 | ||
| | ||
32 | x.matches("x"); | ||
| ----------^^^- help: try using a char instead: `x.matches('x')` | ||
|
||
error: single-character string constant used as pattern | ||
--> $DIR/single_char_pattern.rs:33:16 | ||
| | ||
33 | x.rmatches("x"); | ||
| -----------^^^- help: try using a char instead: `x.rmatches('x')` | ||
|
||
error: single-character string constant used as pattern | ||
--> $DIR/single_char_pattern.rs:34:21 | ||
| | ||
34 | x.match_indices("x"); | ||
| ----------------^^^- help: try using a char instead: `x.match_indices('x')` | ||
|
||
error: single-character string constant used as pattern | ||
--> $DIR/single_char_pattern.rs:35:22 | ||
| | ||
35 | x.rmatch_indices("x"); | ||
| -----------------^^^- help: try using a char instead: `x.rmatch_indices('x')` | ||
|
||
error: single-character string constant used as pattern | ||
--> $DIR/single_char_pattern.rs:36:25 | ||
| | ||
36 | x.trim_left_matches("x"); | ||
| --------------------^^^- help: try using a char instead: `x.trim_left_matches('x')` | ||
|
||
error: single-character string constant used as pattern | ||
--> $DIR/single_char_pattern.rs:37:26 | ||
| | ||
37 | x.trim_right_matches("x"); | ||
| ---------------------^^^- help: try using a char instead: `x.trim_right_matches('x')` | ||
|