Skip to content

Commit d7e5996

Browse files
committed
Skip elidable_lifetime_names lint for proc-macro generated code
When linting code generated by proc macros (like `derivative`), the `elidable_lifetime_names` lint can produce fix suggestions with overlapping spans. This causes `cargo clippy --fix` to fail with "cannot replace slice of data that was already replaced". This change adds `is_from_proc_macro` checks to the three lint entry points (`check_item`, `check_impl_item`, `check_trait_item`) to skip linting proc-macro generated code entirely. Fixes rust-lang#16316
1 parent e256d3e commit d7e5996

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

clippy_lints/src/lifetimes.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use clippy_config::Conf;
22
use clippy_utils::diagnostics::{span_lint, span_lint_and_then};
33
use clippy_utils::msrvs::{self, Msrv};
4-
use clippy_utils::trait_ref_of_method;
4+
use clippy_utils::{is_from_proc_macro, trait_ref_of_method};
55
use itertools::Itertools;
66
use rustc_ast::visit::{try_visit, walk_list};
77
use rustc_data_structures::fx::{FxHashSet, FxIndexMap, FxIndexSet};
@@ -149,16 +149,22 @@ impl<'tcx> LateLintPass<'tcx> for Lifetimes {
149149
..
150150
} = item.kind
151151
{
152+
if is_from_proc_macro(cx, item) {
153+
return;
154+
}
152155
check_fn_inner(cx, sig, Some(id), None, generics, item.span, true, self.msrv);
153156
} else if let ItemKind::Impl(impl_) = &item.kind
154157
&& !item.span.from_expansion()
158+
&& !is_from_proc_macro(cx, item)
155159
{
156160
report_extra_impl_lifetimes(cx, impl_);
157161
}
158162
}
159163

160164
fn check_impl_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx ImplItem<'_>) {
161-
if let ImplItemKind::Fn(ref sig, id) = item.kind {
165+
if let ImplItemKind::Fn(ref sig, id) = item.kind
166+
&& !is_from_proc_macro(cx, item)
167+
{
162168
let report_extra_lifetimes = trait_ref_of_method(cx, item.owner_id).is_none();
163169
check_fn_inner(
164170
cx,
@@ -174,7 +180,9 @@ impl<'tcx> LateLintPass<'tcx> for Lifetimes {
174180
}
175181

176182
fn check_trait_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx TraitItem<'_>) {
177-
if let TraitItemKind::Fn(ref sig, ref body) = item.kind {
183+
if let TraitItemKind::Fn(ref sig, ref body) = item.kind
184+
&& !is_from_proc_macro(cx, item)
185+
{
178186
let (body, trait_sig) = match *body {
179187
TraitFn::Required(sig) => (None, Some(sig)),
180188
TraitFn::Provided(id) => (Some(id), None),

0 commit comments

Comments
 (0)