]> git.lizzy.rs Git - rust.git/blob - tests/ui/ptr_arg.rs
Merge pull request #2640 from mikerite/fix_compilation_20180406
[rust.git] / tests / ui / ptr_arg.rs
1 #![allow(unused, many_single_char_names)]
2 #![warn(ptr_arg)]
3
4 use std::borrow::Cow;
5
6 fn do_vec(x: &Vec<i64>) {
7     //Nothing here
8 }
9
10 fn do_vec_mut(x: &mut Vec<i64>) { // no error here
11     //Nothing here
12 }
13
14 fn do_str(x: &String) {
15     //Nothing here either
16 }
17
18 fn do_str_mut(x: &mut String) { // no error here
19     //Nothing here either
20 }
21
22 fn main() {
23 }
24
25 trait Foo {
26     type Item;
27     fn do_vec(x: &Vec<i64>);
28     fn do_item(x: &Self::Item);
29 }
30
31 struct Bar;
32
33 // no error, in trait impl (#425)
34 impl Foo for Bar {
35     type Item = Vec<u8>;
36     fn do_vec(x: &Vec<i64>) {}
37     fn do_item(x: &Vec<u8>) {}
38 }
39
40 fn cloned(x: &Vec<u8>) -> Vec<u8> {
41     let e = x.clone();
42     let f = e.clone(); // OK
43     let g = x;
44     let h = g.clone(); // Alas, we cannot reliably detect this without following data.
45     let i = (e).clone();
46     x.clone()
47 }
48
49 fn str_cloned(x: &String) -> String {
50     let a = x.clone();
51     let b = x.clone();
52     let c = b.clone();
53     let d = a.clone()
54              .clone()
55              .clone();
56     x.clone()
57 }
58
59 fn false_positive_capacity(x: &Vec<u8>, y: &String) {
60     let a = x.capacity();
61     let b = y.clone();
62     let c = y.as_str();
63 }
64
65 fn false_positive_capacity_too(x: &String) -> String {
66     if x.capacity() > 1024 { panic!("Too large!"); }
67     x.clone()
68 }
69
70 #[allow(dead_code)]
71 fn test_cow_with_ref(c: &Cow<[i32]>) {
72 }
73
74 #[allow(dead_code)]
75 fn test_cow(c: Cow<[i32]>) {
76     let _c = c;
77 }