Skip to content

Update Clippy #96735

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 199 commits into from
May 5, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
199 commits
Select commit Hold shift + click to select a range
c70f1e0
ignore `&x | &y` in unnested_or_patterns
pitaj Apr 2, 2022
bca346b
rebase and use ty::Const in patterns again
b-naber Mar 25, 2022
4227411
Generate deprecated lints test
Jarcho Apr 2, 2022
d5ef542
Generate renamed lint test
Jarcho Apr 3, 2022
2f78075
get rid of visit_constant in thir visitor
b-naber Apr 6, 2022
6e20a63
Don't lint `manual_non_exhaustive` when the enum variant is used
Jarcho Apr 6, 2022
b0f8a31
Cleanup `manual_non_exhaustive`
Jarcho Apr 6, 2022
ddd3af2
Only lint `mut_from_ref` when unsafe code is used
Jarcho Apr 6, 2022
d5e887c
Better check size and alignment requirements in `unsound_collection_t…
Jarcho Apr 6, 2022
06cfeb9
New lint `is_digit_ascii_radix`
pitaj Apr 2, 2022
a63308b
Auto merge of #8619 - pitaj:fix-6973, r=giraffate
bors Apr 8, 2022
1905425
Update documentation for `mut_from_ref`
Jarcho Apr 8, 2022
7113135
Merge commit '984330a6ee3c4d15626685d6dc8b7b759ff630bd' into clippyup
flip1995 Apr 7, 2022
da26623
Update Cargo.lock
flip1995 Apr 8, 2022
b79f13e
Avoid looking at the internals of Interned directly
oli-obk Apr 8, 2022
2249168
Refactor HIR item-like traversal (part 1)
kckeiks Apr 3, 2022
3363a62
remove CheckVisitor, CollectExternCrateVisitor and ItemLikeVisitor impls
kckeiks Apr 7, 2022
63f6a79
Don't lint various match lints when expanded by a proc-macro
Jarcho Apr 8, 2022
b029a86
Auto merge of #8648 - Jarcho:transmute_collection_7706, r=xFrednet
bors Apr 8, 2022
0155a63
Auto merge of #95524 - oli-obk:cached_stable_hash_cleanups, r=nnether…
bors Apr 9, 2022
744b0ff
Don't lint `iter_with_drain` on references
Jarcho Apr 9, 2022
a951148
fix comments in test for split_once
kyoto7250 Apr 9, 2022
cfd52aa
Auto merge of #8669 - kyoto7250:fix_comments_in_test_split_once, r=xF…
bors Apr 9, 2022
ffde78b
Allow passing --remove to `cargo dev setup <SUBCOMMAND>`
yoav-lavi Apr 8, 2022
c7e6863
Auto merge of #8664 - yoav-lavi:main, r=xFrednet
bors Apr 9, 2022
1450c98
fix typo
andy-k Apr 9, 2022
719a040
Compare inline constants by their bodies rather than value in `Spanle…
Jarcho Apr 10, 2022
5e335a5
Check for loops/closures in `local_used_after_expr`
Alexendoo Apr 10, 2022
6fba897
Remove overlap between `manual_split_once` and `needless_splitn`
Alexendoo Apr 4, 2022
5344236
Auto merge of #8631 - Alexendoo:splitn-overlap, r=xFrednet
bors Apr 10, 2022
85e91dc
Auto merge of #8671 - andy-k:fix-typo, r=flip1995
bors Apr 11, 2022
a4d1837
unnecessary_string_new
yoav-lavi Apr 7, 2022
1020137
unnecessary_owned_empty_string -> unnecessary_owned_empty_strings
yoav-lavi Apr 11, 2022
5c19ae9
Auto merge of #8660 - yoav-lavi:squashed-master, r=flip1995
bors Apr 11, 2022
62d912e
Add new `Deinit` statement kind
JakobDegen Apr 5, 2022
18ab97d
Auto merge of #8668 - Jarcho:iter_with_drain_8538, r=Manishearth
bors Apr 11, 2022
131ff87
Auto merge of #8673 - Jarcho:same_functions_8139, r=Manishearth
bors Apr 11, 2022
89ee6aa
Auto merge of #8667 - Jarcho:proc_macro_check, r=flip1995
bors Apr 11, 2022
c82dd0f
Fix ICE in `undocumented_unsafe_blocks`
Jarcho Apr 11, 2022
4a21082
Fix subtraction overflow in `cast_possible_truncation`
Alexendoo Apr 11, 2022
636ed84
Auto merge of #8687 - Alexendoo:cast-possible-truncation-overflow, r=…
bors Apr 11, 2022
dbcd828
Auto merge of #8624 - pitaj:is_digit_ascii_radix, r=xFrednet
bors Apr 11, 2022
9716a9e
adding condition for map_clone message
kyoto7250 Apr 11, 2022
40224f4
refactor: Put together an if statement
kyoto7250 Apr 12, 2022
bc069ef
Auto merge of #8688 - kyoto7250:adding_condition_for_map_clone, r=gir…
bors Apr 12, 2022
739f273
Do not apply `rest_pat_in_fully_bound_structs` on `#[non_exhaustive]`…
mucinoab Apr 12, 2022
b3bd03a
Auto merge of #8686 - Jarcho:undocumented_unsafe_blocks_8681, r=flip1995
bors Apr 12, 2022
214fba7
Prevent infinite (exponential) recursion in only_used_in_recursion
flip1995 Apr 12, 2022
f08a9c0
Auto merge of #8691 - flip1995:infinite_recursion_only_in_recursion, …
bors Apr 12, 2022
dfdc5ad
fix unnecessary_to_owned about msrv
kyoto7250 Apr 12, 2022
849668a
Auto merge of #8690 - mucinoab:DoNot-rest_pat_in_fully_bound_structs-…
bors Apr 12, 2022
d8c97e6
Auto merge of #8645 - Jarcho:manual_non_exhaustive_5714, r=Jarcho
bors Apr 12, 2022
06b1695
Auto merge of #8647 - Jarcho:mut_from_ref_6326, r=giraffate
bors Apr 13, 2022
f70c73f
Auto merge of #8692 - kyoto7250:fixing_unnecessary_to_owned, r=giraffate
bors Apr 13, 2022
5b7df24
errors: lazily load fallback fluent bundle
davidtwco Apr 12, 2022
27634b0
Auto merge of #94255 - b-naber:use-mir-constant-in-thir, r=oli-obk
bors Apr 13, 2022
66d253f
pub_use
yoav-lavi Apr 12, 2022
b6645d0
Auto merge of #8670 - yoav-lavi:main, r=giraffate
bors Apr 13, 2022
ba15cdd
Add `usize` cast to `clippy::manual_bits` suggestion
xFrednet Apr 10, 2022
a377ebc
Auto merge of #95968 - davidtwco:translation-lazy-fallback, r=oli-obk
bors Apr 13, 2022
38ba055
Auto merge of #8676 - Alexendoo:local-used-across-loop, r=xFrednet
bors Apr 14, 2022
9f131e5
assertions_on_constants: ignore indirect `cfg!`
pitaj Apr 1, 2022
67badbe
New lint `format_add_strings`
pitaj Apr 4, 2022
3bd0ac7
Update lint description of `clippy::manual_bits` to include the `as …
xFrednet Apr 14, 2022
262b35e
Introduce option_take_on_temporary lints
b-NC Apr 8, 2022
ee9281d
Implement checks to the expression
b-NC Apr 8, 2022
f8f1441
Swap span_lint for span_lint_and_sugg
b-NC Apr 8, 2022
cf83e18
Swap the category of the lint
b-NC Apr 8, 2022
8b2b343
Delete unused variable `y` in test
b-NC Apr 9, 2022
b52bc9b
Swap type checked expression
b-NC Apr 10, 2022
76268c0
Introduce new lint check
b-NC Apr 10, 2022
8229936
Modify lint description
b-NC Apr 11, 2022
2903b56
Add tests and docs
b-NC Apr 12, 2022
ecb3c3f
Auto merge of #8677 - xFrednet:8213-manual-bits-suggestion, r=giraffate
bors Apr 14, 2022
aade96f
Auto merge of #8626 - pitaj:format_add_string, r=llogiq
bors Apr 14, 2022
0de314b
Reimplement lowering of sym operands for asm! so that it also works w…
Amanieu Mar 1, 2022
dc97080
Update issue-92893.stderr
ouz-a Apr 14, 2022
80bcd9b
Auto merge of #8614 - pitaj:fix-7597, r=giraffate
bors Apr 14, 2022
d68ac9c
Don't lint `let_unit_value` when needed for type inferenece
Jarcho Mar 17, 2022
48bcc1d
Move `let_unit_value` back into `style`
Jarcho Mar 17, 2022
70f7c62
Allow more complex expressions in `let_unit_value`
Jarcho Apr 5, 2022
0bc93b6
Auto merge of #8563 - Jarcho:let_unit_1502, r=Jarcho
bors Apr 15, 2022
b592cc6
Fix typo in comment
youknowone Apr 15, 2022
c0fce5a
Auto merge of #8702 - youknowone:fix-typo, r=xFrednet
bors Apr 15, 2022
6f82524
clippy: Update full path to `CString`
petrochenkov Apr 15, 2022
3d5dc41
Rollup merge of #94849 - ouz-a:master4, r=oli-obk
Dylan-DPC Apr 15, 2022
d1a78f3
Fix formatting of `cast_abs_to_unsigned` docs
lupd Apr 15, 2022
29ef80c
adding spell checking
Apr 15, 2022
fb1934b
infallible <> infalliable in filename
Apr 15, 2022
2be7ad5
initialization misspell
Apr 15, 2022
73b7cb9
shound -> should
Apr 15, 2022
e475dde
collapsible <> collspible
Apr 15, 2022
9938daf
Auto merge of #8705 - cpw2n5:spellcheck, r=Manishearth
bors Apr 15, 2022
4844325
Add `await_holding_invalid_type` lint
lilymara-onesignal Apr 14, 2022
3cd8b5a
fixup! Add `await_holding_invalid_type` lint
lilymara-onesignal Apr 15, 2022
5344192
fixup! Add `await_holding_invalid_type` lint
lilymara-onesignal Apr 15, 2022
5b35bd9
lintcheck: fix --fix
matthiaskrgr Apr 15, 2022
5cf2920
Auto merge of #94468 - Amanieu:global_asm_sym, r=nagisa
bors Apr 16, 2022
af72103
Changelog for Rust 1.61 :octopus:
xFrednet Apr 13, 2022
3abd2c0
Auto merge of #8698 - xFrednet:0000-changelog-1-61, r=flip1995
bors Apr 16, 2022
b2959db
Auto merge of #8706 - lupd:cast-abs-to-unsigned, r=xFrednet
bors Apr 16, 2022
0f4f9ec
Auto merge of #8709 - matthiaskrgr:lintcheckfix, r=llogiq
bors Apr 16, 2022
cc25cbd
Auto merge of #95655 - kckeiks:create-hir-crate-items-query, r=cjgillot
bors Apr 17, 2022
e4110cf
Bless clippy.
cjgillot Apr 1, 2022
18a4411
Stop using CRATE_DEF_INDEX.
cjgillot Apr 15, 2022
cb1924a
Auto merge of #95779 - cjgillot:ast-lifetimes-undeclared, r=petrochenkov
bors Apr 17, 2022
e5ebece
Auto merge of #8665 - InfRandomness:option_take_on_temporary, r=llogiq
bors Apr 17, 2022
ccedc64
Add `#[clippy::print_hir]` attribute for debugging
xFrednet Apr 15, 2022
b94e24e
Fix needless_match false positive for if-let
youknowone Apr 15, 2022
7a4d071
Less authoritative stable_sort_primitive message
Apr 18, 2022
7a73e09
Update lints
Apr 18, 2022
95de4dc
Auto merge of #8701 - xFrednet:0000-clippy-print-hir-attr, r=flip1995
bors Apr 18, 2022
6d0baf2
Update clippy_lints/src/await_holding_invalid.rs
lilymara-onesignal Apr 18, 2022
228ce78
Update clippy_lints/src/await_holding_invalid.rs
lilymara-onesignal Apr 18, 2022
ee3ebb3
Update clippy_lints/src/await_holding_invalid.rs
lilymara-onesignal Apr 18, 2022
a511072
fixup! Add `await_holding_invalid_type` lint
lilymara-onesignal Apr 18, 2022
7e26edc
fixup! Add `await_holding_invalid_type` lint
lilymara-onesignal Apr 18, 2022
8eccbbe
fixup! Add `await_holding_invalid_type` lint
lilymara-onesignal Apr 18, 2022
0508685
fixup! Add `await_holding_invalid_type` lint
lilymara-onesignal Apr 18, 2022
cbdf17c
Auto merge of #8707 - OneSignal:await-invalid-types, r=llogiq
bors Apr 18, 2022
df1ec91
adds lint logic and test for bytes_count_to_len
chaseruskin Jan 31, 2022
f19387d
add checking type
kyoto7250 Apr 16, 2022
c922bb9
fix ICE
asquared31415 Apr 19, 2022
60bb2a7
Rollup merge of #96142 - cjgillot:no-crate-def-index, r=petrochenkov
Dylan-DPC Apr 19, 2022
e17b97c
Auto merge of #8711 - kyoto7250:new-lint-bytes-count-to-len, r=giraffate
bors Apr 19, 2022
1b6b802
Better documentation wording and add known problems section
Apr 20, 2022
f99ad82
Auto merge of #8700 - youknowone:needless_match-false-positive, r=xFr…
bors Apr 20, 2022
4c25880
Auto merge of #8716 - binggh:stable-sort-message-update, r=giraffate
bors Apr 21, 2022
8de3fb1
Add empty_drop lint
PyroTechniac Mar 25, 2022
a9d31e7
Auto merge of #8571 - PyroTechniac:empty-drop, r=flip1995
bors Apr 21, 2022
4424aa4
`manual_split_once`: lint manual iteration of `SplitN`
Alexendoo Apr 18, 2022
14667d1
Fix missing whitespace in `collapsible_else_if` suggestion
Serial-ATA Apr 21, 2022
cf68cad
Auto merge of #8729 - Serial-ATA:issue-7318, r=Manishearth
bors Apr 21, 2022
ed22428
Auto merge of #8717 - Alexendoo:manual-split-once-manual-iter, r=dswi…
bors Apr 22, 2022
a96bc7a
dogfood: allow unknown lints when not running with `internal` feature
Alexendoo Apr 22, 2022
cef882c
Auto merge of #8731 - Alexendoo:dogfood-allow-unknown-lints, r=xFrednet
bors Apr 22, 2022
f20e890
Add macro export exemption to `redundant_pub_crate`
Serial-ATA Apr 22, 2022
b35c04f
Extend `extra_unused_lifetimes` to handle impl lifetimes
smoelius Apr 23, 2022
fabc26f
Stop visiting visibility.
cjgillot Feb 13, 2022
abc8eb7
Drop vis in FieldDef.
cjgillot Feb 13, 2022
6ec33df
Drop vis in ImplItem.
cjgillot Feb 13, 2022
04024ba
Drop vis in Item.
cjgillot Feb 13, 2022
0c164bb
ignore `redundant_pub_crate` in `useless_attribute`
Alexendoo Apr 23, 2022
51db157
fix
tamaroning Apr 23, 2022
af9dfa3
fix ICE by using a type to return the info we want and also fix some …
asquared31415 Apr 23, 2022
ec3afba
Make clippy inspector more precise.
cjgillot Feb 14, 2022
2a5ee68
Auto merge of #8736 - Serial-ATA:issue-8732, r=xFrednet
bors Apr 24, 2022
6aa3684
Auto merge of #8738 - tamaroning:fix_wrong_self_convention, r=xFrednet
bors Apr 24, 2022
b3de32b
Add `rename_lint` command
Jarcho Apr 4, 2022
f290249
mistyped_literal_suffixes: improve suggestions for integer types
liquid-dragons Apr 23, 2022
b4a50e9
mistyped_literal_suffixes: ignore floats without exponent
liquid-dragons Apr 24, 2022
a85dc87
Add `large_include_file` lint
Serial-ATA Apr 21, 2022
388e6b7
Auto merge of #8742 - goth-turtle:mistyped-literal-suffix, r=llogiq
bors Apr 24, 2022
cf99f50
remove extra lifetime
asquared31415 Apr 24, 2022
e6fa163
Fix false positives
smoelius Apr 25, 2022
c22bb06
Fix naming
smoelius Apr 25, 2022
760f293
Auto merge of #8727 - Serial-ATA:lint-large-includes, r=xFrednet
bors Apr 25, 2022
94623ee
Auto merge of #8737 - smoelius:extra-impl-lifetimes, r=giraffate
bors Apr 26, 2022
1d1fecf
`needless_late_init`: ignore `if let`, `let mut` and significant drops
Alexendoo Apr 1, 2022
95396f6
Auto merge of #8617 - Alexendoo:relax-needless-late-init, r=giraffate
bors Apr 27, 2022
33bf9e9
`redundant_closure` ignore coerced closure
dswij Feb 23, 2022
18a1831
Auto merge of #8743 - Alexendoo:useless-attribute-redundant-pub-crate…
bors Apr 27, 2022
d5c62fd
Auto merge of #8431 - dswij:8416, r=xFrednet
bors Apr 27, 2022
5ffe8a1
errors: `span_suggestion` takes `impl ToString`
davidtwco Apr 26, 2022
8f8fc9f
use non-panicking snippet, use struct update syntax and add comment
asquared31415 Apr 29, 2022
8ef4b8d
Update GitHub Actions actions/checkout@v2 to v3
dtolnay Apr 30, 2022
faadd8f
Box HIR Generics and Impl.
cjgillot Feb 5, 2022
67241bb
Inline WhereClause into Generics.
cjgillot Feb 5, 2022
e2d923a
Store all generic bounds as where predicates.
cjgillot Feb 7, 2022
e46c782
Bless tests.
cjgillot Mar 14, 2022
c80cd4d
Auto merge of #8764 - dtolnay-contrib:checkoutv3, r=llogiq
bors Apr 30, 2022
ec46992
Auto merge of #8720 - asquared31415:ptr-cast-ice-fix, r=Alexendoo,xFr…
bors Apr 30, 2022
959ed52
Add missing quite in `large_include_file` example
xFrednet Apr 30, 2022
32fe476
Auto merge of #8625 - Jarcho:rename_lint, r=xFrednet
bors Apr 30, 2022
95f8b26
Auto merge of #8767 - xFrednet:8765-fix-doc-example, r=camsteffen
bors Apr 30, 2022
defc537
Fix the clippy build
scottmcm Apr 25, 2022
6ad810f
improve identity_op
tamaroning Apr 22, 2022
8172166
rustc: Panic by default in `DefIdTree::parent`
petrochenkov Apr 25, 2022
0ceacbe
Auto merge of #8730 - tamaroning:fix8724, r=Alexendoo
bors May 3, 2022
3476056
Make rustc_parse_format compile on stable
bjorn3 Apr 29, 2022
f505cc9
Easier readability for needless_late_init
May 3, 2022
7017eb1
cargo dev bless
May 3, 2022
d53293d
Ignore type aliases in `init_numbered_fields`
Alexendoo May 3, 2022
1834f32
Move only_used_in_recursion to nursery
flip1995 May 3, 2022
38b7a04
Auto merge of #8783 - flip1995:ouir-nursery, r=llogiq
bors May 3, 2022
8be86fc
Auto merge of #96558 - bjorn3:librarify_parse_format, r=davidtwco
bors May 3, 2022
a10fe90
Auto merge of #8779 - binggh:easier-needless-late-init, r=llogiq
bors May 3, 2022
fea177f
add trim_split_whitespace
FoseFx Mar 22, 2022
751fd0d
Auto merge of #8780 - Alexendoo:init-numbered-field-alias, r=flip1995
bors May 4, 2022
c7a705a
Auto merge of #8575 - FoseFx:trim_split_whitespace2, r=flip1995
bors May 4, 2022
c318cf4
Overhaul `MacArgs::Eq`.
nnethercote Apr 28, 2022
82f469f
Auto merge of #96546 - nnethercote:overhaul-MacArgs, r=petrochenkov
bors May 4, 2022
3b0c78d
Merge remote-tracking branch 'upstream/master' into rustup
flip1995 May 5, 2022
7e017db
Bump nightly version -> 2022-05-05
flip1995 May 5, 2022
bb01aca
HACK: Move buggy lints to nursery
flip1995 May 5, 2022
0062829
Fix ICE in EarlyAttribtues lints
flip1995 May 5, 2022
7c21f91
Auto merge of #8788 - flip1995:rustup, r=xFrednet,flip1995
bors May 5, 2022
4963845
Merge commit '7c21f91b15b7604f818565646b686d90f99d1baf' into clippyup
flip1995 May 5, 2022
463c760
Update Cargo.lock
flip1995 May 5, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Extend extra_unused_lifetimes to handle impl lifetimes
  • Loading branch information
