]> git.proxmox.com Git - rustc.git/blame - src/test/ui/lint/noop-method-call.rs
Merge tag 'debian/1.52.1+dfsg1-1_exp2' into proxmox/buster
[rustc.git] / src / test / ui / lint / noop-method-call.rs
CommitLineData
6a06907d
XL
1// check-pass
2
3#![allow(unused)]
4#![warn(noop_method_call)]
5
6use std::borrow::Borrow;
7use std::ops::Deref;
8
9struct PlainType<T>(T);
10
11#[derive(Clone)]
12struct CloneType<T>(T);
13
14fn main() {
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
18
19 let clone_type_ref = &CloneType(1u32);
20 let clone_type_ref_clone: CloneType<u32> = clone_type_ref.clone();
21
22 // Calling clone on a double reference doesn't warn since the method call itself
23 // peels the outer reference off
24 let clone_type_ref = &&CloneType(1u32);
25 let clone_type_ref_clone: &CloneType<u32> = clone_type_ref.clone();
26
27 let non_deref_type = &PlainType(1u32);
28 let non_deref_type_deref: &PlainType<u32> = non_deref_type.deref();
29 //~^ WARNING call to `.deref()` on a reference in this situation does nothing
30
31 // Dereferencing a &&T does not warn since it has collapsed the double reference
32 let non_deref_type = &&PlainType(1u32);
33 let non_deref_type_deref: &PlainType<u32> = non_deref_type.deref();
34
35 let non_borrow_type = &PlainType(1u32);
36 let non_borrow_type_borrow: &PlainType<u32> = non_borrow_type.borrow();
37 //~^ WARNING call to `.borrow()` on a reference in this situation does nothing
38
39 // Borrowing a &&T does not warn since it has collapsed the double reference
40 let non_borrow_type = &&PlainType(1u32);
41 let non_borrow_type_borrow: &PlainType<u32> = non_borrow_type.borrow();
42
43 let xs = ["a", "b", "c"];
44 let _v: Vec<&str> = xs.iter().map(|x| x.clone()).collect(); // ok, but could use `*x` instead
45}
46
47fn generic<T>(non_clone_type: &PlainType<T>) {
48 non_clone_type.clone();
49}
50
51fn non_generic(non_clone_type: &PlainType<u32>) {
52 non_clone_type.clone();
53 //~^ WARNING call to `.clone()` on a reference in this situation does nothing
54}