4 #![warn(needless_pass_by_value)]
5 #![allow(dead_code, single_match, if_let_redundant_pattern_matching, many_single_char_names)]
7 // `v` should be warned
8 // `w`, `x` and `y` are allowed (moved or mutated)
9 fn foo<T: Default>(v: Vec<T>, w: Vec<T>, mut x: Vec<T>, y: Vec<T>) -> Vec<T> {
10 assert_eq!(v.len(), 42);
19 fn consume<T>(_: T) {}
21 struct Wrapper(String);
23 fn bar(x: String, y: Wrapper) {
24 assert_eq!(x.len(), 42);
25 assert_eq!(y.0.len(), 42);
28 // U implements `Borrow<U>`, but should be warned correctly
29 fn test_borrow_trait<T: std::borrow::Borrow<str>, U>(t: T, u: U) {
30 println!("{}", t.borrow());
35 fn test_fn<F: Fn(i32) -> i32>(f: F) {
39 // x should be warned, but y is ok
40 fn test_match(x: Option<Option<String>>, y: Option<Option<String>>) {
42 Some(Some(_)) => 1, // not moved
47 Some(Some(s)) => consume(s), // moved
52 // x and y should be warned, but z is ok
53 fn test_destructure(x: Wrapper, y: Wrapper, z: Wrapper) {
54 let Wrapper(s) = z; // moved
55 let Wrapper(ref t) = y; // not moved
56 let Wrapper(_) = y; // still not moved
58 assert_eq!(x.0.len(), s.len());