smoelius committed Apr 23, 2022
commit b35c04f7dc8febef216b17209d030bd239c19f2c
65 changes: 58 additions & 7 deletions clippy_lints/src/lifetimes.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
use clippy_utils::diagnostics::span_lint;
use clippy_utils::trait_ref_of_method;
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_hir::intravisit::nested_filter::{self as hir_nested_filter, NestedFilter};
use rustc_hir::intravisit::{
walk_fn_decl, walk_generic_param, walk_generics, walk_item, walk_param_bound, walk_poly_trait_ref, walk_ty, Visitor,
walk_fn_decl, walk_generic_param, walk_generics, walk_impl_item_ref, walk_item, walk_param_bound,
walk_poly_trait_ref, walk_trait_ref, walk_ty, Visitor,
};
use rustc_hir::FnRetTy::Return;
use rustc_hir::{
BareFnTy, BodyId, FnDecl, GenericArg, GenericBound, GenericParam, GenericParamKind, Generics, ImplItem,
BareFnTy, BodyId, FnDecl, GenericArg, GenericBound, GenericParam, GenericParamKind, Generics, Impl, ImplItem,
ImplItemKind, Item, ItemKind, LangItem, Lifetime, LifetimeName, ParamName, PolyTraitRef, TraitBoundModifier,
TraitFn, TraitItem, TraitItemKind, Ty, TyKind, WhereClause, WherePredicate,
};
use rustc_lint::{LateContext, LateLintPass};
use rustc_middle::hir::nested_filter as mir_nested_filter;
use rustc_session::{declare_lint_pass, declare_tool_lint};
use rustc_span::source_map::Span;
use rustc_span::symbol::{kw, Ident, Symbol};
Expand Down Expand Up @@ -84,6 +87,8 @@ impl<'tcx> LateLintPass<'tcx> for Lifetimes {
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) {
if let ItemKind::Fn(ref sig, ref generics, id) = item.kind {
check_fn_inner(cx, sig.decl, Some(id), None, generics, item.span, true);
} else if let ItemKind::Impl(ref impl_) = item.kind {
report_extra_impl_lifetimes(cx, impl_);
}
}

