]> git.lizzy.rs Git - rust.git/blobdiff - clippy_lints/src/attrs.rs
Auto merge of #4551 - mikerite:fix-ice-reporting, r=llogiq
[rust.git] / clippy_lints / src / attrs.rs
index 36fc4b94385f9363c2d81597998fb3664f96f2e9..a4b411d751998ec3f897373929ee52190d40c9f5 100644 (file)
@@ -2,8 +2,8 @@
 
 use crate::reexport::*;
 use crate::utils::{
-    in_macro_or_desugar, is_present_in_source, last_line_of_span, match_def_path, paths, snippet_opt, span_lint,
-    span_lint_and_sugg, span_lint_and_then, without_block_comments,
+    is_present_in_source, last_line_of_span, match_def_path, paths, snippet_opt, span_lint, span_lint_and_sugg,
+    span_lint_and_then, without_block_comments,
 };
 use if_chain::if_chain;
 use rustc::hir::*;
@@ -49,9 +49,9 @@
     /// **What it does:** Checks for `extern crate` and `use` items annotated with
     /// lint attributes.
     ///
-    /// This lint whitelists `#[allow(unused_imports)]` and `#[allow(deprecated)]` on
-    /// `use` items and `#[allow(unused_imports)]` on `extern crate` items with a
-    /// `#[macro_use]` attribute.
+    /// This lint whitelists `#[allow(unused_imports)]`, `#[allow(deprecated)]` and
+    /// `#[allow(unreachable_pub)]` on `use` items and `#[allow(unused_imports)]` on
+    /// `extern crate` items with a `#[macro_use]` attribute.
     ///
     /// **Why is this bad?** Lint attributes have no effect on crate imports. Most
     /// likely a `!` was forgotten.
     ///
     /// **Example:**
     /// ```rust
-    /// // Bad
-    /// #[inline(always)]
-    ///
-    /// fn not_quite_good_code(..) { ... }
-    ///
     /// // Good (as inner attribute)
     /// #![inline(always)]
     ///
-    /// fn this_is_fine(..) { ... }
+    /// fn this_is_fine() { }
+    ///
+    /// // Bad
+    /// #[inline(always)]
+    ///
+    /// fn not_quite_good_code() { }
     ///
     /// // Good (as outer attribute)
     /// #[inline(always)]
-    /// fn this_is_fine_too(..) { ... }
+    /// fn this_is_fine_too() { }
     /// ```
     pub EMPTY_LINE_AFTER_OUTER_ATTR,
     nursery,
 
 declare_clippy_lint! {
     /// **What it does:** Checks for `allow`/`warn`/`deny`/`forbid` attributes with scoped clippy
-    /// lints and if those lints exist in clippy. If there is a uppercase letter in the lint name
+    /// lints and if those lints exist in clippy. If there is an uppercase letter in the lint name
     /// (not the tool name) and a lowercase version of this lint exists, it will suggest to lowercase
     /// the lint name.
     ///
@@ -239,13 +239,14 @@ fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx Item) {
                         if let Some(ident) = attr.ident() {
                             match &*ident.as_str() {
                                 "allow" | "warn" | "deny" | "forbid" => {
-                                    // whitelist `unused_imports` and `deprecated` for `use` items
+                                    // whitelist `unused_imports`, `deprecated` and `unreachable_pub` for `use` items
                                     // and `unused_imports` for `extern crate` items with `macro_use`
                                     for lint in lint_list {
                                         match item.node {
                                             ItemKind::Use(..) => {
                                                 if is_word(lint, sym!(unused_imports))
                                                     || is_word(lint, sym!(deprecated))
+                                                    || is_word(lint, sym!(unreachable_pub))
                                                 {
                                                     return;
                                                 }
@@ -276,7 +277,7 @@ fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx Item) {
                                                         line_span,
                                                         "if you just forgot a `!`, use",
                                                         sugg,
-                                                        Applicability::MachineApplicable,
+                                                        Applicability::MaybeIncorrect,
                                                     );
                                                 },
                                             );
@@ -318,7 +319,7 @@ fn check_clippy_lint_names(cx: &LateContext<'_, '_>, items: &[NestedMetaItem]) {
             let name = meta_item.path.segments.last().unwrap().ident.name;
             if let CheckLintNameResult::Tool(Err((None, _))) = lint_store.check_lint_name(
                 &name.as_str(),
-                Some(tool_name.as_str()),
+                Some(tool_name.name),
             );
             then {
                 span_lint_and_then(
@@ -331,7 +332,7 @@ fn check_clippy_lint_names(cx: &LateContext<'_, '_>, items: &[NestedMetaItem]) {
                             let name_lower = name.as_str().to_lowercase();
                             match lint_store.check_lint_name(
                                 &name_lower,
-                                Some(tool_name.as_str())
+                                Some(tool_name.name)
                             ) {
                                 // FIXME: can we suggest similar lint names here?
                                 // https://github.com/rust-lang/rust/pull/56992
@@ -411,7 +412,7 @@ fn is_relevant_expr(cx: &LateContext<'_, '_>, tables: &ty::TypeckTables<'_>, exp
 }
 
 fn check_attrs(cx: &LateContext<'_, '_>, span: Span, name: Name, attrs: &[Attribute]) {
-    if in_macro_or_desugar(span) {
+    if span.from_expansion() {
         return;
     }