Skip to content

Commit a14be49

Browse files
committed
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
1 parent 12e0c4c commit a14be49

6 files changed

+260
-32
lines changed

tests/ui/non_canonical_clone_impl.fixed

Lines changed: 40 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#![no_main]
55

66
extern crate proc_macros;
7-
use proc_macros::with_span;
7+
use proc_macros::inline_macros;
88

99
// lint
1010

@@ -100,18 +100,45 @@ impl<A: Copy> Clone for Uwu<A> {
100100

101101
impl<A: std::fmt::Debug + Copy + Clone> Copy for Uwu<A> {}
102102

103-
// should skip proc macros, see https://github.com/rust-lang/rust-clippy/issues/12788
104-
#[derive(proc_macro_derive::NonCanonicalClone)]
105-
pub struct G;
103+
#[inline_macros]
104+
mod issue12788 {
105+
use proc_macros::{external, with_span};
106106

107-
with_span!(
108-
span
107+
// lint -- not an external macro
108+
inline!(
109+
#[derive(Copy)]
110+
pub struct A;
109111

110-
#[derive(Copy)]
111-
struct H;
112-
impl Clone for H {
113-
fn clone(&self) -> Self {
114-
todo!()
112+
impl Clone for A {
113+
fn clone(&self) -> Self { *self }
115114
}
116-
}
117-
);
115+
);
116+
117+
// do not lint -- should skip external macros
118+
external!(
119+
#[derive(Copy)]
120+
pub struct B;
121+
122+
impl Clone for B {
123+
fn clone(&self) -> Self {
124+
todo!()
125+
}
126+
}
127+
);
128+
129+
// do not lint -- should skip proc macros
130+
#[derive(proc_macro_derive::NonCanonicalClone)]
131+
pub struct C;
132+
133+
with_span!(
134+
span
135+
136+
#[derive(Copy)]
137+
struct D;
138+
impl Clone for D {
139+
fn clone(&self) -> Self {
140+
todo!()
141+
}
142+
}
143+
);
144+
}

tests/ui/non_canonical_clone_impl.rs

Lines changed: 43 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#![no_main]
55

66
extern crate proc_macros;
7-
use proc_macros::with_span;
7+
use proc_macros::inline_macros;
88

99
// lint
1010

@@ -114,18 +114,48 @@ impl<A: Copy> Clone for Uwu<A> {
114114

115115
impl<A: std::fmt::Debug + Copy + Clone> Copy for Uwu<A> {}
116116

117-
// should skip proc macros, see https://github.com/rust-lang/rust-clippy/issues/12788
118-
#[derive(proc_macro_derive::NonCanonicalClone)]
119-
pub struct G;
117+
#[inline_macros]
118+
mod issue12788 {
119+
use proc_macros::{external, with_span};
120120

121-
with_span!(
122-
span
121+
// lint -- not an external macro
122+
inline!(
123+
#[derive(Copy)]
124+
pub struct A;
123125

124-
#[derive(Copy)]
125-
struct H;
126-
impl Clone for H {
127-
fn clone(&self) -> Self {
128-
todo!()
126+
impl Clone for A {
127+
fn clone(&self) -> Self {
128+
//~^ non_canonical_clone_impl
129+
todo!()
130+
}
129131
}
130-
}
131-
);
132+
);
133+
134+
// do not lint -- should skip external macros
135+
external!(
136+
#[derive(Copy)]
137+
pub struct B;
138+
139+
impl Clone for B {
140+
fn clone(&self) -> Self {
141+
todo!()
142+
}
143+
}
144+
);
145+
146+
// do not lint -- should skip proc macros
147+
#[derive(proc_macro_derive::NonCanonicalClone)]
148+
pub struct C;
149+
150+
with_span!(
151+
span
152+
153+
#[derive(Copy)]
154+
struct D;
155+
impl Clone for D {
156+
fn clone(&self) -> Self {
157+
todo!()
158+
}
159+
}
160+
);
161+
}

tests/ui/non_canonical_clone_impl.stderr

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,17 @@ LL | | *self = source.clone();
4141
LL | | }
4242
| |_____^ help: remove it
4343

44-
error: aborting due to 4 previous errors
44+
error: non-canonical implementation of `clone` on a `Copy` type
45+
--> tests/ui/non_canonical_clone_impl.rs:127:37
46+
|
47+
LL | fn clone(&self) -> Self {
48+
| _____________________________________^
49+
LL | |
50+
LL | | todo!()
51+
LL | | }
52+
| |_____________^ help: change this to: `{ *self }`
53+
|
54+
= note: this error originates in the macro `__inline_mac_mod_issue12788` (in Nightly builds, run with -Z macro-backtrace for more info)
55+
56+
error: aborting due to 5 previous errors
4557

tests/ui/non_canonical_partial_ord_impl.fixed

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1+
//@aux-build:proc_macro_derive.rs
12
#![no_main]
23

4+
extern crate proc_macros;
5+
use proc_macros::inline_macros;
6+
37
use std::cmp::Ordering;
48

59
// lint
@@ -163,6 +167,73 @@ impl PartialOrd for I {
163167
}
164168
}
165169

170+
#[inline_macros]
171+
mod issue12788 {
172+
use std::cmp::Ordering;
173+
174+
use proc_macros::{external, with_span};
175+
176+
// lint -- not an external macro
177+
inline!(
178+
#[derive(PartialEq, Eq)]
179+
pub struct A;
180+
181+
impl Ord for A {
182+
fn cmp(&self, other: &Self) -> Ordering {
183+
todo!();
184+
}
185+
}
186+
187+
impl PartialOrd for A {
188+
//~^ non_canonical_partial_ord_impl
189+
fn partial_cmp(&self, other: &Self) -> Option<Ordering> { Some(self.cmp(other)) }
190+
}
191+
);
192+
193+
// do not lint -- should skip external macros
194+
external!(
195+
#[derive(PartialEq, Eq)]
196+
pub struct B;
197+
198+
impl Ord for B {
199+
fn cmp(&self, other: &Self) -> Ordering {
200+
todo!();
201+
}
202+
}
203+
204+
impl PartialOrd for B {
205+
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
206+
todo!();
207+
}
208+
}
209+
210+
);
211+
212+
// do not lint -- should skip proc macros
213+
#[derive(proc_macro_derive::NonCanonicalClone)]
214+
pub struct C;
215+
216+
with_span!(
217+
span
218+
219+
#[derive(PartialEq, Eq)]
220+
pub struct D;
221+
222+
impl Ord for D {
223+
fn cmp(&self, other: &Self) -> Ordering {
224+
todo!();
225+
}
226+
}
227+
228+
impl PartialOrd for D {
229+
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
230+
todo!();
231+
}
232+
}
233+
234+
);
235+
}
236+
166237
// #13640, do not lint
167238

