Rollup merge of #107648 - matthiaskrgr:unused_lifetime_104432_fix, r=cjgillot
unused-lifetimes: don't warn about lifetimes originating from expanded code previously, we would warn like this: ```` warning: lifetime parameter `'s` never used --> /tmp/unusedlif/code.rs:6:62 | 5 | #[derive(Clone)] | - help: elide the unused lifetime 6 | struct ShimMethod4<T: Trait2 + 'static>(pub &'static dyn for<'s> Fn(&'s mut T::As)); | ^^ | = note: requested on the command line with `-W unused-lifetimes` ```` Fixes #104432
This commit is contained in:
commit
be1789a56d
@ -2244,19 +2244,23 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
|
|||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
debug!(?param.ident, ?param.ident.span);
|
debug!(?param.ident, ?param.ident.span);
|
||||||
|
|
||||||
let deletion_span = deletion_span();
|
let deletion_span = deletion_span();
|
||||||
self.r.lint_buffer.buffer_lint_with_diagnostic(
|
// the give lifetime originates from expanded code so we won't be able to remove it #104432
|
||||||
lint::builtin::UNUSED_LIFETIMES,
|
let lifetime_only_in_expanded_code =
|
||||||
param.id,
|
deletion_span.map(|sp| sp.in_derive_expansion()).unwrap_or(true);
|
||||||
param.ident.span,
|
if !lifetime_only_in_expanded_code {
|
||||||
&format!("lifetime parameter `{}` never used", param.ident),
|
self.r.lint_buffer.buffer_lint_with_diagnostic(
|
||||||
lint::BuiltinLintDiagnostics::SingleUseLifetime {
|
lint::builtin::UNUSED_LIFETIMES,
|
||||||
param_span: param.ident.span,
|
param.id,
|
||||||
use_span: None,
|
param.ident.span,
|
||||||
deletion_span,
|
&format!("lifetime parameter `{}` never used", param.ident),
|
||||||
},
|
lint::BuiltinLintDiagnostics::SingleUseLifetime {
|
||||||
);
|
param_span: param.ident.span,
|
||||||
|
use_span: None,
|
||||||
|
deletion_span,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,12 @@
|
|||||||
|
// check-pass
|
||||||
|
|
||||||
|
#![deny(unused_lifetimes)]
|
||||||
|
trait Trait2 {
|
||||||
|
type As;
|
||||||
|
}
|
||||||
|
|
||||||
|
// we should not warn about an unused lifetime about code generated from this proc macro here
|
||||||
|
#[derive(Clone)]
|
||||||
|
struct ShimMethod4<T: Trait2 + 'static>(pub &'static dyn for<'s> Fn(&'s mut T::As));
|
||||||
|
|
||||||
|
pub fn main() {}
|
Loading…
x
Reference in New Issue
Block a user