]> git.lizzy.rs Git - rust.git/blob - tests/ui/methods.rs
rustup and compile-fail -> ui test move
[rust.git] / tests / ui / methods.rs
1 #![feature(plugin)]
2 #![feature(const_fn)]
3 #![plugin(clippy)]
4
5 #![deny(clippy, clippy_pedantic)]
6 #![allow(blacklisted_name, unused, print_stdout, non_ascii_literal, new_without_default, new_without_default_derive, missing_docs_in_private_items)]
7
8 use std::collections::BTreeMap;
9 use std::collections::HashMap;
10 use std::collections::HashSet;
11 use std::collections::VecDeque;
12 use std::ops::Mul;
13 use std::iter::FromIterator;
14
15 struct T;
16
17 impl T {
18     fn add(self, other: T) -> T { self } //~ERROR defining a method called `add`
19     fn drop(&mut self) { } //~ERROR defining a method called `drop`
20
21     fn sub(&self, other: T) -> &T { self } // no error, self is a ref
22     fn div(self) -> T { self } // no error, different #arguments
23     fn rem(self, other: T) { } // no error, wrong return type
24
25     fn into_u32(self) -> u32 { 0 } // fine
26     fn into_u16(&self) -> u16 { 0 } //~ERROR methods called `into_*` usually take self by value
27
28     fn to_something(self) -> u32 { 0 } //~ERROR methods called `to_*` usually take self by reference
29
30     fn new(self) {}
31     //~^ ERROR methods called `new` usually take no self
32     //~| ERROR methods called `new` usually return `Self`
33 }
34
35 struct Lt<'a> {
36     foo: &'a u32,
37 }
38
39 impl<'a> Lt<'a> {
40     // The lifetime is different, but that’s irrelevant, see #734
41     #[allow(needless_lifetimes)]
42     pub fn new<'b>(s: &'b str) -> Lt<'b> { unimplemented!() }
43 }
44
45 struct Lt2<'a> {
46     foo: &'a u32,
47 }
48
49 impl<'a> Lt2<'a> {
50     // The lifetime is different, but that’s irrelevant, see #734
51     pub fn new(s: &str) -> Lt2 { unimplemented!() }
52 }
53
54 struct Lt3<'a> {
55     foo: &'a u32,
56 }
57
58 impl<'a> Lt3<'a> {
59     // The lifetime is different, but that’s irrelevant, see #734
60     pub fn new() -> Lt3<'static> { unimplemented!() }
61 }
62
63 #[derive(Clone,Copy)]
64 struct U;
65
66 impl U {
67     fn new() -> Self { U }
68     fn to_something(self) -> u32 { 0 } // ok because U is Copy
69 }
70
71 struct V<T> {
72     _dummy: T
73 }
74
75 impl<T> V<T> {
76     fn new() -> Option<V<T>> { None }
77 }
78
79 impl Mul<T> for T {
80     type Output = T;
81     fn mul(self, other: T) -> T { self } // no error, obviously
82 }
83
84 /// Utility macro to test linting behavior in `option_methods()`
85 /// The lints included in `option_methods()` should not lint if the call to map is partially
86 /// within a macro
87 macro_rules! opt_map {
88     ($opt:expr, $map:expr) => {($opt).map($map)};
89 }
90
91 /// Checks implementation of the following lints:
92 /// * `OPTION_MAP_UNWRAP_OR`
93 /// * `OPTION_MAP_UNWRAP_OR_ELSE`
94 fn option_methods() {
95     let opt = Some(1);
96
97     // Check OPTION_MAP_UNWRAP_OR
98     // single line case
99     let _ = opt.map(|x| x + 1) //~  ERROR called `map(f).unwrap_or(a)`
100                                //~| NOTE replace `map(|x| x + 1).unwrap_or(0)`
101                .unwrap_or(0); // should lint even though this call is on a separate line
102     // multi line cases
103     let _ = opt.map(|x| { //~ ERROR called `map(f).unwrap_or(a)`
104                         x + 1
105                     }
106               ).unwrap_or(0);
107     let _ = opt.map(|x| x + 1) //~ ERROR called `map(f).unwrap_or(a)`
108                .unwrap_or({
109                     0
110                 });
111     // macro case
112     let _ = opt_map!(opt, |x| x + 1).unwrap_or(0); // should not lint
113
114     // Check OPTION_MAP_UNWRAP_OR_ELSE
115     // single line case
116     let _ = opt.map(|x| x + 1) //~  ERROR called `map(f).unwrap_or_else(g)`
117                                //~| NOTE replace `map(|x| x + 1).unwrap_or_else(|| 0)`
118                .unwrap_or_else(|| 0); // should lint even though this call is on a separate line
119     // multi line cases
120     let _ = opt.map(|x| { //~ ERROR called `map(f).unwrap_or_else(g)`
121                         x + 1
122                     }
123               ).unwrap_or_else(|| 0);
124     let _ = opt.map(|x| x + 1) //~ ERROR called `map(f).unwrap_or_else(g)`
125                .unwrap_or_else(||
126                     0
127                 );
128     // macro case
129     let _ = opt_map!(opt, |x| x + 1).unwrap_or_else(|| 0); // should not lint
130 }
131
132 /// Struct to generate false positives for things with .iter()
133 #[derive(Copy, Clone)]
134 struct HasIter;
135
136 impl HasIter {
137     fn iter(self) -> IteratorFalsePositives {
138         IteratorFalsePositives { foo: 0 }
139     }
140
141     fn iter_mut(self) -> IteratorFalsePositives {
142         IteratorFalsePositives { foo: 0 }
143     }
144 }
145
146 /// Struct to generate false positive for Iterator-based lints
147 #[derive(Copy, Clone)]
148 struct IteratorFalsePositives {
149     foo: u32,
150 }
151
152 impl IteratorFalsePositives {
153     fn filter(self) -> IteratorFalsePositives {
154         self
155     }
156
157     fn next(self) -> IteratorFalsePositives {
158         self
159     }
160
161     fn find(self) -> Option<u32> {
162         Some(self.foo)
163     }
164
165     fn position(self) -> Option<u32> {
166         Some(self.foo)
167     }
168
169     fn rposition(self) -> Option<u32> {
170         Some(self.foo)
171     }
172
173     fn nth(self, n: usize) -> Option<u32> {
174         Some(self.foo)
175     }
176
177     fn skip(self, _: usize) -> IteratorFalsePositives {
178         self
179     }
180 }
181
182 #[derive(Copy, Clone)]
183 struct HasChars;
184
185 impl HasChars {
186     fn chars(self) -> std::str::Chars<'static> {
187         "HasChars".chars()
188     }
189 }
190
191 /// Checks implementation of `FILTER_NEXT` lint
192 fn filter_next() {
193     let v = vec![3, 2, 1, 0, -1, -2, -3];
194
195     // check single-line case
196     let _ = v.iter().filter(|&x| *x < 0).next();
197     //~^ ERROR called `filter(p).next()` on an `Iterator`.
198     //~| NOTE replace `filter(|&x| *x < 0).next()`
199
200     // check multi-line case
201     let _ = v.iter().filter(|&x| { //~ERROR called `filter(p).next()` on an `Iterator`.
202                                 *x < 0
203                             }
204                    ).next();
205
206     // check that we don't lint if the caller is not an Iterator
207     let foo = IteratorFalsePositives { foo: 0 };
208     let _ = foo.filter().next();
209 }
210
211 /// Checks implementation of `SEARCH_IS_SOME` lint
212 fn search_is_some() {
213     let v = vec![3, 2, 1, 0, -1, -2, -3];
214
215     // check `find().is_some()`, single-line
216     let _ = v.iter().find(|&x| *x < 0).is_some();
217     //~^ ERROR called `is_some()` after searching
218     //~| NOTE replace `find(|&x| *x < 0).is_some()`
219
220     // check `find().is_some()`, multi-line
221     let _ = v.iter().find(|&x| { //~ERROR called `is_some()` after searching
222                               *x < 0
223                           }
224                    ).is_some();
225
226     // check `position().is_some()`, single-line
227     let _ = v.iter().position(|&x| x < 0).is_some();
228     //~^ ERROR called `is_some()` after searching
229     //~| NOTE replace `position(|&x| x < 0).is_some()`
230
231     // check `position().is_some()`, multi-line
232     let _ = v.iter().position(|&x| { //~ERROR called `is_some()` after searching
233                                   x < 0
234                               }
235                    ).is_some();
236
237     // check `rposition().is_some()`, single-line
238     let _ = v.iter().rposition(|&x| x < 0).is_some();
239     //~^ ERROR called `is_some()` after searching
240     //~| NOTE replace `rposition(|&x| x < 0).is_some()`
241
242     // check `rposition().is_some()`, multi-line
243     let _ = v.iter().rposition(|&x| { //~ERROR called `is_some()` after searching
244                                    x < 0
245                                }
246                    ).is_some();
247
248     // check that we don't lint if the caller is not an Iterator
249     let foo = IteratorFalsePositives { foo: 0 };
250     let _ = foo.find().is_some();
251     let _ = foo.position().is_some();
252     let _ = foo.rposition().is_some();
253 }
254
255 /// Checks implementation of the `OR_FUN_CALL` lint
256 fn or_fun_call() {
257     struct Foo;
258
259     impl Foo {
260         fn new() -> Foo { Foo }
261     }
262
263     enum Enum {
264         A(i32),
265     }
266
267     const fn make_const(i: i32) -> i32 { i }
268
269     fn make<T>() -> T { unimplemented!(); }
270
271     let with_enum = Some(Enum::A(1));
272     with_enum.unwrap_or(Enum::A(5));
273
274     let with_const_fn = Some(1);
275     with_const_fn.unwrap_or(make_const(5));
276
277     let with_constructor = Some(vec![1]);
278     with_constructor.unwrap_or(make());
279     //~^ERROR use of `unwrap_or`
280     //~|HELP try this
281     //~|SUGGESTION with_constructor.unwrap_or_else(make)
282
283     let with_new = Some(vec![1]);
284     with_new.unwrap_or(Vec::new());
285     //~^ERROR use of `unwrap_or`
286     //~|HELP try this
287     //~|SUGGESTION with_new.unwrap_or_default();
288
289     let with_const_args = Some(vec![1]);
290     with_const_args.unwrap_or(Vec::with_capacity(12));
291     //~^ERROR use of `unwrap_or`
292     //~|HELP try this
293     //~|SUGGESTION with_const_args.unwrap_or_else(|| Vec::with_capacity(12));
294
295     let with_err : Result<_, ()> = Ok(vec![1]);
296     with_err.unwrap_or(make());
297     //~^ERROR use of `unwrap_or`
298     //~|HELP try this
299     //~|SUGGESTION with_err.unwrap_or_else(|_| make());
300
301     let with_err_args : Result<_, ()> = Ok(vec![1]);
302     with_err_args.unwrap_or(Vec::with_capacity(12));
303     //~^ERROR use of `unwrap_or`
304     //~|HELP try this
305     //~|SUGGESTION with_err_args.unwrap_or_else(|_| Vec::with_capacity(12));
306
307     let with_default_trait = Some(1);
308     with_default_trait.unwrap_or(Default::default());
309     //~^ERROR use of `unwrap_or`
310     //~|HELP try this
311     //~|SUGGESTION with_default_trait.unwrap_or_default();
312
313     let with_default_type = Some(1);
314     with_default_type.unwrap_or(u64::default());
315     //~^ERROR use of `unwrap_or`
316     //~|HELP try this
317     //~|SUGGESTION with_default_type.unwrap_or_default();
318
319     let with_vec = Some(vec![1]);
320     with_vec.unwrap_or(vec![]);
321     //~^ERROR use of `unwrap_or`
322     //~|HELP try this
323     // FIXME #944: ~|SUGGESTION with_vec.unwrap_or_else(|| vec![]);
324
325     let without_default = Some(Foo);
326     without_default.unwrap_or(Foo::new());
327     //~^ERROR use of `unwrap_or`
328     //~|HELP try this
329     //~|SUGGESTION without_default.unwrap_or_else(Foo::new);
330
331     let mut map = HashMap::<u64, String>::new();
332     map.entry(42).or_insert(String::new());
333     //~^ERROR use of `or_insert` followed by a function call
334     //~|HELP try this
335     //~|SUGGESTION map.entry(42).or_insert_with(String::new);
336
337     let mut btree = BTreeMap::<u64, String>::new();
338     btree.entry(42).or_insert(String::new());
339     //~^ERROR use of `or_insert` followed by a function call
340     //~|HELP try this
341     //~|SUGGESTION btree.entry(42).or_insert_with(String::new);
342
343     let stringy = Some(String::from(""));
344     let _ = stringy.unwrap_or("".to_owned());
345     //~^ERROR use of `unwrap_or`
346     //~|HELP try this
347     //~|SUGGESTION stringy.unwrap_or_else(|| "".to_owned());
348 }
349
350 /// Checks implementation of `ITER_NTH` lint
351 fn iter_nth() {
352     let mut some_vec = vec![0, 1, 2, 3];
353     let mut boxed_slice: Box<[u8]> = Box::new([0, 1, 2, 3]);
354     let mut some_vec_deque: VecDeque<_> = some_vec.iter().cloned().collect();
355
356     {
357         // Make sure we lint `.iter()` for relevant types
358         let bad_vec = some_vec.iter().nth(3);
359         //~^ERROR called `.iter().nth()` on a Vec. Calling `.get()` is both faster and more readable
360         let bad_slice = &some_vec[..].iter().nth(3);
361         //~^ERROR called `.iter().nth()` on a slice. Calling `.get()` is both faster and more readable
362         let bad_boxed_slice = boxed_slice.iter().nth(3);
363         //~^ERROR called `.iter().nth()` on a slice. Calling `.get()` is both faster and more readable
364         let bad_vec_deque = some_vec_deque.iter().nth(3);
365         //~^ERROR called `.iter().nth()` on a VecDeque. Calling `.get()` is both faster and more readable
366     }
367
368     {
369         // Make sure we lint `.iter_mut()` for relevant types
370         let bad_vec = some_vec.iter_mut().nth(3);
371         //~^ERROR called `.iter_mut().nth()` on a Vec. Calling `.get_mut()` is both faster and more readable
372     }
373     {
374         let bad_slice = &some_vec[..].iter_mut().nth(3);
375         //~^ERROR called `.iter_mut().nth()` on a slice. Calling `.get_mut()` is both faster and more readable
376     }
377     {
378         let bad_vec_deque = some_vec_deque.iter_mut().nth(3);
379         //~^ERROR called `.iter_mut().nth()` on a VecDeque. Calling `.get_mut()` is both faster and more readable
380     }
381
382     // Make sure we don't lint for non-relevant types
383     let false_positive = HasIter;
384     let ok = false_positive.iter().nth(3);
385     let ok_mut = false_positive.iter_mut().nth(3);
386 }
387
388 /// Checks implementation of `ITER_SKIP_NEXT` lint
389 fn iter_skip_next() {
390     let mut some_vec = vec![0, 1, 2, 3];
391
392     let _ = some_vec.iter().skip(42).next();
393     //~^ERROR called `skip(x).next()` on an iterator. This is more succinctly expressed by calling `nth(x)`
394
395     let _ = some_vec.iter().cycle().skip(42).next();
396     //~^ERROR called `skip(x).next()` on an iterator. This is more succinctly expressed by calling `nth(x)`
397
398     let _ = (1..10).skip(10).next();
399     //~^ERROR called `skip(x).next()` on an iterator. This is more succinctly expressed by calling `nth(x)`
400
401     let _ = &some_vec[..].iter().skip(3).next();
402     //~^ERROR called `skip(x).next()` on an iterator. This is more succinctly expressed by calling `nth(x)`
403
404     let foo = IteratorFalsePositives { foo : 0 };
405     let _ = foo.skip(42).next();
406     let _ = foo.filter().skip(42).next();
407 }
408
409 struct GetFalsePositive {
410     arr: [u32; 3],
411 }
412
413 impl GetFalsePositive {
414     fn get(&self, pos: usize) -> Option<&u32> { self.arr.get(pos) }
415     fn get_mut(&mut self, pos: usize) -> Option<&mut u32> { self.arr.get_mut(pos) }
416 }
417
418 /// Checks implementation of `GET_UNWRAP` lint
419 fn get_unwrap() {
420     let mut boxed_slice: Box<[u8]> = Box::new([0, 1, 2, 3]);
421     let mut some_slice = &mut [0, 1, 2, 3];
422     let mut some_vec = vec![0, 1, 2, 3];
423     let mut some_vecdeque: VecDeque<_> = some_vec.iter().cloned().collect();
424     let mut some_hashmap: HashMap<u8, char> = HashMap::from_iter(vec![(1, 'a'), (2, 'b')]);
425     let mut some_btreemap: BTreeMap<u8, char> = BTreeMap::from_iter(vec![(1, 'a'), (2, 'b')]);
426     let mut false_positive = GetFalsePositive { arr: [0, 1, 2] };
427
428     { // Test `get().unwrap()`
429         let _ = boxed_slice.get(1).unwrap();
430         //~^ERROR called `.get().unwrap()` on a slice. Using `[]` is more clear and more concise
431         //~|HELP try this
432         //~|SUGGESTION boxed_slice[1]
433         let _ = some_slice.get(0).unwrap();
434         //~^ERROR called `.get().unwrap()` on a slice. Using `[]` is more clear and more concise
435         //~|HELP try this
436         //~|SUGGESTION some_slice[0]
437         let _ = some_vec.get(0).unwrap();
438         //~^ERROR called `.get().unwrap()` on a Vec. Using `[]` is more clear and more concise
439         //~|HELP try this
440         //~|SUGGESTION some_vec[0]
441         let _ = some_vecdeque.get(0).unwrap();
442         //~^ERROR called `.get().unwrap()` on a VecDeque. Using `[]` is more clear and more concise
443         //~|HELP try this
444         //~|SUGGESTION some_vecdeque[0]
445         let _ = some_hashmap.get(&1).unwrap();
446         //~^ERROR called `.get().unwrap()` on a HashMap. Using `[]` is more clear and more concise
447         //~|HELP try this
448         //~|SUGGESTION some_hashmap[&1]
449         let _ = some_btreemap.get(&1).unwrap();
450         //~^ERROR called `.get().unwrap()` on a BTreeMap. Using `[]` is more clear and more concise
451         //~|HELP try this
452         //~|SUGGESTION some_btreemap[&1]
453
454         let _ = false_positive.get(0).unwrap();
455     }
456
457     { // Test `get_mut().unwrap()`
458         *boxed_slice.get_mut(0).unwrap() = 1;
459         //~^ERROR called `.get_mut().unwrap()` on a slice. Using `[]` is more clear and more concise
460         //~|HELP try this
461         //~|SUGGESTION &mut boxed_slice[0]
462         *some_slice.get_mut(0).unwrap() = 1;
463         //~^ERROR called `.get_mut().unwrap()` on a slice. Using `[]` is more clear and more concise
464         //~|HELP try this
465         //~|SUGGESTION &mut some_slice[0]
466         *some_vec.get_mut(0).unwrap() = 1;
467         //~^ERROR called `.get_mut().unwrap()` on a Vec. Using `[]` is more clear and more concise
468         //~|HELP try this
469         //~|SUGGESTION &mut some_vec[0]
470         *some_vecdeque.get_mut(0).unwrap() = 1;
471         //~^ERROR called `.get_mut().unwrap()` on a VecDeque. Using `[]` is more clear and more concise
472         //~|HELP try this
473         //~|SUGGESTION &mut some_vecdeque[0]
474
475         // Check false positives
476         *some_hashmap.get_mut(&1).unwrap() = 'b';
477         *some_btreemap.get_mut(&1).unwrap() = 'b';
478         *false_positive.get_mut(0).unwrap() = 1;
479     }
480 }
481
482
483 #[allow(similar_names)]
484 fn main() {
485     use std::io;
486
487     let opt = Some(0);
488     let _ = opt.unwrap();  //~ERROR used unwrap() on an Option
489
490     let res: Result<i32, ()> = Ok(0);
491     let _ = res.unwrap();  //~ERROR used unwrap() on a Result
492
493     res.ok().expect("disaster!"); //~ERROR called `ok().expect()`
494     // the following should not warn, since `expect` isn't implemented unless
495     // the error type implements `Debug`
496     let res2: Result<i32, MyError> = Ok(0);
497     res2.ok().expect("oh noes!");
498     let res3: Result<u32, MyErrorWithParam<u8>>= Ok(0);
499     res3.ok().expect("whoof"); //~ERROR called `ok().expect()`
500     let res4: Result<u32, io::Error> = Ok(0);
501     res4.ok().expect("argh"); //~ERROR called `ok().expect()`
502     let res5: io::Result<u32> = Ok(0);
503     res5.ok().expect("oops"); //~ERROR called `ok().expect()`
504     let res6: Result<u32, &str> = Ok(0);
505     res6.ok().expect("meh"); //~ERROR called `ok().expect()`
506 }
507
508 struct MyError(()); // doesn't implement Debug
509
510 #[derive(Debug)]
511 struct MyErrorWithParam<T> {
512     x: T
513 }
514
515 #[allow(unnecessary_operation)]
516 fn starts_with() {
517     "".chars().next() == Some(' ');
518     //~^ ERROR starts_with
519     //~| HELP like this
520     //~| SUGGESTION "".starts_with(' ')
521
522     Some(' ') != "".chars().next();
523     //~^ ERROR starts_with
524     //~| HELP like this
525     //~| SUGGESTION !"".starts_with(' ')
526 }
527
528 fn str_extend_chars() {
529     let abc = "abc";
530     let def = String::from("def");
531     let mut s = String::new();
532
533     s.push_str(abc);
534     s.extend(abc.chars());
535     //~^ERROR calling `.extend(_.chars())`
536     //~|HELP try this
537     //~|SUGGESTION s.push_str(abc)
538
539     s.push_str("abc");
540     s.extend("abc".chars());
541     //~^ERROR calling `.extend(_.chars())`
542     //~|HELP try this
543     //~|SUGGESTION s.push_str("abc")
544
545     s.push_str(&def);
546     s.extend(def.chars());
547     //~^ERROR calling `.extend(_.chars())`
548     //~|HELP try this
549     //~|SUGGESTION s.push_str(&def)
550
551     s.extend(abc.chars().skip(1));
552     s.extend("abc".chars().skip(1));
553     s.extend(['a', 'b', 'c'].iter());
554
555     let f = HasChars;
556     s.extend(f.chars());
557 }
558
559 fn clone_on_copy() {
560     42.clone(); //~ERROR using `clone` on a `Copy` type
561                 //~| HELP try removing the `clone` call
562                 //~| SUGGESTION 42
563     vec![1].clone(); // ok, not a Copy type
564     Some(vec![1]).clone(); // ok, not a Copy type
565     (&42).clone(); //~ERROR using `clone` on a `Copy` type
566                    //~| HELP try dereferencing it
567                    //~| SUGGESTION *(&42)
568 }
569
570 fn clone_on_copy_generic<T: Copy>(t: T) {
571     t.clone(); //~ERROR using `clone` on a `Copy` type
572                //~| HELP try removing the `clone` call
573                //~| SUGGESTION t
574     Some(t).clone(); //~ERROR using `clone` on a `Copy` type
575                      //~| HELP try removing the `clone` call
576                      //~| SUGGESTION Some(t)
577 }
578
579 fn clone_on_double_ref() {
580     let x = vec![1];
581     let y = &&x;
582     let z: &Vec<_> = y.clone(); //~ERROR using `clone` on a double
583                                 //~| HELP try dereferencing it
584                                 //~| SUGGESTION let z: &Vec<_> = (*y).clone();
585     println!("{:p} {:p}",*y, z);
586 }
587
588 fn single_char_pattern() {
589     let x = "foo";
590     x.split("x");
591     //~^ ERROR single-character string constant used as pattern
592     //~| HELP try using a char instead:
593     //~| SUGGESTION x.split('x');
594
595     x.split("xx");
596
597     x.split('x');
598
599     let y = "x";
600     x.split(y);
601
602     // Not yet testing for multi-byte characters
603     // Changing `r.len() == 1` to `r.chars().count() == 1` in `lint_single_char_pattern`
604     // should have done this but produced an ICE
605     //
606     // We may not want to suggest changing these anyway
607     // See: https://github.com/Manishearth/rust-clippy/issues/650#issuecomment-184328984
608     x.split("ß");
609     x.split("ℝ");
610     x.split("💣");
611     // Can't use this lint for unicode code points which don't fit in a char
612     x.split("❤️");
613
614     x.contains("x");
615     //~^ ERROR single-character string constant used as pattern
616     //~| HELP try using a char instead:
617     //~| SUGGESTION x.contains('x');
618     x.starts_with("x");
619     //~^ ERROR single-character string constant used as pattern
620     //~| HELP try using a char instead:
621     //~| SUGGESTION x.starts_with('x');
622     x.ends_with("x");
623     //~^ ERROR single-character string constant used as pattern
624     //~| HELP try using a char instead:
625     //~| SUGGESTION x.ends_with('x');
626     x.find("x");
627     //~^ ERROR single-character string constant used as pattern
628     //~| HELP try using a char instead:
629     //~| SUGGESTION x.find('x');
630     x.rfind("x");
631     //~^ ERROR single-character string constant used as pattern
632     //~| HELP try using a char instead:
633     //~| SUGGESTION x.rfind('x');
634     x.rsplit("x");
635     //~^ ERROR single-character string constant used as pattern
636     //~| HELP try using a char instead:
637     //~| SUGGESTION x.rsplit('x');
638     x.split_terminator("x");
639     //~^ ERROR single-character string constant used as pattern
640     //~| HELP try using a char instead:
641     //~| SUGGESTION x.split_terminator('x');
642     x.rsplit_terminator("x");
643     //~^ ERROR single-character string constant used as pattern
644     //~| HELP try using a char instead:
645     //~| SUGGESTION x.rsplit_terminator('x');
646     x.splitn(0, "x");
647     //~^ ERROR single-character string constant used as pattern
648     //~| HELP try using a char instead:
649     //~| SUGGESTION x.splitn(0, 'x');
650     x.rsplitn(0, "x");
651     //~^ ERROR single-character string constant used as pattern
652     //~| HELP try using a char instead:
653     //~| SUGGESTION x.rsplitn(0, 'x');
654     x.matches("x");
655     //~^ ERROR single-character string constant used as pattern
656     //~| HELP try using a char instead:
657     //~| SUGGESTION x.matches('x');
658     x.rmatches("x");
659     //~^ ERROR single-character string constant used as pattern
660     //~| HELP try using a char instead:
661     //~| SUGGESTION x.rmatches('x');
662     x.match_indices("x");
663     //~^ ERROR single-character string constant used as pattern
664     //~| HELP try using a char instead:
665     //~| SUGGESTION x.match_indices('x');
666     x.rmatch_indices("x");
667     //~^ ERROR single-character string constant used as pattern
668     //~| HELP try using a char instead:
669     //~| SUGGESTION x.rmatch_indices('x');
670     x.trim_left_matches("x");
671     //~^ ERROR single-character string constant used as pattern
672     //~| HELP try using a char instead:
673     //~| SUGGESTION x.trim_left_matches('x');
674     x.trim_right_matches("x");
675     //~^ ERROR single-character string constant used as pattern
676     //~| HELP try using a char instead:
677     //~| SUGGESTION x.trim_right_matches('x');
678
679     let h = HashSet::<String>::new();
680     h.contains("X"); // should not warn
681 }
682
683 #[allow(result_unwrap_used)]
684 fn temporary_cstring() {
685     use std::ffi::CString;
686
687     CString::new("foo").unwrap().as_ptr();
688     //~^ ERROR you are getting the inner pointer of a temporary `CString`
689     //~| NOTE that pointer will be invalid outside this expression
690     //~| HELP assign the `CString` to a variable to extend its lifetime
691 }