]> git.lizzy.rs Git - rust.git/blobdiff - clippy_lints/src/main_recursion.rs
Merge remote-tracking branch 'upstream/master' into rustup
[rust.git] / clippy_lints / src / main_recursion.rs
index 0513eb8ac9e50233b71ef9c47a57b92f84a23c4c..1ed3f3de839085d3e73510edc49921738d6ec003 100644 (file)
@@ -1,10 +1,8 @@
-use rustc::lint::{LateContext, LateLintPass};
 use rustc_hir::{Crate, Expr, ExprKind, QPath};
+use rustc_lint::{LateContext, LateLintPass};
 use rustc_session::{declare_tool_lint, impl_lint_pass};
-use rustc_span::symbol::sym;
-use syntax::ast::AttrKind;
 
-use crate::utils::{is_entrypoint_fn, snippet, span_help_and_lint};
+use crate::utils::{is_entrypoint_fn, is_no_std_crate, snippet, span_lint_and_help};
 use if_chain::if_chain;
 
 declare_clippy_lint! {
@@ -33,34 +31,28 @@ pub struct MainRecursion {
 
 impl_lint_pass!(MainRecursion => [MAIN_RECURSION]);
 
-impl LateLintPass<'_, '_> for MainRecursion {
-    fn check_crate(&mut self, _: &LateContext<'_, '_>, krate: &Crate<'_>) {
-        self.has_no_std_attr = krate.attrs.iter().any(|attr| {
-            if let AttrKind::Normal(ref attr) = attr.kind {
-                attr.path == sym::no_std
-            } else {
-                false
-            }
-        });
+impl LateLintPass<'_> for MainRecursion {
+    fn check_crate(&mut self, _: &LateContext<'_>, krate: &Crate<'_>) {
+        self.has_no_std_attr = is_no_std_crate(krate);
     }
 
-    fn check_expr_post(&mut self, cx: &LateContext<'_, '_>, expr: &Expr<'_>) {
+    fn check_expr_post(&mut self, cx: &LateContext<'_>, expr: &Expr<'_>) {
         if self.has_no_std_attr {
             return;
         }
 
         if_chain! {
             if let ExprKind::Call(func, _) = &expr.kind;
-            if let ExprKind::Path(path) = &func.kind;
-            if let QPath::Resolved(_, path) = &path;
+            if let ExprKind::Path(QPath::Resolved(_, path)) = &func.kind;
             if let Some(def_id) = path.res.opt_def_id();
             if is_entrypoint_fn(cx, def_id);
             then {
-                span_help_and_lint(
+                span_lint_and_help(
                     cx,
                     MAIN_RECURSION,
                     func.span,
                     &format!("recursing into entrypoint `{}`", snippet(cx, func.span, "main")),
+                    None,
                     "consider using another function for this recursion"
                 )
             }