]> git.lizzy.rs Git - rust.git/blob - tests/ui/needless_pass_by_value.rs
Rename lint to needless_take_by_value
[rust.git] / tests / ui / needless_pass_by_value.rs
1 #![feature(plugin)]
2 #![plugin(clippy)]
3
4 #![deny(needless_pass_by_value)]
5 #![allow(dead_code)]
6
7 // `v` will 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);
11
12     consume(w);
13
14     x.push(T::default());
15
16     y
17 }
18
19 fn consume<T>(_: T) {}
20
21 struct Wrapper(String);
22
23 fn bar(x: String, y: Wrapper) {
24     assert_eq!(x.len(), 42);
25     assert_eq!(y.0.len(), 42);
26 }
27
28 fn test_borrow_trait<T: std::borrow::Borrow<str>, U>(t: T, u: U) {
29     // U implements `Borrow<U>`, but warned correctly
30     println!("{}", t.borrow());
31     consume(&u);
32 }
33
34 // ok
35 fn test_fn<F: Fn(i32) -> i32>(f: F) {
36     f(1);
37 }
38
39 fn main() {}