Skip to content

Commit dd2d448

Browse files
committed
replace inline!, a proc-macro, with a MBE
this allows its contents to get linted again despite the `is_from_proc_macro` check I think this should be right, since proc-macros are by definition located in a separate crate, so the user can't generally modify their contents to appease Clippy
1 parent 9f7332b commit dd2d448

File tree

3 files changed

+60
-39
lines changed

3 files changed

+60
-39
lines changed

tests/ui/ptr_as_ptr.fixed

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#![warn(clippy::ptr_as_ptr)]
44

55
extern crate proc_macros;
6-
use proc_macros::{external, inline_macros, with_span};
6+
use proc_macros::{external, with_span};
77

88
mod issue_11278_a {
99
#[derive(Debug)]
@@ -20,7 +20,6 @@ mod issue_11278_b {
2020
}
2121
}
2222

23-
#[inline_macros]
2423
fn main() {
2524
let ptr: *const u32 = &42_u32;
2625
let mut_ptr: *mut u32 = &mut 42_u32;
@@ -53,7 +52,13 @@ fn main() {
5352
//~^ ptr_as_ptr
5453

5554
// Make sure the lint is triggered inside a macro
56-
let _ = inline!($ptr as *const i32);
55+
macro_rules! foo {
56+
() => {
57+
ptr.cast::<i32>()
58+
//~^ ptr_as_ptr
59+
};
60+
};
61+
foo!();
5762

5863
// Do not lint inside macros from external crates
5964
let _ = external!($ptr as *const i32);

tests/ui/ptr_as_ptr.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#![warn(clippy::ptr_as_ptr)]
44

55
extern crate proc_macros;
6-
use proc_macros::{external, inline_macros, with_span};
6+
use proc_macros::{external, with_span};
77

88
mod issue_11278_a {
99
#[derive(Debug)]
@@ -20,7 +20,6 @@ mod issue_11278_b {
2020
}
2121
}
2222

23-
#[inline_macros]
2423
fn main() {
2524
let ptr: *const u32 = &42_u32;
2625
let mut_ptr: *mut u32 = &mut 42_u32;
@@ -53,7 +52,13 @@ fn main() {
5352
//~^ ptr_as_ptr
5453

5554
// Make sure the lint is triggered inside a macro
56-
let _ = inline!($ptr as *const i32);
55+
macro_rules! foo {
56+
() => {
57+
ptr as *const i32
58+
//~^ ptr_as_ptr
59+
};
60+
};
61+
foo!();
5762

5863
// Do not lint inside macros from external crates
5964
let _ = external!($ptr as *const i32);

tests/ui/ptr_as_ptr.stderr

Lines changed: 44 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -8,196 +8,207 @@ LL | *unsafe { Box::from_raw(Box::into_raw(Box::new(o)) as *mut super::i
88
= help: to override `-D warnings` add `#[allow(clippy::ptr_as_ptr)]`
99

1010
error: `as` casting between raw pointers without changing their constness
11-
--> tests/ui/ptr_as_ptr.rs:28:13
11+
--> tests/ui/ptr_as_ptr.rs:27:13
1212
|
1313
LL | let _ = ptr as *const i32;
1414
| ^^^^^^^^^^^^^^^^^ help: try `pointer::cast`, a safer alternative: `ptr.cast::<i32>()`
1515

1616
error: `as` casting between raw pointers without changing their constness
17-
--> tests/ui/ptr_as_ptr.rs:30:13
17+
--> tests/ui/ptr_as_ptr.rs:29:13
1818
|
1919
LL | let _ = mut_ptr as *mut i32;
2020
| ^^^^^^^^^^^^^^^^^^^ help: try `pointer::cast`, a safer alternative: `mut_ptr.cast::<i32>()`
2121

2222
error: `as` casting between raw pointers without changing their constness
23-
--> tests/ui/ptr_as_ptr.rs:36:17
23+
--> tests/ui/ptr_as_ptr.rs:35:17
2424
|
2525
LL | let _ = *ptr_ptr as *const i32;
2626
| ^^^^^^^^^^^^^^^^^^^^^^ help: try `pointer::cast`, a safer alternative: `(*ptr_ptr).cast::<i32>()`
2727

2828
error: `as` casting between raw pointers without changing their constness
29-
--> tests/ui/ptr_as_ptr.rs:50:25
29+
--> tests/ui/ptr_as_ptr.rs:49:25
3030
|
3131
LL | let _: *const i32 = ptr as *const _;
3232
| ^^^^^^^^^^^^^^^ help: try `pointer::cast`, a safer alternative: `ptr.cast()`
3333

3434
error: `as` casting between raw pointers without changing their constness
35-
--> tests/ui/ptr_as_ptr.rs:52:23
35+
--> tests/ui/ptr_as_ptr.rs:51:23
3636
|
3737
LL | let _: *mut i32 = mut_ptr as _;
3838
| ^^^^^^^^^^^^ help: try `pointer::cast`, a safer alternative: `mut_ptr.cast()`
3939

4040
error: `as` casting between raw pointers without changing their constness
41-
--> tests/ui/ptr_as_ptr.rs:79:13
41+
--> tests/ui/ptr_as_ptr.rs:57:13
42+
|
43+
LL | ptr as *const i32
44+
| ^^^^^^^^^^^^^^^^^ help: try `pointer::cast`, a safer alternative: `ptr.cast::<i32>()`
45+
...
46+
LL | foo!();
47+
| ------ in this macro invocation
48+
|
49+
= note: this error originates in the macro `foo` (in Nightly builds, run with -Z macro-backtrace for more info)
50+
51+
error: `as` casting between raw pointers without changing their constness
52+
--> tests/ui/ptr_as_ptr.rs:84:13
4253
|
4354
LL | let _ = ptr as *const i32;
4455
| ^^^^^^^^^^^^^^^^^ help: try `pointer::cast`, a safer alternative: `ptr.cast::<i32>()`
4556

4657
error: `as` casting between raw pointers without changing their constness
47-
--> tests/ui/ptr_as_ptr.rs:81:13
58+
--> tests/ui/ptr_as_ptr.rs:86:13
4859
|
4960
LL | let _ = mut_ptr as *mut i32;
5061
| ^^^^^^^^^^^^^^^^^^^ help: try `pointer::cast`, a safer alternative: `mut_ptr.cast::<i32>()`
5162

5263
error: `as` casting between raw pointers without changing their constness
53-
--> tests/ui/ptr_as_ptr.rs:89:9
64+
--> tests/ui/ptr_as_ptr.rs:94:9
5465
|
5566
LL | ptr::null_mut() as *mut u32
5667
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try call directly: `ptr::null_mut::<u32>()`
5768

5869
error: `as` casting between raw pointers without changing their constness
59-
--> tests/ui/ptr_as_ptr.rs:94:9
70+
--> tests/ui/ptr_as_ptr.rs:99:9
6071
|
6172
LL | std::ptr::null_mut() as *mut u32
6273
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try call directly: `std::ptr::null_mut::<u32>()`
6374

6475
error: `as` casting between raw pointers without changing their constness
65-
--> tests/ui/ptr_as_ptr.rs:100:9
76+
--> tests/ui/ptr_as_ptr.rs:105:9
6677
|
6778
LL | ptr::null_mut() as *mut u32
6879
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try call directly: `ptr::null_mut::<u32>()`
6980

7081
error: `as` casting between raw pointers without changing their constness
71-
--> tests/ui/ptr_as_ptr.rs:105:9
82+
--> tests/ui/ptr_as_ptr.rs:110:9
7283
|
7384
LL | core::ptr::null_mut() as *mut u32
7485
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try call directly: `core::ptr::null_mut::<u32>()`
7586

7687
error: `as` casting between raw pointers without changing their constness
77-
--> tests/ui/ptr_as_ptr.rs:111:9
88+
--> tests/ui/ptr_as_ptr.rs:116:9
7889
|
7990
LL | ptr::null() as *const u32
8091
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try call directly: `ptr::null::<u32>()`
8192

8293
error: `as` casting between raw pointers without changing their constness
83-
--> tests/ui/ptr_as_ptr.rs:116:9
94+
--> tests/ui/ptr_as_ptr.rs:121:9
8495
|
8596
LL | std::ptr::null() as *const u32
8697
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try call directly: `std::ptr::null::<u32>()`
8798

8899
error: `as` casting between raw pointers without changing their constness
89-
--> tests/ui/ptr_as_ptr.rs:122:9
100+
--> tests/ui/ptr_as_ptr.rs:127:9
90101
|
91102
LL | ptr::null() as *const u32
92103
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try call directly: `ptr::null::<u32>()`
93104

94105
error: `as` casting between raw pointers without changing their constness
95-
--> tests/ui/ptr_as_ptr.rs:127:9
106+
--> tests/ui/ptr_as_ptr.rs:132:9
96107
|
97108
LL | core::ptr::null() as *const u32
98109
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try call directly: `core::ptr::null::<u32>()`
99110

100111
error: `as` casting between raw pointers without changing their constness
101-
--> tests/ui/ptr_as_ptr.rs:135:9
112+
--> tests/ui/ptr_as_ptr.rs:140:9
102113
|
103114
LL | ptr::null_mut() as *mut _
104115
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try call directly: `ptr::null_mut()`
105116

106117
error: `as` casting between raw pointers without changing their constness
107-
--> tests/ui/ptr_as_ptr.rs:140:9
118+
--> tests/ui/ptr_as_ptr.rs:145:9
108119
|
109120
LL | std::ptr::null_mut() as *mut _
110121
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try call directly: `std::ptr::null_mut()`
111122

112123
error: `as` casting between raw pointers without changing their constness
113-
--> tests/ui/ptr_as_ptr.rs:146:9
124+
--> tests/ui/ptr_as_ptr.rs:151:9
114125
|
115126
LL | ptr::null_mut() as *mut _
116127
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try call directly: `ptr::null_mut()`
117128

118129
error: `as` casting between raw pointers without changing their constness
119-
--> tests/ui/ptr_as_ptr.rs:151:9
130+
--> tests/ui/ptr_as_ptr.rs:156:9
120131
|
121132
LL | core::ptr::null_mut() as *mut _
122133
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try call directly: `core::ptr::null_mut()`
123134

124135
error: `as` casting between raw pointers without changing their constness
125-
--> tests/ui/ptr_as_ptr.rs:157:9
136+
--> tests/ui/ptr_as_ptr.rs:162:9
126137
|
127138
LL | ptr::null() as *const _
128139
| ^^^^^^^^^^^^^^^^^^^^^^^ help: try call directly: `ptr::null()`
129140

130141
error: `as` casting between raw pointers without changing their constness
131-
--> tests/ui/ptr_as_ptr.rs:162:9
142+
--> tests/ui/ptr_as_ptr.rs:167:9
132143
|
133144
LL | std::ptr::null() as *const _
134145
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try call directly: `std::ptr::null()`
135146

136147
error: `as` casting between raw pointers without changing their constness
137-
--> tests/ui/ptr_as_ptr.rs:168:9
148+
--> tests/ui/ptr_as_ptr.rs:173:9
138149
|
139150
LL | ptr::null() as *const _
140151
| ^^^^^^^^^^^^^^^^^^^^^^^ help: try call directly: `ptr::null()`
141152

142153
error: `as` casting between raw pointers without changing their constness
143-
--> tests/ui/ptr_as_ptr.rs:173:9
154+
--> tests/ui/ptr_as_ptr.rs:178:9
144155
|
145156
LL | core::ptr::null() as *const _
146157
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try call directly: `core::ptr::null()`
147158

148159
error: `as` casting between raw pointers without changing their constness
149-
--> tests/ui/ptr_as_ptr.rs:181:9
160+
--> tests/ui/ptr_as_ptr.rs:186:9
150161
|
151162
LL | ptr::null_mut() as _
152163
| ^^^^^^^^^^^^^^^^^^^^ help: try call directly: `ptr::null_mut()`
153164

154165
error: `as` casting between raw pointers without changing their constness
155-
--> tests/ui/ptr_as_ptr.rs:186:9
166+
--> tests/ui/ptr_as_ptr.rs:191:9
156167
|
157168
LL | std::ptr::null_mut() as _
158169
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try call directly: `std::ptr::null_mut()`
159170

160171
error: `as` casting between raw pointers without changing their constness
161-
--> tests/ui/ptr_as_ptr.rs:192:9
172+
--> tests/ui/ptr_as_ptr.rs:197:9
162173
|
163174
LL | ptr::null_mut() as _
164175
| ^^^^^^^^^^^^^^^^^^^^ help: try call directly: `ptr::null_mut()`
165176

166177
error: `as` casting between raw pointers without changing their constness
167-
--> tests/ui/ptr_as_ptr.rs:197:9
178+
--> tests/ui/ptr_as_ptr.rs:202:9
168179
|
169180
LL | core::ptr::null_mut() as _
170181
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try call directly: `core::ptr::null_mut()`
171182

172183
error: `as` casting between raw pointers without changing their constness
173-
--> tests/ui/ptr_as_ptr.rs:203:9
184+
--> tests/ui/ptr_as_ptr.rs:208:9
174185
|
175186
LL | ptr::null() as _
176187
| ^^^^^^^^^^^^^^^^ help: try call directly: `ptr::null()`
177188

178189
error: `as` casting between raw pointers without changing their constness
179-
--> tests/ui/ptr_as_ptr.rs:208:9
190+
--> tests/ui/ptr_as_ptr.rs:213:9
180191
|
181192
LL | std::ptr::null() as _
182193
| ^^^^^^^^^^^^^^^^^^^^^ help: try call directly: `std::ptr::null()`
183194

184195
error: `as` casting between raw pointers without changing their constness
185-
--> tests/ui/ptr_as_ptr.rs:214:9
196+
--> tests/ui/ptr_as_ptr.rs:219:9
186197
|
187198
LL | ptr::null() as _
188199
| ^^^^^^^^^^^^^^^^ help: try call directly: `ptr::null()`
189200

190201
error: `as` casting between raw pointers without changing their constness
191-
--> tests/ui/ptr_as_ptr.rs:219:9
202+
--> tests/ui/ptr_as_ptr.rs:224:9
192203
|
193204
LL | core::ptr::null() as _
194205
| ^^^^^^^^^^^^^^^^^^^^^^ help: try call directly: `core::ptr::null()`
195206

196207
error: `as` casting between raw pointers without changing their constness
197-
--> tests/ui/ptr_as_ptr.rs:227:43
208+
--> tests/ui/ptr_as_ptr.rs:232:43
198209
|
199210
LL | let _: fn() = std::mem::transmute(std::ptr::null::<()>() as *const u8);
200211
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try call directly: `std::ptr::null::<u8>()`
201212

202-
error: aborting due to 33 previous errors
213+
error: aborting due to 34 previous errors
203214

0 commit comments

Comments
 (0)