2024-05-26 09:54:44 +00:00
|
|
|
//@aux-build:proc_macro_derive.rs
|
2023-06-13 10:25:49 +00:00
|
|
|
#![allow(clippy::clone_on_copy, unused)]
|
2024-01-03 13:53:03 +00:00
|
|
|
#![allow(clippy::assigning_clones)]
|
2023-06-11 07:46:28 +00:00
|
|
|
#![no_main]
|
|
|
|
|
2024-05-30 13:43:40 +00:00
|
|
|
extern crate proc_macros;
|
|
|
|
use proc_macros::with_span;
|
|
|
|
|
2023-06-11 07:46:28 +00:00
|
|
|
// lint
|
|
|
|
|
|
|
|
struct A(u32);
|
|
|
|
|
|
|
|
impl Clone for A {
|
|
|
|
fn clone(&self) -> Self {
|
|
|
|
Self(self.0)
|
|
|
|
}
|
2023-06-13 10:25:49 +00:00
|
|
|
|
|
|
|
fn clone_from(&mut self, source: &Self) {
|
|
|
|
source.clone();
|
|
|
|
*self = source.clone();
|
|
|
|
}
|
2023-06-11 07:46:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Copy for A {}
|
|
|
|
|
|
|
|
// do not lint
|
|
|
|
|
|
|
|
struct B(u32);
|
|
|
|
|
|
|
|
impl Clone for B {
|
|
|
|
fn clone(&self) -> Self {
|
|
|
|
*self
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Copy for B {}
|
|
|
|
|
|
|
|
// do not lint derived (clone's implementation is `*self` here anyway)
|
|
|
|
|
|
|
|
#[derive(Clone, Copy)]
|
|
|
|
struct C(u32);
|
|
|
|
|
|
|
|
// do not lint derived (fr this time)
|
|
|
|
|
|
|
|
struct D(u32);
|
|
|
|
|
|
|
|
#[automatically_derived]
|
|
|
|
impl Clone for D {
|
|
|
|
fn clone(&self) -> Self {
|
|
|
|
Self(self.0)
|
|
|
|
}
|
2023-06-13 10:25:49 +00:00
|
|
|
|
|
|
|
fn clone_from(&mut self, source: &Self) {
|
|
|
|
source.clone();
|
|
|
|
*self = source.clone();
|
|
|
|
}
|
2023-06-11 07:46:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Copy for D {}
|
|
|
|
|
|
|
|
// do not lint if clone is not manually implemented
|
|
|
|
|
|
|
|
struct E(u32);
|
|
|
|
|
|
|
|
#[automatically_derived]
|
|
|
|
impl Clone for E {
|
|
|
|
fn clone(&self) -> Self {
|
|
|
|
Self(self.0)
|
|
|
|
}
|
2023-06-13 10:25:49 +00:00
|
|
|
|
|
|
|
fn clone_from(&mut self, source: &Self) {
|
|
|
|
source.clone();
|
|
|
|
*self = source.clone();
|
|
|
|
}
|
2023-06-11 07:46:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Copy for E {}
|
|
|
|
|
2023-06-13 10:25:49 +00:00
|
|
|
// lint since clone is not derived
|
|
|
|
|
|
|
|
#[derive(Copy)]
|
|
|
|
struct F(u32);
|
|
|
|
|
|
|
|
impl Clone for F {
|
|
|
|
fn clone(&self) -> Self {
|
|
|
|
Self(self.0)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn clone_from(&mut self, source: &Self) {
|
|
|
|
source.clone();
|
|
|
|
*self = source.clone();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-11 07:46:28 +00:00
|
|
|
// do not lint since copy has more restrictive bounds
|
|
|
|
|
|
|
|
#[derive(Eq, PartialEq)]
|
|
|
|
struct Uwu<A: Copy>(A);
|
|
|
|
|
|
|
|
impl<A: Copy> Clone for Uwu<A> {
|
|
|
|
fn clone(&self) -> Self {
|
|
|
|
Self(self.0)
|
|
|
|
}
|
2023-06-13 10:25:49 +00:00
|
|
|
|
|
|
|
fn clone_from(&mut self, source: &Self) {
|
|
|
|
source.clone();
|
|
|
|
*self = source.clone();
|
|
|
|
}
|
2023-06-11 07:46:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl<A: std::fmt::Debug + Copy + Clone> Copy for Uwu<A> {}
|
2024-05-26 09:54:44 +00:00
|
|
|
|
|
|
|
// should skip proc macros, see https://github.com/rust-lang/rust-clippy/issues/12788
|
|
|
|
#[derive(proc_macro_derive::NonCanonicalClone)]
|
|
|
|
pub struct G;
|
2024-05-30 13:43:40 +00:00
|
|
|
|
|
|
|
with_span!(
|
|
|
|
span
|
|
|
|
|
|
|
|
#[derive(Copy)]
|
|
|
|
struct H;
|
|
|
|
impl Clone for H {
|
|
|
|
fn clone(&self) -> Self {
|
|
|
|
todo!()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|