Skip to content

Commit e36c7d5

Browse files
committed
test: add test cases for str
1 parent 6f6dd88 commit e36c7d5

File tree

3 files changed

+121
-13
lines changed

3 files changed

+121
-13
lines changed

tests/ui/search_is_some_fixable_none.fixed

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -224,15 +224,42 @@ mod issue_11910 {
224224
fn bar(&self, _: bool) {}
225225
}
226226

227-
fn test_then() {
227+
fn test_normal_for_iter() {
228+
let v = vec![3, 2, 1, 0, -1, -2, -3];
229+
let _ = !v.iter().any(|x| *x == 42);
230+
Foo.bar(!v.iter().any(|x| *x == 42));
231+
}
232+
233+
fn test_then_for_iter() {
228234
let v = vec![3, 2, 1, 0, -1, -2, -3];
229235
(!v.iter().any(|x| *x == 42)).then(computations);
230236
}
231237

232-
fn test_then_some() {
238+
fn test_then_some_for_iter() {
233239
let v = vec![3, 2, 1, 0, -1, -2, -3];
234240
(!v.iter().any(|x| *x == 42)).then_some(0);
241+
}
235242

236-
Foo.bar(!v.iter().any(|x| *x == 42));
243+
fn test_normal_for_str() {
244+
let s = "hello";
245+
let _ = !s.contains("world");
246+
Foo.bar(!s.contains("world"));
247+
let s = String::from("hello");
248+
let _ = !s.contains("world");
249+
Foo.bar(!s.contains("world"));
250+
}
251+
252+
fn test_then_for_str() {
253+
let s = "hello";
254+
let _ = (!s.contains("world")).then(computations);
255+
let s = String::from("hello");
256+
let _ = (!s.contains("world")).then(computations);
257+
}
258+
259+
fn test_then_some_for_str() {
260+
let s = "hello";
261+
let _ = (!s.contains("world")).then_some(0);
262+
let s = String::from("hello");
263+
let _ = (!s.contains("world")).then_some(0);
237264
}
238265
}

tests/ui/search_is_some_fixable_none.rs

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -230,15 +230,42 @@ mod issue_11910 {
230230
fn bar(&self, _: bool) {}
231231
}
232232

233-
fn test_then() {
233+
fn test_normal_for_iter() {
234+
let v = vec![3, 2, 1, 0, -1, -2, -3];
235+
let _ = v.iter().find(|x| **x == 42).is_none();
236+
Foo.bar(v.iter().find(|x| **x == 42).is_none());
237+
}
238+
239+
fn test_then_for_iter() {
234240
let v = vec![3, 2, 1, 0, -1, -2, -3];
235241
v.iter().find(|x| **x == 42).is_none().then(computations);
236242
}
237243

238-
fn test_then_some() {
244+
fn test_then_some_for_iter() {
239245
let v = vec![3, 2, 1, 0, -1, -2, -3];
240246
v.iter().find(|x| **x == 42).is_none().then_some(0);
247+
}
241248

242-
Foo.bar(v.iter().find(|x| **x == 42).is_none());
249+
fn test_normal_for_str() {
250+
let s = "hello";
251+
let _ = s.find("world").is_none();
252+
Foo.bar(s.find("world").is_none());
253+
let s = String::from("hello");
254+
let _ = s.find("world").is_none();
255+
Foo.bar(s.find("world").is_none());
256+
}
257+
258+
fn test_then_for_str() {
259+
let s = "hello";
260+
let _ = s.find("world").is_none().then(computations);
261+
let s = String::from("hello");
262+
let _ = s.find("world").is_none().then(computations);
263+
}
264+
265+
fn test_then_some_for_str() {
266+
let s = "hello";
267+
let _ = s.find("world").is_none().then_some(0);
268+
let s = String::from("hello");
269+
let _ = s.find("world").is_none().then_some(0);
243270
}
244271
}

tests/ui/search_is_some_fixable_none.stderr

Lines changed: 61 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -283,22 +283,76 @@ LL | let _ = v.iter().find(|fp| test_u32_2(*fp.field)).is_none();
283283
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!v.iter().any(|fp| test_u32_2(*fp.field))`
284284

285285
error: called `is_none()` after searching an `Iterator` with `find`
286-
--> $DIR/search_is_some_fixable_none.rs:235:9
286+
--> $DIR/search_is_some_fixable_none.rs:235:17
287+
|
288+
LL | let _ = v.iter().find(|x| **x == 42).is_none();
289+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!v.iter().any(|x| *x == 42)`
290+
291+
error: called `is_none()` after searching an `Iterator` with `find`
292+
--> $DIR/search_is_some_fixable_none.rs:236:17
293+
|
294+
LL | Foo.bar(v.iter().find(|x| **x == 42).is_none());
295+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!v.iter().any(|x| *x == 42)`
296+
297+
error: called `is_none()` after searching an `Iterator` with `find`
298+
--> $DIR/search_is_some_fixable_none.rs:241:9
287299
|
288300
LL | v.iter().find(|x| **x == 42).is_none().then(computations);
289301
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `(!v.iter().any(|x| *x == 42))`
290302

291303
error: called `is_none()` after searching an `Iterator` with `find`
292-
--> $DIR/search_is_some_fixable_none.rs:240:9
304+
--> $DIR/search_is_some_fixable_none.rs:246:9
293305
|
294306
LL | v.iter().find(|x| **x == 42).is_none().then_some(0);
295307
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `(!v.iter().any(|x| *x == 42))`
296308

297-
error: called `is_none()` after searching an `Iterator` with `find`
298-
--> $DIR/search_is_some_fixable_none.rs:242:17
309+
error: called `is_none()` after calling `find()` on a string
310+
--> $DIR/search_is_some_fixable_none.rs:251:17
299311
|
300-
LL | Foo.bar(v.iter().find(|x| **x == 42).is_none());
301-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!v.iter().any(|x| *x == 42)`
312+
LL | let _ = s.find("world").is_none();
313+
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!s.contains("world")`
314+
315+
error: called `is_none()` after calling `find()` on a string
316+
--> $DIR/search_is_some_fixable_none.rs:252:17
317+
|
318+
LL | Foo.bar(s.find("world").is_none());
319+
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!s.contains("world")`
320+
321+
error: called `is_none()` after calling `find()` on a string
322+
--> $DIR/search_is_some_fixable_none.rs:254:17
323+
|
324+
LL | let _ = s.find("world").is_none();
325+
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!s.contains("world")`
326+
327+
error: called `is_none()` after calling `find()` on a string
328+
--> $DIR/search_is_some_fixable_none.rs:255:17
329+
|
330+
LL | Foo.bar(s.find("world").is_none());
331+
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!s.contains("world")`
332+
333+
error: called `is_none()` after calling `find()` on a string
334+
--> $DIR/search_is_some_fixable_none.rs:260:17
335+
|
336+
LL | let _ = s.find("world").is_none().then(computations);
337+
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `(!s.contains("world"))`
338+
339+
error: called `is_none()` after calling `find()` on a string
340+
--> $DIR/search_is_some_fixable_none.rs:262:17
341+
|
342+
LL | let _ = s.find("world").is_none().then(computations);
343+
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `(!s.contains("world"))`
344+
345+
error: called `is_none()` after calling `find()` on a string
346+
--> $DIR/search_is_some_fixable_none.rs:267:17
347+
|
348+
LL | let _ = s.find("world").is_none().then_some(0);
349+
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `(!s.contains("world"))`
350+
351+
error: called `is_none()` after calling `find()` on a string
352+
--> $DIR/search_is_some_fixable_none.rs:269:17
353+
|
354+
LL | let _ = s.find("world").is_none().then_some(0);
355+
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `(!s.contains("world"))`
302356

303-
error: aborting due to 46 previous errors
357+
error: aborting due to 55 previous errors
304358

0 commit comments

Comments
 (0)