33use crate :: reexport:: * ;
44use crate :: utils:: {
55 in_macro_or_desugar, is_present_in_source, last_line_of_span, paths, snippet_opt, span_lint, span_lint_and_sugg,
6- span_lint_and_then, without_block_comments,
6+ span_lint_and_then, without_block_comments, match_def_path
77} ;
8+ use crate :: utils:: sym;
89use if_chain:: if_chain;
910use rustc:: hir:: * ;
1011use rustc:: lint:: {
@@ -17,6 +18,7 @@ use rustc_errors::Applicability;
1718use semver:: Version ;
1819use syntax:: ast:: { AttrStyle , Attribute , Lit , LitKind , MetaItemKind , NestedMetaItem } ;
1920use syntax:: source_map:: Span ;
21+ use syntax:: symbol:: Symbol ;
2022
2123declare_clippy_lint ! {
2224 /// **What it does:** Checks for items annotated with `#[inline(always)]`,
@@ -205,14 +207,14 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Attributes {
205207 } ,
206208 _ => { } ,
207209 }
208- if items. is_empty ( ) || !attr. check_name ( " deprecated" ) {
210+ if items. is_empty ( ) || !attr. check_name ( * sym :: deprecated) {
209211 return ;
210212 }
211213 for item in items {
212214 if_chain ! {
213215 if let NestedMetaItem :: MetaItem ( mi) = & item;
214216 if let MetaItemKind :: NameValue ( lit) = & mi. node;
215- if mi. check_name( " since" ) ;
217+ if mi. check_name( * sym :: since) ;
216218 then {
217219 check_semver( cx, item. span( ) , lit) ;
218220 }
@@ -228,7 +230,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Attributes {
228230 }
229231 match item. node {
230232 ItemKind :: ExternCrate ( ..) | ItemKind :: Use ( ..) => {
231- let skip_unused_imports = item. attrs . iter ( ) . any ( |attr| attr. check_name ( " macro_use" ) ) ;
233+ let skip_unused_imports = item. attrs . iter ( ) . any ( |attr| attr. check_name ( * sym :: macro_use) ) ;
232234
233235 for attr in & item. attrs {
234236 if in_external_macro ( cx. sess ( ) , attr. span ) {
@@ -243,15 +245,15 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Attributes {
243245 for lint in lint_list {
244246 match item. node {
245247 ItemKind :: Use ( ..) => {
246- if is_word ( lint, " unused_imports" ) || is_word ( lint, " deprecated" ) {
248+ if is_word ( lint, * sym :: unused_imports) || is_word ( lint, * sym :: deprecated) {
247249 return ;
248250 }
249251 } ,
250252 ItemKind :: ExternCrate ( ..) => {
251- if is_word ( lint, " unused_imports" ) && skip_unused_imports {
253+ if is_word ( lint, * sym :: unused_imports) && skip_unused_imports {
252254 return ;
253255 }
254- if is_word ( lint, " unused_extern_crates" ) {
256+ if is_word ( lint, * sym :: unused_extern_crates) {
255257 return ;
256258 }
257259 } ,
@@ -395,7 +397,7 @@ fn is_relevant_expr(cx: &LateContext<'_, '_>, tables: &ty::TypeckTables<'_>, exp
395397 ExprKind :: Call ( path_expr, _) => {
396398 if let ExprKind :: Path ( qpath) = & path_expr. node {
397399 if let Some ( fun_id) = tables. qpath_res ( qpath, path_expr. hir_id ) . opt_def_id ( ) {
398- !cx . match_def_path ( fun_id, & paths:: BEGIN_PANIC )
400+ !match_def_path ( cx , fun_id, & * paths:: BEGIN_PANIC )
399401 } else {
400402 true
401403 }
@@ -441,10 +443,10 @@ fn check_attrs(cx: &LateContext<'_, '_>, span: Span, name: Name, attrs: &[Attrib
441443 }
442444
443445 if let Some ( values) = attr. meta_item_list ( ) {
444- if values. len ( ) != 1 || !attr. check_name ( " inline" ) {
446+ if values. len ( ) != 1 || !attr. check_name ( * sym :: inline) {
445447 continue ;
446448 }
447- if is_word ( & values[ 0 ] , " always" ) {
449+ if is_word ( & values[ 0 ] , * sym :: always) {
448450 span_lint (
449451 cx,
450452 INLINE_ALWAYS ,
@@ -473,7 +475,7 @@ fn check_semver(cx: &LateContext<'_, '_>, span: Span, lit: &Lit) {
473475 ) ;
474476}
475477
476- fn is_word ( nmi : & NestedMetaItem , expected : & str ) -> bool {
478+ fn is_word ( nmi : & NestedMetaItem , expected : Symbol ) -> bool {
477479 if let NestedMetaItem :: MetaItem ( mi) = & nmi {
478480 mi. is_word ( ) && mi. check_name ( expected)
479481 } else {
@@ -487,16 +489,16 @@ impl EarlyLintPass for DeprecatedCfgAttribute {
487489 fn check_attribute ( & mut self , cx : & EarlyContext < ' _ > , attr : & Attribute ) {
488490 if_chain ! {
489491 // check cfg_attr
490- if attr. check_name( " cfg_attr" ) ;
492+ if attr. check_name( * sym :: cfg_attr) ;
491493 if let Some ( items) = attr. meta_item_list( ) ;
492494 if items. len( ) == 2 ;
493495 // check for `rustfmt`
494496 if let Some ( feature_item) = items[ 0 ] . meta_item( ) ;
495- if feature_item. check_name( " rustfmt" ) ;
497+ if feature_item. check_name( * sym :: rustfmt) ;
496498 // check for `rustfmt_skip` and `rustfmt::skip`
497499 if let Some ( skip_item) = & items[ 1 ] . meta_item( ) ;
498- if skip_item. check_name( " rustfmt_skip" ) ||
499- skip_item. path. segments. last( ) . expect( "empty path in attribute" ) . ident. name == " skip" ;
500+ if skip_item. check_name( * sym :: rustfmt_skip) ||
501+ skip_item. path. segments. last( ) . expect( "empty path in attribute" ) . ident. name == * sym :: skip;
500502 // Only lint outer attributes, because custom inner attributes are unstable
501503 // Tracking issue: https://github.com/rust-lang/rust/issues/54726
502504 if let AttrStyle :: Outer = attr. style;
0 commit comments