|
7 | 7 | // option. This file may not be copied, modified, or distributed
|
8 | 8 | // except according to those terms.
|
9 | 9 |
|
10 |
| - |
11 | 10 | //! checks for attributes
|
12 | 11 |
|
13 | 12 | use crate::reexport::*;
|
14 |
| -use crate::utils::{ |
15 |
| - in_macro, last_line_of_span, match_def_path, opt_def_id, paths, snippet_opt, span_lint, span_lint_and_sugg, |
16 |
| - span_lint_and_then, without_block_comments, |
17 |
| -}; |
18 |
| -use if_chain::if_chain; |
19 | 13 | use crate::rustc::hir::*;
|
20 | 14 | use crate::rustc::lint::{
|
21 | 15 | CheckLintNameResult, EarlyContext, EarlyLintPass, LateContext, LateLintPass, LintArray, LintContext, LintPass,
|
22 | 16 | };
|
23 | 17 | use crate::rustc::ty::{self, TyCtxt};
|
24 | 18 | use crate::rustc::{declare_tool_lint, lint_array};
|
25 |
| -use semver::Version; |
26 |
| -use crate::syntax::ast::{ |
27 |
| - AttrStyle, Attribute, Lit, LitKind, MetaItemKind, NestedMetaItem, NestedMetaItemKind, |
28 |
| -}; |
29 |
| -use crate::syntax::source_map::Span; |
30 | 19 | use crate::rustc_errors::Applicability;
|
| 20 | +use crate::syntax::ast::{AttrStyle, Attribute, Lit, LitKind, MetaItemKind, NestedMetaItem, NestedMetaItemKind}; |
| 21 | +use crate::syntax::source_map::Span; |
| 22 | +use crate::utils::{ |
| 23 | + in_macro, last_line_of_span, match_def_path, opt_def_id, paths, snippet_opt, span_lint, span_lint_and_sugg, |
| 24 | + span_lint_and_then, without_block_comments, |
| 25 | +}; |
| 26 | +use if_chain::if_chain; |
| 27 | +use semver::Version; |
31 | 28 |
|
32 | 29 | /// **What it does:** Checks for items annotated with `#[inline(always)]`,
|
33 | 30 | /// unless the annotated function is empty or simply panics.
|
@@ -219,8 +216,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AttrPass {
|
219 | 216 | match &*attr.name().as_str() {
|
220 | 217 | "allow" | "warn" | "deny" | "forbid" => {
|
221 | 218 | check_clippy_lint_names(cx, items);
|
222 |
| - } |
223 |
| - _ => {} |
| 219 | + }, |
| 220 | + _ => {}, |
224 | 221 | }
|
225 | 222 | if items.is_empty() || attr.name() != "deprecated" {
|
226 | 223 | return;
|
@@ -254,19 +251,19 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AttrPass {
|
254 | 251 | // and `unused_imports` for `extern crate` items with `macro_use`
|
255 | 252 | for lint in lint_list {
|
256 | 253 | match item.node {
|
257 |
| - ItemKind::Use(..) => if is_word(lint, "unused_imports") |
258 |
| - || is_word(lint, "deprecated") { |
259 |
| - return |
| 254 | + ItemKind::Use(..) => { |
| 255 | + if is_word(lint, "unused_imports") || is_word(lint, "deprecated") { |
| 256 | + return; |
| 257 | + } |
260 | 258 | },
|
261 | 259 | ItemKind::ExternCrate(..) => {
|
262 |
| - if is_word(lint, "unused_imports") |
263 |
| - && skip_unused_imports { |
264 |
| - return |
| 260 | + if is_word(lint, "unused_imports") && skip_unused_imports { |
| 261 | + return; |
265 | 262 | }
|
266 | 263 | if is_word(lint, "unused_extern_crates") {
|
267 |
| - return |
| 264 | + return; |
268 | 265 | }
|
269 |
| - } |
| 266 | + }, |
270 | 267 | _ => {},
|
271 | 268 | }
|
272 | 269 | }
|
@@ -396,14 +393,16 @@ fn is_relevant_expr(tcx: TyCtxt<'_, '_, '_>, tables: &ty::TypeckTables<'_>, expr
|
396 | 393 | ExprKind::Block(ref block, _) => is_relevant_block(tcx, tables, block),
|
397 | 394 | ExprKind::Ret(Some(ref e)) => is_relevant_expr(tcx, tables, e),
|
398 | 395 | ExprKind::Ret(None) | ExprKind::Break(_, None) => false,
|
399 |
| - ExprKind::Call(ref path_expr, _) => if let ExprKind::Path(ref qpath) = path_expr.node { |
400 |
| - if let Some(fun_id) = opt_def_id(tables.qpath_def(qpath, path_expr.hir_id)) { |
401 |
| - !match_def_path(tcx, fun_id, &paths::BEGIN_PANIC) |
| 396 | + ExprKind::Call(ref path_expr, _) => { |
| 397 | + if let ExprKind::Path(ref qpath) = path_expr.node { |
| 398 | + if let Some(fun_id) = opt_def_id(tables.qpath_def(qpath, path_expr.hir_id)) { |
| 399 | + !match_def_path(tcx, fun_id, &paths::BEGIN_PANIC) |
| 400 | + } else { |
| 401 | + true |
| 402 | + } |
402 | 403 | } else {
|
403 | 404 | true
|
404 | 405 | }
|
405 |
| - } else { |
406 |
| - true |
407 | 406 | },
|
408 | 407 | _ => true,
|
409 | 408 | }
|
@@ -435,7 +434,8 @@ fn check_attrs(cx: &LateContext<'_, '_>, span: Span, name: Name, attrs: &[Attrib
|
435 | 434 | cx,
|
436 | 435 | EMPTY_LINE_AFTER_OUTER_ATTR,
|
437 | 436 | begin_of_attr_to_item,
|
438 |
| - "Found an empty line after an outer attribute. Perhaps you forgot to add a '!' to make it an inner attribute?" |
| 437 | + "Found an empty line after an outer attribute. \ |
| 438 | + Perhaps you forgot to add a '!' to make it an inner attribute?", |
439 | 439 | );
|
440 | 440 | }
|
441 | 441 | }
|
@@ -501,9 +501,7 @@ pub struct CfgAttrPass;
|
501 | 501 |
|
502 | 502 | impl LintPass for CfgAttrPass {
|
503 | 503 | fn get_lints(&self) -> LintArray {
|
504 |
| - lint_array!( |
505 |
| - DEPRECATED_CFG_ATTR, |
506 |
| - ) |
| 504 | + lint_array!(DEPRECATED_CFG_ATTR,) |
507 | 505 | }
|
508 | 506 | }
|
509 | 507 |
|
|
0 commit comments