Expand Down Expand Up @@ -194,8 +199,7 @@ fn explicit_self_type<'tcx>(cx: &LateContext<'tcx>, func: &FnDecl<'tcx>, ident:
visitor.visit_ty(self_ty);

!visitor.all_lts().is_empty()
}
else {
} else {
false
}
}
Expand Down Expand Up @@ -481,11 +485,29 @@ fn has_where_lifetimes<'tcx>(cx: &LateContext<'tcx>, where_clause: &'tcx WhereCl
false
}

struct LifetimeChecker {
struct LifetimeChecker<'cx, 'tcx, F> {
cx: &'cx LateContext<'tcx>,
map: FxHashMap<Symbol, Span>,
phantom: std::marker::PhantomData<F>,
}

impl<'tcx> Visitor<'tcx> for LifetimeChecker {
impl<'cx, 'tcx, F> LifetimeChecker<'cx, 'tcx, F> {
fn new(cx: &'cx LateContext<'tcx>, map: FxHashMap<Symbol, Span>) -> LifetimeChecker<'cx, 'tcx, F> {
Self {
cx,
map,
phantom: std::marker::PhantomData,
}
}
}

impl<'cx, 'tcx, F> Visitor<'tcx> for LifetimeChecker<'cx, 'tcx, F>
where
F: NestedFilter<'tcx>,
{
type Map = rustc_middle::hir::map::Map<'tcx>;
type NestedFilter = F;

// for lifetimes as parameters of generics
fn visit_lifetime(&mut self, lifetime: &'tcx Lifetime) {
self.map.remove(&lifetime.name.ident().name);
Expand All @@ -501,6 +523,10 @@ impl<'tcx> Visitor<'tcx> for LifetimeChecker {
walk_generic_param(self, param);
}
}

fn nested_visit_map(&mut self) -> Self::Map {
self.cx.tcx.hir()
}
}

fn report_extra_lifetimes<'tcx>(cx: &LateContext<'tcx>, func: &'tcx FnDecl<'_>, generics: &'tcx Generics<'_>) {
Expand All @@ -512,7 +538,7 @@ fn report_extra_lifetimes<'tcx>(cx: &LateContext<'tcx>, func: &'tcx FnDecl<'_>,
_ => None,
})
.collect();
let mut checker = LifetimeChecker { map: hs };
let mut checker = LifetimeChecker::<hir_nested_filter::None>::new(cx, hs);

