Skip to content

Commit a30ca62

Browse files
committed
Auto merge of #11022 - lochetti:fix_11014, r=dswij
Avoid linting `extra_unused_type_parameters` on procedural macros Don't lint `extra_unused_type_parameters` if code was generated by procedural macro. This PR fixes #11014 changelog: [`extra_unused_type_parameters`] avoid linting macro-generated code
2 parents 1b4c423 + f0eb40c commit a30ca62

4 files changed

+34
-8
lines changed

clippy_lints/src/extra_unused_type_parameters.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use clippy_utils::diagnostics::{span_lint_and_help, span_lint_and_then};
2+
use clippy_utils::is_from_proc_macro;
23
use clippy_utils::trait_ref_of_method;
34
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
45
use rustc_errors::Applicability;
@@ -265,6 +266,7 @@ impl<'tcx> LateLintPass<'tcx> for ExtraUnusedTypeParameters {
265266
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'tcx>) {
266267
if let ItemKind::Fn(_, generics, body_id) = item.kind
267268
&& !self.is_empty_exported_or_macro(cx, item.span, item.owner_id.def_id, body_id)
269+
&& !is_from_proc_macro(cx, item)
268270
{
269271
let mut walker = TypeWalker::new(cx, generics);
270272
walk_item(&mut walker, item);

tests/ui/extra_unused_type_parameters.fixed

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
//@run-rustfix
2+
//@aux-build:proc_macros.rs
23

34
#![allow(unused, clippy::needless_lifetimes)]
45
#![warn(clippy::extra_unused_type_parameters)]
56

7+
extern crate proc_macros;
8+
use proc_macros::with_span;
9+
610
fn unused_ty(x: u8) {
711
unimplemented!()
812
}
@@ -102,4 +106,12 @@ mod issue10319 {
102106
}
103107
}
104108

109+
with_span!(
110+
span
111+
112+
fn should_not_lint<T>(x: u8) {
113+
unimplemented!()
114+
}
115+
);
116+
105117
fn main() {}

tests/ui/extra_unused_type_parameters.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
//@run-rustfix
2+
//@aux-build:proc_macros.rs
23

34
#![allow(unused, clippy::needless_lifetimes)]
45
#![warn(clippy::extra_unused_type_parameters)]
56

7+
extern crate proc_macros;
8+
use proc_macros::with_span;
9+
610
fn unused_ty<T>(x: u8) {
711
unimplemented!()
812
}
@@ -102,4 +106,12 @@ mod issue10319 {
102106
}
103107
}
104108

109+
with_span!(
110+
span
111+
112+
fn should_not_lint<T>(x: u8) {
113+
unimplemented!()
114+
}
115+
);
116+
105117
fn main() {}

tests/ui/extra_unused_type_parameters.stderr

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
error: type parameter `T` goes unused in function definition
2-
--> $DIR/extra_unused_type_parameters.rs:6:13
2+
--> $DIR/extra_unused_type_parameters.rs:10:13
33
|
44
LL | fn unused_ty<T>(x: u8) {
55
| ^^^ help: consider removing the parameter
66
|
77
= note: `-D clippy::extra-unused-type-parameters` implied by `-D warnings`
88

99
error: type parameters go unused in function definition: T, U
10-
--> $DIR/extra_unused_type_parameters.rs:10:16
10+
--> $DIR/extra_unused_type_parameters.rs:14:16
1111
|
1212
LL | fn unused_multi<T, U>(x: u8) {
1313
| ^^^^^^ help: consider removing the parameters
1414

1515
error: type parameter `T` goes unused in function definition
16-
--> $DIR/extra_unused_type_parameters.rs:14:21
16+
--> $DIR/extra_unused_type_parameters.rs:18:21
1717
|
1818
LL | fn unused_with_lt<'a, T>(x: &'a u8) {
1919
| ^^^ help: consider removing the parameter
2020

2121
error: type parameters go unused in function definition: T, V
22-
--> $DIR/extra_unused_type_parameters.rs:26:19
22+
--> $DIR/extra_unused_type_parameters.rs:30:19
2323
|
2424
LL | fn unused_bounded<T: Default, U, V: Default>(x: U) {
2525
| ^^^^^^^^^^^^ ^^^^^^^^^^^^
@@ -31,7 +31,7 @@ LL + fn unused_bounded<U>(x: U) {
3131
|
3232

3333
error: type parameters go unused in function definition: A, D, E
34-
--> $DIR/extra_unused_type_parameters.rs:30:16
34+
--> $DIR/extra_unused_type_parameters.rs:34:16
3535
|
3636
LL | fn some_unused<A, B, C, D: Iterator<Item = (B, C)>, E>(b: B, c: C) {
3737
| ^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -43,19 +43,19 @@ LL + fn some_unused<B, C>(b: B, c: C) {
4343
|
4444

4545
error: type parameter `T` goes unused in function definition
46-
--> $DIR/extra_unused_type_parameters.rs:55:22
46+
--> $DIR/extra_unused_type_parameters.rs:59:22
4747
|
4848
LL | fn unused_ty_impl<T>(&self) {
4949
| ^^^ help: consider removing the parameter
5050

5151
error: type parameters go unused in function definition: A, B
52-
--> $DIR/extra_unused_type_parameters.rs:77:17
52+
--> $DIR/extra_unused_type_parameters.rs:81:17
5353
|
5454
LL | fn unused_opaque<A, B>(dummy: impl Default) {
5555
| ^^^^^^ help: consider removing the parameters
5656

5757
error: type parameter `U` goes unused in function definition
58-
--> $DIR/extra_unused_type_parameters.rs:90:56
58+
--> $DIR/extra_unused_type_parameters.rs:94:56
5959
|
6060
LL | fn unused_with_priv_trait_bound<T: private::Private, U>() {
6161
| ^^^ help: consider removing the parameter

0 commit comments

Comments
 (0)