168239
#[derive(Eq, PartialEq)]

tests/ui/non_canonical_partial_ord_impl.rs

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1+
//@aux-build:proc_macro_derive.rs
12
#![no_main]
23

4+
extern crate proc_macros;
5+
use proc_macros::inline_macros;
6+
37
use std::cmp::Ordering;
48

59
// lint
@@ -167,6 +171,75 @@ impl PartialOrd for I {
167171
}
168172
}
169173

174+
#[inline_macros]
175+
mod issue12788 {
176+
use std::cmp::Ordering;
177+
178+
use proc_macros::{external, with_span};
179+
180+
// lint -- not an external macro
181+
inline!(
182+
#[derive(PartialEq, Eq)]
183+
pub struct A;
184+
185+
impl Ord for A {
186+
fn cmp(&self, other: &Self) -> Ordering {
187+
todo!();
188+
}
189+
}
190+
191+
impl PartialOrd for A {
192+
//~^ non_canonical_partial_ord_impl
193+
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
194+
todo!();
195+
}
196+
}
197+
);
198+
199+
// do not lint -- should skip external macros
200+
external!(
201+
#[derive(PartialEq, Eq)]
202+
pub struct B;
203+
204+
impl Ord for B {
205+
fn cmp(&self, other: &Self) -> Ordering {
206+
todo!();
207+
}
208+
}
209+
210+
impl PartialOrd for B {
211+
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
212+
todo!();
213+
}
214+
}
215+
216+
);
217+
218+
// do not lint -- should skip proc macros
219+
#[derive(proc_macro_derive::NonCanonicalClone)]
220+
pub struct C;
221+
222+
with_span!(
223+
span
224+
225+
#[derive(PartialEq, Eq)]
226+
pub struct D;
227+
228+
impl Ord for D {
229+
fn cmp(&self, other: &Self) -> Ordering {
230+
todo!();
231+
}
232+
}
233+
234+
impl PartialOrd for D {
235+
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
236+
todo!();
237+
}
238+
}
239+
240+
);
241+
}
242+
170243
// #13640, do not lint
171244

