fork/rust
git clone https://git.julia.blue/fork/rust
3bcad65fbf6
master
1// check-pass 2// run-rustfix 3 4#![feature(rustc_attrs)] 5#![allow(unused)] 6 7use std::borrow::Borrow; 8use std::ops::Deref; 9 10struct PlainType<T>(T); 11 12#[derive(Clone)] 13struct CloneType<T>(T); 14 15fn check(mut encoded: &[u8]) { 16 let _ = &mut encoded; 17 //~^ WARN call to `.clone()` on a reference in this situation does nothing 18 let _ = &encoded; 19 //~^ WARN call to `.clone()` on a reference in this situation does nothing 20} 21 22fn main() { 23 let non_clone_type_ref = &PlainType(1u32); 24 let non_clone_type_ref_clone: &PlainType<u32> = non_clone_type_ref; 25 //~^ WARN call to `.clone()` on a reference in this situation does nothing 26 27 let clone_type_ref = &CloneType(1u32); 28 let clone_type_ref_clone: CloneType<u32> = clone_type_ref.clone(); 29 30 31 let non_deref_type = &PlainType(1u32); 32 let non_deref_type_deref: &PlainType<u32> = non_deref_type; 33 //~^ WARN call to `.deref()` on a reference in this situation does nothing 34 35 let non_borrow_type = &PlainType(1u32); 36 let non_borrow_type_borrow: &PlainType<u32> = non_borrow_type; 37 //~^ WARN 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 44fn generic<T>(non_clone_type: &PlainType<T>) { 45 non_clone_type; 46 //~^ WARN call to `.clone()` on a reference in this situation does nothing 47} 48 49fn non_generic(non_clone_type: &PlainType<u32>) { 50 non_clone_type; 51 //~^ WARN call to `.clone()` on a reference in this situation does nothing 52} 53 54struct DiagnosticClone; 55impl Clone for DiagnosticClone { 56 #[rustc_diagnostic_item = "other_clone"] 57 fn clone(&self) -> Self { 58 DiagnosticClone 59 } 60} 61 62fn with_other_diagnostic_item(x: DiagnosticClone) { 63 x.clone(); 64}