]>
git.proxmox.com Git - rustc.git/blob - tests/ui/lint/noop-method-call.rs
4 #![warn(noop_method_call)]
6 use std
::borrow
::Borrow
;
9 struct PlainType
<T
>(T
);
12 struct CloneType
<T
>(T
);
15 let non_clone_type_ref
= &PlainType(1u32);
16 let non_clone_type_ref_clone
: &PlainType
<u32> = non_clone_type_ref
.clone();
17 //~^ WARNING call to `.clone()` on a reference in this situation does nothing
19 let clone_type_ref
= &CloneType(1u32);
20 let clone_type_ref_clone
: CloneType
<u32> = clone_type_ref
.clone();
22 let clone_type_ref
= &&CloneType(1u32);
23 let clone_type_ref_clone
: &CloneType
<u32> = clone_type_ref
.clone();
24 //~^ WARNING using `.clone()` on a double reference, which returns `&CloneType<u32>`
26 let non_deref_type
= &PlainType(1u32);
27 let non_deref_type_deref
: &PlainType
<u32> = non_deref_type
.deref();
28 //~^ WARNING call to `.deref()` on a reference in this situation does nothing
30 let non_deref_type
= &&PlainType(1u32);
31 let non_deref_type_deref
: &PlainType
<u32> = non_deref_type
.deref();
32 //~^ WARNING using `.deref()` on a double reference, which returns `&PlainType<u32>`
34 let non_borrow_type
= &PlainType(1u32);
35 let non_borrow_type_borrow
: &PlainType
<u32> = non_borrow_type
.borrow();
36 //~^ WARNING call to `.borrow()` on a reference in this situation does nothing
38 // Borrowing a &&T does not warn since it has collapsed the double reference
39 let non_borrow_type
= &&PlainType(1u32);
40 let non_borrow_type_borrow
: &PlainType
<u32> = non_borrow_type
.borrow();
42 let xs
= ["a", "b", "c"];
43 let _v
: Vec
<&str> = xs
.iter().map(|x
| x
.clone()).collect(); // could use `*x` instead
44 //~^ WARNING using `.clone()` on a double reference, which returns `&str`
47 fn generic
<T
>(non_clone_type
: &PlainType
<T
>) {
48 non_clone_type
.clone();
49 //~^ WARNING call to `.clone()` on a reference in this situation does nothing
52 fn non_generic(non_clone_type
: &PlainType
<u32>) {
53 non_clone_type
.clone();
54 //~^ WARNING call to `.clone()` on a reference in this situation does nothing