Skip to content

Commit 55c9100

Browse files
committed
Don't ling as_conversions in proc macros
1 parent 60258b0 commit 55c9100

File tree

4 files changed

+20
-10
lines changed

4 files changed

+20
-10
lines changed

clippy_lints/src/as_conversions.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use clippy_utils::diagnostics::span_lint_and_help;
2-
use rustc_ast::ast::{Expr, ExprKind};
3-
use rustc_lint::{EarlyContext, EarlyLintPass, LintContext};
2+
use clippy_utils::is_from_proc_macro;
3+
use rustc_hir::{Expr, ExprKind};
4+
use rustc_lint::{LateContext, LateLintPass, LintContext};
45
use rustc_middle::lint::in_external_macro;
56
use rustc_session::{declare_lint_pass, declare_tool_lint};
67

@@ -45,9 +46,9 @@ declare_clippy_lint! {
4546

4647
declare_lint_pass!(AsConversions => [AS_CONVERSIONS]);
4748

48-
impl EarlyLintPass for AsConversions {
49-
fn check_expr(&mut self, cx: &EarlyContext<'_>, expr: &Expr) {
50-
if in_external_macro(cx.sess(), expr.span) {
49+
impl<'tcx> LateLintPass<'tcx> for AsConversions {
50+
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &Expr<'tcx>) {
51+
if in_external_macro(cx.sess(), expr.span) || is_from_proc_macro(cx, expr) {
5152
return;
5253
}
5354

clippy_lints/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -839,7 +839,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
839839
store.register_late_pass(move |_| Box::new(large_stack_arrays::LargeStackArrays::new(array_size_threshold)));
840840
store.register_late_pass(move |_| Box::new(large_const_arrays::LargeConstArrays::new(array_size_threshold)));
841841
store.register_late_pass(|_| Box::new(floating_point_arithmetic::FloatingPointArithmetic));
842-
store.register_early_pass(|| Box::new(as_conversions::AsConversions));
842+
store.register_late_pass(|_| Box::new(as_conversions::AsConversions));
843843
store.register_late_pass(|_| Box::new(let_underscore::LetUnderscore));
844844
store.register_early_pass(|| Box::<single_component_path_imports::SingleComponentPathImports>::default());
845845
let max_fn_params_bools = conf.max_fn_params_bools;

tests/ui/as_conversions.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
//@aux-build:proc_macros.rs
22

33
#![warn(clippy::as_conversions)]
4-
#![allow(clippy::borrow_as_ptr)]
4+
#![allow(clippy::borrow_as_ptr, unused)]
55

66
extern crate proc_macros;
77
use proc_macros::external;
8+
use proc_macros::with_span;
89

910
fn main() {
1011
let i = 0u32 as u64;
@@ -13,3 +14,11 @@ fn main() {
1314

1415
external!(0u32 as u64);
1516
}
17+
18+
with_span!(
19+
span
20+
21+
fn coverting() {
22+
let x = 0u32 as u64;
23+
}
24+
);

tests/ui/as_conversions.stderr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: using a potentially dangerous silent `as` conversion
2-
--> $DIR/as_conversions.rs:10:13
2+
--> $DIR/as_conversions.rs:11:13
33
|
44
LL | let i = 0u32 as u64;
55
| ^^^^^^^^^^^
@@ -8,15 +8,15 @@ LL | let i = 0u32 as u64;
88
= note: `-D clippy::as-conversions` implied by `-D warnings`
99

1010
error: using a potentially dangerous silent `as` conversion
11-
--> $DIR/as_conversions.rs:12:13
11+
--> $DIR/as_conversions.rs:13:13
1212
|
1313
LL | let j = &i as *const u64 as *mut u64;
1414
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1515
|
1616
= help: consider using a safe wrapper for this conversion
1717

1818
error: using a potentially dangerous silent `as` conversion
19-
--> $DIR/as_conversions.rs:12:13
19+
--> $DIR/as_conversions.rs:13:13
2020
|
2121
LL | let j = &i as *const u64 as *mut u64;
2222
| ^^^^^^^^^^^^^^^^

0 commit comments

Comments
 (0)