add missing test for macros

The missing external macro test for `non_canonical_clone_impl` was
caught thanks to lintcheck -- I went ahead and added all the other
combinations of the test while at it
This commit is contained in:
Ada Alakbarova 2025-09-24 16:35:46 +02:00
parent ebbbbebf2d
commit 097f2fd2f4
No known key found for this signature in database
6 changed files with 260 additions and 32 deletions

View file

@ -4,7 +4,7 @@
#![no_main]
extern crate proc_macros;
use proc_macros::with_span;
use proc_macros::inline_macros;
// lint
@ -100,18 +100,45 @@ impl<A: Copy> Clone for Uwu<A> {
impl<A: std::fmt::Debug + Copy + Clone> Copy for Uwu<A> {}
// should skip proc macros, see https://github.com/rust-lang/rust-clippy/issues/12788
#[derive(proc_macro_derive::NonCanonicalClone)]
pub struct G;
#[inline_macros]
mod issue12788 {
use proc_macros::{external, with_span};
with_span!(
span
// lint -- not an external macro
inline!(
#[derive(Copy)]
pub struct A;
#[derive(Copy)]
struct H;
impl Clone for H {
fn clone(&self) -> Self {
todo!()
impl Clone for A {
fn clone(&self) -> Self { *self }
}
}
);
);
// do not lint -- should skip external macros
external!(
#[derive(Copy)]
pub struct B;
impl Clone for B {
fn clone(&self) -> Self {
todo!()
}
}
);
// do not lint -- should skip proc macros
#[derive(proc_macro_derive::NonCanonicalClone)]
pub struct C;
with_span!(
span
#[derive(Copy)]
struct D;
impl Clone for D {
fn clone(&self) -> Self {
todo!()
}
}
);
}

View file

@ -4,7 +4,7 @@
#![no_main]
extern crate proc_macros;
use proc_macros::with_span;
use proc_macros::inline_macros;
// lint
@ -114,18 +114,48 @@ impl<A: Copy> Clone for Uwu<A> {
impl<A: std::fmt::Debug + Copy + Clone> Copy for Uwu<A> {}
// should skip proc macros, see https://github.com/rust-lang/rust-clippy/issues/12788
#[derive(proc_macro_derive::NonCanonicalClone)]
pub struct G;
#[inline_macros]
mod issue12788 {
use proc_macros::{external, with_span};
with_span!(
span
// lint -- not an external macro
inline!(
#[derive(Copy)]
pub struct A;
#[derive(Copy)]
struct H;
impl Clone for H {
fn clone(&self) -> Self {
todo!()
impl Clone for A {
fn clone(&self) -> Self {
//~^ non_canonical_clone_impl
todo!()
}
}
}
);
);
// do not lint -- should skip external macros
external!(
#[derive(Copy)]
pub struct B;
impl Clone for B {
fn clone(&self) -> Self {
todo!()
}
}
);
// do not lint -- should skip proc macros
#[derive(proc_macro_derive::NonCanonicalClone)]
pub struct C;
with_span!(
span
#[derive(Copy)]
struct D;
impl Clone for D {
fn clone(&self) -> Self {
todo!()
}
}
);
}

View file

@ -41,5 +41,17 @@ LL | | *self = source.clone();
LL | | }
| |_____^ help: remove it
error: aborting due to 4 previous errors
error: non-canonical implementation of `clone` on a `Copy` type
--> tests/ui/non_canonical_clone_impl.rs:127:37
|
LL | fn clone(&self) -> Self {
| _____________________________________^
LL | |
LL | | todo!()
LL | | }
| |_____________^ help: change this to: `{ *self }`
|
= note: this error originates in the macro `__inline_mac_mod_issue12788` (in Nightly builds, run with -Z macro-backtrace for more info)
error: aborting due to 5 previous errors

View file

@ -1,5 +1,9 @@
//@aux-build:proc_macro_derive.rs
#![no_main]
extern crate proc_macros;
use proc_macros::inline_macros;
use std::cmp::Ordering;
// lint
@ -163,6 +167,73 @@ impl PartialOrd for I {
}
}
#[inline_macros]
mod issue12788 {
use std::cmp::Ordering;
use proc_macros::{external, with_span};
// lint -- not an external macro
inline!(
#[derive(PartialEq, Eq)]
pub struct A;
impl Ord for A {
fn cmp(&self, other: &Self) -> Ordering {
todo!();
}
}
impl PartialOrd for A {
//~^ non_canonical_partial_ord_impl
fn partial_cmp(&self, other: &Self) -> Option<Ordering> { Some(self.cmp(other)) }
}
);
// do not lint -- should skip external macros
external!(
#[derive(PartialEq, Eq)]
pub struct B;
impl Ord for B {
fn cmp(&self, other: &Self) -> Ordering {
todo!();
}
}
impl PartialOrd for B {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
todo!();
}
}
);
// do not lint -- should skip proc macros
#[derive(proc_macro_derive::NonCanonicalClone)]
pub struct C;
with_span!(
span
#[derive(PartialEq, Eq)]
pub struct D;
impl Ord for D {
fn cmp(&self, other: &Self) -> Ordering {
todo!();
}
}
impl PartialOrd for D {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
todo!();
}
}
);
}
// #13640, do not lint
#[derive(Eq, PartialEq)]

