Added a lint as suggested in 6010 which recommends using contains()
instead of `find()` follows by `is_some()` on strings Update clippy_lints/src/find_is_some_on_strs.rs Co-authored-by: Takayuki Nakata <f.seasons017@gmail.com> Update clippy_lints/src/methods/mod.rs Co-authored-by: Philipp Krones <hello@philkrones.com>
This commit is contained in:
parent
c4fc076e11
commit
a1cf2d334d
4 changed files with 56 additions and 7 deletions
|
|
@ -168,8 +168,27 @@ fn search_is_some() {
|
|||
x < 0
|
||||
}
|
||||
).is_some();
|
||||
|
||||
let s1 = String::from("hello world");
|
||||
let s2 = String::from("world");
|
||||
// Check caller `find()` is a &`static str case
|
||||
let _ = "hello world".find("world").is_some();
|
||||
let _ = "hello world".find(&s2).is_some();
|
||||
let _ = "hello world".find(&s2[2..]).is_some();
|
||||
// Check caller of `find()` is a String case
|
||||
let _ = s1.find("world").is_some();
|
||||
let _ = s1.find(&s2).is_some();
|
||||
let _ = s1.find(&s2[2..]).is_some();
|
||||
// Check caller of `find()` is a slice of String case
|
||||
let _ = s1[2..].find("world").is_some();
|
||||
let _ = s1[2..].find(&s2).is_some();
|
||||
let _ = s1[2..].find(&s2[2..]).is_some();
|
||||
|
||||
// Check that we don't lint if the caller is not an `Iterator`.
|
||||
// Check that we don't lint if `find()` is called with
|
||||
// Pattern that is not a string
|
||||
let _ = s1.find(|c: char| c == 'o' || c == 'l').is_some();
|
||||
|
||||
// Check that we don't lint if the caller is not an `Iterator` or string
|
||||
let foo = IteratorFalsePositives { foo: 0 };
|
||||
let _ = foo.find().is_some();
|
||||
let _ = foo.position().is_some();
|
||||
|
|
|
|||
|
|
@ -88,5 +88,3 @@ LL | | }
|
|||
LL | | ).is_some();
|
||||
| |______________________________^
|
||||
|
||||
error: aborting due to 11 previous errors
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue