]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/tests/ui/needless_borrow.fixed
Rollup merge of #85663 - fee1-dead:document-arc-from, r=m-ou-se
[rust.git] / src / tools / clippy / tests / ui / needless_borrow.fixed
1 // run-rustfix
2
3 #![allow(clippy::needless_borrowed_reference)]
4
5 fn x(y: &i32) -> i32 {
6     *y
7 }
8
9 #[warn(clippy::all, clippy::needless_borrow)]
10 #[allow(unused_variables)]
11 fn main() {
12     let a = 5;
13     let b = x(&a);
14     let c = x(&a);
15     let s = &String::from("hi");
16     let s_ident = f(&s); // should not error, because `&String` implements Copy, but `String` does not
17     let g_val = g(&Vec::new()); // should not error, because `&Vec<T>` derefs to `&[T]`
18     let vec = Vec::new();
19     let vec_val = g(&vec); // should not error, because `&Vec<T>` derefs to `&[T]`
20     h(&"foo"); // should not error, because the `&&str` is required, due to `&Trait`
21     let garbl = match 42 {
22         44 => &a,
23         45 => {
24             println!("foo");
25             &&a // FIXME: this should lint, too
26         },
27         46 => &a,
28         _ => panic!(),
29     };
30 }
31
32 fn f<T: Copy>(y: &T) -> T {
33     *y
34 }
35
36 fn g(y: &[u8]) -> u8 {
37     y[0]
38 }
39
40 trait Trait {}
41
42 impl<'a> Trait for &'a str {}
43
44 fn h(_: &dyn Trait) {}