3
3
use crate :: reexport:: * ;
4
4
use crate :: utils:: {
5
5
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
7
7
} ;
8
+ use crate :: utils:: sym;
8
9
use if_chain:: if_chain;
9
10
use rustc:: hir:: * ;
10
11
use rustc:: lint:: {
@@ -17,6 +18,7 @@ use rustc_errors::Applicability;
17
18
use semver:: Version ;
18
19
use syntax:: ast:: { AttrStyle , Attribute , Lit , LitKind , MetaItemKind , NestedMetaItem } ;
19
20
use syntax:: source_map:: Span ;
21
+ use syntax:: symbol:: Symbol ;
20
22
21
23
declare_clippy_lint ! {
22
24
/// **What it does:** Checks for items annotated with `#[inline(always)]`,
@@ -205,14 +207,14 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Attributes {
205
207
} ,
206
208
_ => { } ,
207
209
}
208
- if items. is_empty ( ) || !attr. check_name ( " deprecated" ) {
210
+ if items. is_empty ( ) || !attr. check_name ( * sym :: deprecated) {
209
211
return ;
210
212
}
211
213
for item in items {
212
214
if_chain ! {
213
215
if let NestedMetaItem :: MetaItem ( mi) = & item;
214
216
if let MetaItemKind :: NameValue ( lit) = & mi. node;
215
- if mi. check_name( " since" ) ;
217
+ if mi. check_name( * sym :: since) ;
216
218
then {
217
219
check_semver( cx, item. span( ) , lit) ;
218
220
}
@@ -228,7 +230,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Attributes {
228
230
}
229
231
match item. node {
230
232
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) ) ;
232
234
233
235
for attr in & item. attrs {
234
236
if in_external_macro ( cx. sess ( ) , attr. span ) {
@@ -243,15 +245,15 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Attributes {
243
245
for lint in lint_list {
244
246
match item. node {
245
247
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) {
247
249
return ;
248
250
}
249
251
} ,
250
252
ItemKind :: ExternCrate ( ..) => {
251
- if is_word ( lint, " unused_imports" ) && skip_unused_imports {
253
+ if is_word ( lint, * sym :: unused_imports) && skip_unused_imports {
252
254
return ;
253
255
}
254
- if is_word ( lint, " unused_extern_crates" ) {
256
+ if is_word ( lint, * sym :: unused_extern_crates) {
255
257
return ;
256
258
}
257
259
} ,
@@ -395,7 +397,7 @@ fn is_relevant_expr(cx: &LateContext<'_, '_>, tables: &ty::TypeckTables<'_>, exp
395
397
ExprKind :: Call ( path_expr, _) => {
396
398
if let ExprKind :: Path ( qpath) = & path_expr. node {
397
399
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 )
399
401
} else {
400
402
true
401
403
}
@@ -441,10 +443,10 @@ fn check_attrs(cx: &LateContext<'_, '_>, span: Span, name: Name, attrs: &[Attrib
441
443
}
442
444
443
445
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) {
445
447
continue ;
446
448
}
447
- if is_word ( & values[ 0 ] , " always" ) {
449
+ if is_word ( & values[ 0 ] , * sym :: always) {
448
450
span_lint (
449
451
cx,
450
452
INLINE_ALWAYS ,
@@ -473,7 +475,7 @@ fn check_semver(cx: &LateContext<'_, '_>, span: Span, lit: &Lit) {
473
475
) ;
474
476
}
475
477
476
- fn is_word ( nmi : & NestedMetaItem , expected : & str ) -> bool {
478
+ fn is_word ( nmi : & NestedMetaItem , expected : Symbol ) -> bool {
477
479
if let NestedMetaItem :: MetaItem ( mi) = & nmi {
478
480
mi. is_word ( ) && mi. check_name ( expected)
479
481
} else {
@@ -487,16 +489,16 @@ impl EarlyLintPass for DeprecatedCfgAttribute {
487
489
fn check_attribute ( & mut self , cx : & EarlyContext < ' _ > , attr : & Attribute ) {
488
490
if_chain ! {
489
491
// check cfg_attr
490
- if attr. check_name( " cfg_attr" ) ;
492
+ if attr. check_name( * sym :: cfg_attr) ;
491
493
if let Some ( items) = attr. meta_item_list( ) ;
492
494
if items. len( ) == 2 ;
493
495
// check for `rustfmt`
494
496
if let Some ( feature_item) = items[ 0 ] . meta_item( ) ;
495
- if feature_item. check_name( " rustfmt" ) ;
497
+ if feature_item. check_name( * sym :: rustfmt) ;
496
498
// check for `rustfmt_skip` and `rustfmt::skip`
497
499
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;
500
502
// Only lint outer attributes, because custom inner attributes are unstable
501
503
// Tracking issue: https://github.com/rust-lang/rust/issues/54726
502
504
if let AttrStyle :: Outer = attr. style;
0 commit comments