1010//! checks for attributes
1111
1212use crate :: reexport:: * ;
13- use crate :: rustc:: hir:: * ;
14- use crate :: rustc:: lint:: {
15- CheckLintNameResult , EarlyContext , EarlyLintPass , LateContext , LateLintPass , LintArray , LintContext , LintPass ,
16- } ;
17- use crate :: rustc:: ty:: { self , TyCtxt } ;
18- use crate :: rustc:: { declare_tool_lint, lint_array} ;
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 ;
2213use crate :: utils:: {
2314 in_macro, last_line_of_span, match_def_path, opt_def_id, paths, snippet_opt, span_lint, span_lint_and_sugg,
2415 span_lint_and_then, without_block_comments,
2516} ;
2617use if_chain:: if_chain;
18+ use rustc:: hir:: * ;
19+ use rustc:: lint:: {
20+ CheckLintNameResult , EarlyContext , EarlyLintPass , LateContext , LateLintPass , LintArray , LintContext , LintPass ,
21+ } ;
22+ use rustc:: ty:: { self , TyCtxt } ;
23+ use rustc:: { declare_tool_lint, lint_array} ;
24+ use rustc_errors:: Applicability ;
2725use semver:: Version ;
26+ use syntax:: ast:: { AttrStyle , Attribute , Lit , LitKind , MetaItemKind , NestedMetaItem , NestedMetaItemKind } ;
27+ use syntax:: source_map:: Span ;
2828
2929/// **What it does:** Checks for items annotated with `#[inline(always)]`,
3030/// unless the annotated function is empty or simply panics.
@@ -212,7 +212,7 @@ impl LintPass for AttrPass {
212212
213213impl < ' a , ' tcx > LateLintPass < ' a , ' tcx > for AttrPass {
214214 fn check_attribute ( & mut self , cx : & LateContext < ' a , ' tcx > , attr : & ' tcx Attribute ) {
215- if let Some ( ref items) = attr. meta_item_list ( ) {
215+ if let Some ( items) = & attr. meta_item_list ( ) {
216216 match & * attr. name ( ) . as_str ( ) {
217217 "allow" | "warn" | "deny" | "forbid" => {
218218 check_clippy_lint_names ( cx, items) ;
@@ -224,8 +224,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AttrPass {
224224 }
225225 for item in items {
226226 if_chain ! {
227- if let NestedMetaItemKind :: MetaItem ( ref mi) = item. node;
228- if let MetaItemKind :: NameValue ( ref lit) = mi. node;
227+ if let NestedMetaItemKind :: MetaItem ( mi) = & item. node;
228+ if let MetaItemKind :: NameValue ( lit) = & mi. node;
229229 if mi. name( ) == "since" ;
230230 then {
231231 check_semver( cx, item. span, lit) ;
@@ -237,14 +237,14 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AttrPass {
237237
238238 fn check_item ( & mut self , cx : & LateContext < ' a , ' tcx > , item : & ' tcx Item ) {
239239 if is_relevant_item ( cx. tcx , item) {
240- check_attrs ( cx, item. span , item. name , & item. attrs )
240+ check_attrs ( cx, item. span , item. ident . name , & item. attrs )
241241 }
242242 match item. node {
243243 ItemKind :: ExternCrate ( ..) | ItemKind :: Use ( ..) => {
244244 let skip_unused_imports = item. attrs . iter ( ) . any ( |attr| attr. name ( ) == "macro_use" ) ;
245245
246246 for attr in & item. attrs {
247- if let Some ( ref lint_list) = attr. meta_item_list ( ) {
247+ if let Some ( lint_list) = & attr. meta_item_list ( ) {
248248 match & * attr. name ( ) . as_str ( ) {
249249 "allow" | "warn" | "deny" | "forbid" => {
250250 // whitelist `unused_imports` and `deprecated` for `use` items
@@ -381,22 +381,22 @@ fn is_relevant_trait(tcx: TyCtxt<'_, '_, '_>, item: &TraitItem) -> bool {
381381
382382fn is_relevant_block ( tcx : TyCtxt < ' _ , ' _ , ' _ > , tables : & ty:: TypeckTables < ' _ > , block : & Block ) -> bool {
383383 if let Some ( stmt) = block. stmts . first ( ) {
384- match stmt. node {
384+ match & stmt. node {
385385 StmtKind :: Decl ( _, _) => true ,
386- StmtKind :: Expr ( ref expr, _) | StmtKind :: Semi ( ref expr, _) => is_relevant_expr ( tcx, tables, expr) ,
386+ StmtKind :: Expr ( expr, _) | StmtKind :: Semi ( expr, _) => is_relevant_expr ( tcx, tables, expr) ,
387387 }
388388 } else {
389389 block. expr . as_ref ( ) . map_or ( false , |e| is_relevant_expr ( tcx, tables, e) )
390390 }
391391}
392392
393393fn is_relevant_expr ( tcx : TyCtxt < ' _ , ' _ , ' _ > , tables : & ty:: TypeckTables < ' _ > , expr : & Expr ) -> bool {
394- match expr. node {
395- ExprKind :: Block ( ref block, _) => is_relevant_block ( tcx, tables, block) ,
396- ExprKind :: Ret ( Some ( ref e) ) => is_relevant_expr ( tcx, tables, e) ,
394+ match & expr. node {
395+ ExprKind :: Block ( block, _) => is_relevant_block ( tcx, tables, block) ,
396+ ExprKind :: Ret ( Some ( e) ) => is_relevant_expr ( tcx, tables, e) ,
397397 ExprKind :: Ret ( None ) | ExprKind :: Break ( _, None ) => false ,
398- ExprKind :: Call ( ref path_expr, _) => {
399- if let ExprKind :: Path ( ref qpath) = path_expr. node {
398+ ExprKind :: Call ( path_expr, _) => {
399+ if let ExprKind :: Path ( qpath) = & path_expr. node {
400400 if let Some ( fun_id) = opt_def_id ( tables. qpath_def ( qpath, path_expr. hir_id ) ) {
401401 !match_def_path ( tcx, fun_id, & paths:: BEGIN_PANIC )
402402 } else {
@@ -443,7 +443,7 @@ fn check_attrs(cx: &LateContext<'_, '_>, span: Span, name: Name, attrs: &[Attrib
443443 }
444444 }
445445
446- if let Some ( ref values) = attr. meta_item_list ( ) {
446+ if let Some ( values) = attr. meta_item_list ( ) {
447447 if values. len ( ) != 1 || attr. name ( ) != "inline" {
448448 continue ;
449449 }
@@ -463,7 +463,7 @@ fn check_attrs(cx: &LateContext<'_, '_>, span: Span, name: Name, attrs: &[Attrib
463463}
464464
465465fn check_semver ( cx : & LateContext < ' _ , ' _ > , span : Span , lit : & Lit ) {
466- if let LitKind :: Str ( ref is, _) = lit. node {
466+ if let LitKind :: Str ( is, _) = lit. node {
467467 if Version :: parse ( & is. as_str ( ) ) . is_ok ( ) {
468468 return ;
469469 }
@@ -477,7 +477,7 @@ fn check_semver(cx: &LateContext<'_, '_>, span: Span, lit: &Lit) {
477477}
478478
479479fn is_word ( nmi : & NestedMetaItem , expected : & str ) -> bool {
480- if let NestedMetaItemKind :: MetaItem ( ref mi) = nmi. node {
480+ if let NestedMetaItemKind :: MetaItem ( mi) = & nmi. node {
481481 mi. is_word ( ) && mi. name ( ) == expected
482482 } else {
483483 false
@@ -512,7 +512,7 @@ impl EarlyLintPass for CfgAttrPass {
512512 if_chain ! {
513513 // check cfg_attr
514514 if attr. name( ) == "cfg_attr" ;
515- if let Some ( ref items) = attr. meta_item_list( ) ;
515+ if let Some ( items) = attr. meta_item_list( ) ;
516516 if items. len( ) == 2 ;
517517 // check for `rustfmt`
518518 if let Some ( feature_item) = items[ 0 ] . meta_item( ) ;
0 commit comments