172245
#[derive(Eq, PartialEq)]

tests/ui/non_canonical_partial_ord_impl.stderr

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: non-canonical implementation of `partial_cmp` on an `Ord` type
2-
--> tests/ui/non_canonical_partial_ord_impl.rs:16:1
2+
--> tests/ui/non_canonical_partial_ord_impl.rs:20:1
33
|
44
LL | / impl PartialOrd for A {
55
LL | |
@@ -15,7 +15,7 @@ LL | | }
1515
= help: to override `-D warnings` add `#[allow(clippy::non_canonical_partial_ord_impl)]`
1616

1717
error: non-canonical implementation of `partial_cmp` on an `Ord` type
18-
--> tests/ui/non_canonical_partial_ord_impl.rs:51:1
18+
--> tests/ui/non_canonical_partial_ord_impl.rs:55:1
1919
|
2020
LL | / impl PartialOrd for C {
2121
LL | |
@@ -32,7 +32,22 @@ LL + fn partial_cmp(&self, other: &Self) -> Option<Ordering> { Some(self.cmp
3232
|
3333

3434
error: non-canonical implementation of `partial_cmp` on an `Ord` type
35-
--> tests/ui/non_canonical_partial_ord_impl.rs:198:1
35+
--> tests/ui/non_canonical_partial_ord_impl.rs:191:9
36+
|
37+
LL | / impl PartialOrd for A {
38+
LL | |
39+
LL | | fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
40+
| | _____________________________________________________________________-
41+
LL | || todo!();
42+
LL | || }
43+
| ||_____________- help: change this to: `{ Some(self.cmp(other)) }`
44+
LL | | }
45+
| |__________^
46+
|
47+
= note: this error originates in the macro `__inline_mac_mod_issue12788` (in Nightly builds, run with -Z macro-backtrace for more info)
48+
49+
error: non-canonical implementation of `partial_cmp` on an `Ord` type
50+
--> tests/ui/non_canonical_partial_ord_impl.rs:271:1
3651
|
3752
LL | / impl PartialOrd for K {
3853
LL | |
@@ -45,7 +60,7 @@ LL | | }
4560
| |__^
4661

4762
error: non-canonical implementation of `partial_cmp` on an `Ord` type
48-
--> tests/ui/non_canonical_partial_ord_impl.rs:216:1
63+
--> tests/ui/non_canonical_partial_ord_impl.rs:289:1
4964
|
5065
LL | / impl PartialOrd for L {
5166
LL | |
@@ -57,5 +72,5 @@ LL | || }
5772
LL | | }
5873
| |__^
5974

60-
error: aborting due to 4 previous errors
75+
error: aborting due to 5 previous errors
6176

0 commit comments

Comments
 (0)