walk_generics(&mut checker, generics);
walk_fn_decl(&mut checker, func);
Expand All @@ -527,6 +553,31 @@ fn report_extra_lifetimes<'tcx>(cx: &LateContext<'tcx>, func: &'tcx FnDecl<'_>,
}
}

fn report_extra_impl_lifetimes<'tcx>(cx: &LateContext<'tcx>, impl_: &'tcx Impl<'_>) {
let hs = impl_
.generics
.params
.iter()
.filter_map(|par| match par.kind {
GenericParamKind::Lifetime { .. } => Some((par.name.ident().name, par.span)),
_ => None,
})
.collect();
let mut checker = LifetimeChecker::<mir_nested_filter::All>::new(cx, hs);

if let Some(ref trait_ref) = impl_.of_trait {
walk_trait_ref(&mut checker, trait_ref);
}
walk_ty(&mut checker, impl_.self_ty);
for item in impl_.items {
walk_impl_item_ref(&mut checker, item);
}

for &v in checker.map.values() {
span_lint(cx, EXTRA_UNUSED_LIFETIMES, v, "this lifetime isn't used in the impl");
}
}

struct BodyLifetimeChecker {
lifetimes_used_in_body: bool,
}
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/crashes/ice-2865.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#[allow(dead_code)]
#![allow(dead_code, clippy::extra_unused_lifetimes)]