View file

@ -1,5 +1,9 @@
//@aux-build:proc_macro_derive.rs
#![no_main]
extern crate proc_macros;
use proc_macros::inline_macros;
use std::cmp::Ordering;
// lint
@ -167,6 +171,75 @@ impl PartialOrd for I {
}
}
#[inline_macros]
mod issue12788 {
use std::cmp::Ordering;
use proc_macros::{external, with_span};
// lint -- not an external macro
inline!(
#[derive(PartialEq, Eq)]
pub struct A;
impl Ord for A {
fn cmp(&self, other: &Self) -> Ordering {
todo!();
}
}
impl PartialOrd for A {
//~^ non_canonical_partial_ord_impl
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
todo!();
}
}
);
// do not lint -- should skip external macros
external!(
#[derive(PartialEq, Eq)]
pub struct B;
impl Ord for B {
fn cmp(&self, other: &Self) -> Ordering {
todo!();
}
}
impl PartialOrd for B {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
todo!();
}
}
);
// do not lint -- should skip proc macros
#[derive(proc_macro_derive::NonCanonicalClone)]
pub struct C;
with_span!(
span
#[derive(PartialEq, Eq)]
pub struct D;
impl Ord for D {
fn cmp(&self, other: &Self) -> Ordering {
todo!();
}
}
impl PartialOrd for D {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
todo!();
}
}
);
}
// #13640, do not lint
#[derive(Eq, PartialEq)]

View file

@ -1,5 +1,5 @@
error: non-canonical implementation of `partial_cmp` on an `Ord` type
--> tests/ui/non_canonical_partial_ord_impl.rs:16:1
--> tests/ui/non_canonical_partial_ord_impl.rs:20:1
|
LL | / impl PartialOrd for A {
LL | |
@ -15,7 +15,7 @@ LL | | }
= help: to override `-D warnings` add `#[allow(clippy::non_canonical_partial_ord_impl)]`
error: non-canonical implementation of `partial_cmp` on an `Ord` type
--> tests/ui/non_canonical_partial_ord_impl.rs:51:1
--> tests/ui/non_canonical_partial_ord_impl.rs:55:1
|
LL | / impl PartialOrd for C {
LL | |
@ -32,7 +32,22 @@ LL + fn partial_cmp(&self, other: &Self) -> Option<Ordering> { Some(self.cmp
|
error: non-canonical implementation of `partial_cmp` on an `Ord` type
--> tests/ui/non_canonical_partial_ord_impl.rs:198:1
--> tests/ui/non_canonical_partial_ord_impl.rs:191:9
|
LL | / impl PartialOrd for A {
LL | |
LL | | fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
| | _____________________________________________________________________-
LL | || todo!();
LL | || }
| ||_____________- help: change this to: `{ Some(self.cmp(other)) }`
LL | | }
| |__________^
|
= note: this error originates in the macro `__inline_mac_mod_issue12788` (in Nightly builds, run with -Z macro-backtrace for more info)
error: non-canonical implementation of `partial_cmp` on an `Ord` type
--> tests/ui/non_canonical_partial_ord_impl.rs:271:1
|
LL | / impl PartialOrd for K {
LL | |
@ -45,7 +60,7 @@ LL | | }
| |__^
error: non-canonical implementation of `partial_cmp` on an `Ord` type
--> tests/ui/non_canonical_partial_ord_impl.rs:216:1
--> tests/ui/non_canonical_partial_ord_impl.rs:289:1
|
LL | / impl PartialOrd for L {
LL | |
@ -57,5 +72,5 @@ LL | || }
LL | | }
| |__^
error: aborting due to 4 previous errors
error: aborting due to 5 previous errors