]> git.lizzy.rs Git - rust.git/blobdiff - clippy_lints/src/use_self.rs
clippy: support `QPath::LangItem`
[rust.git] / clippy_lints / src / use_self.rs
index f8e1aff33e7731f5e887c6a2fa5958b2b7664076..776c6bc57ca6f857c4d86b699d99a4d5f2351f41 100644 (file)
@@ -57,7 +57,7 @@
 
 const SEGMENTS_MSG: &str = "segments should be composed of at least 1 element";
 
-fn span_use_self_lint(cx: &LateContext<'_, '_>, path: &Path<'_>, last_segment: Option<&PathSegment<'_>>) {
+fn span_use_self_lint(cx: &LateContext<'_>, path: &Path<'_>, last_segment: Option<&PathSegment<'_>>) {
     let last_segment = last_segment.unwrap_or_else(|| path.segments.last().expect(SEGMENTS_MSG));
 
     // Path segments only include actual path, no methods or fields.
@@ -83,7 +83,7 @@ fn span_use_self_lint(cx: &LateContext<'_, '_>, path: &Path<'_>, last_segment: O
 
 // FIXME: always use this (more correct) visitor, not just in method signatures.
 struct SemanticUseSelfVisitor<'a, 'tcx> {
-    cx: &'a LateContext<'a, 'tcx>,
+    cx: &'a LateContext<'tcx>,
     self_ty: Ty<'tcx>,
 }
 
@@ -110,8 +110,8 @@ fn nested_visit_map(&mut self) -> NestedVisitorMap<Self::Map> {
     }
 }
 
-fn check_trait_method_impl_decl<'a, 'tcx>(
-    cx: &'a LateContext<'a, 'tcx>,
+fn check_trait_method_impl_decl<'tcx>(
+    cx: &LateContext<'tcx>,
     impl_item: &ImplItem<'_>,
     impl_decl: &'tcx FnDecl<'_>,
     impl_trait_ref: ty::TraitRef<'tcx>,
@@ -157,8 +157,8 @@ fn check_trait_method_impl_decl<'a, 'tcx>(
     }
 }
 
-impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UseSelf {
-    fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx Item<'_>) {
+impl<'tcx> LateLintPass<'tcx> for UseSelf {
+    fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) {
         if in_external_macro(cx.sess(), item.span) {
             return;
         }
@@ -167,14 +167,11 @@ fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx Item<'_>) {
             if let TyKind::Path(QPath::Resolved(_, ref item_path)) = item_type.kind;
             then {
                 let parameters = &item_path.segments.last().expect(SEGMENTS_MSG).args;
-                let should_check = if let Some(ref params) = *parameters {
-                    !params.parenthesized && !params.args.iter().any(|arg| match arg {
-                        GenericArg::Lifetime(_) => true,
-                        _ => false,
-                    })
-                } else {
-                    true
-                };
+                let should_check = parameters.as_ref().map_or(
+                    true,
+                    |params| !params.parenthesized
+                        &&!params.args.iter().any(|arg| matches!(arg, GenericArg::Lifetime(_)))
+                );
 
                 if should_check {
                     let visitor = &mut UseSelfVisitor {
@@ -211,7 +208,7 @@ fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx Item<'_>) {
 
 struct UseSelfVisitor<'a, 'tcx> {
     item_path: &'a Path<'a>,
-    cx: &'a LateContext<'a, 'tcx>,
+    cx: &'a LateContext<'tcx>,
 }
 
 impl<'a, 'tcx> Visitor<'tcx> for UseSelfVisitor<'a, 'tcx> {