/// Test for https://github.com/rust-lang/rust-clippy/issues/2865

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/crashes/ice-3151.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/// Test for https://github.com/rust-lang/rust-clippy/issues/2865
/// Test for https://github.com/rust-lang/rust-clippy/issues/3151

#[derive(Clone)]
pub struct HashMap<V, S> {
Expand Down
16 changes: 16 additions & 0 deletions tests/ui/extra_unused_lifetimes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,20 @@ mod issue4291 {
}
}

mod issue6437 {
pub struct Scalar;

impl<'a> std::ops::AddAssign<&Scalar> for &mut Scalar {
fn add_assign(&mut self, _rhs: &Scalar) {
unimplemented!();
}
}

impl<'b> Scalar {
pub fn something<'c>() -> Self {
Self
}
}
}

fn main() {}
20 changes: 19 additions & 1 deletion tests/ui/extra_unused_lifetimes.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,23 @@ error: this lifetime isn't used in the function definition
LL | fn unused_lt<'a>(x: u8) {}
| ^^

error: aborting due to 4 previous errors
error: this lifetime isn't used in the impl
--> $DIR/extra_unused_lifetimes.rs:78:10
|
LL | impl<'a> std::ops::AddAssign<&Scalar> for &mut Scalar {
| ^^

error: this lifetime isn't used in the impl
--> $DIR/extra_unused_lifetimes.rs:84:10
|
LL | impl<'b> Scalar {
| ^^

error: this lifetime isn't used in the function definition
--> $DIR/extra_unused_lifetimes.rs:85:26
|
LL | pub fn something<'c>() -> Self {
| ^^

error: aborting due to 7 previous errors

2 changes: 1 addition & 1 deletion tests/ui/impl.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![allow(dead_code)]
#![allow(dead_code, clippy::extra_unused_lifetimes)]
#![warn(clippy::multiple_inherent_impl)]

struct MyStruct;
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/new_without_default.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![allow(dead_code, clippy::missing_safety_doc)]
#![allow(dead_code, clippy::missing_safety_doc, clippy::extra_unused_lifetimes)]
#![warn(clippy::new_without_default)]

pub struct Foo;
Expand Down