@@ -250,12 +250,8 @@ impl<'tcx> LateLintPass<'tcx> for Attributes {
250250 fn check_attribute ( & mut self , cx : & LateContext < ' tcx > , attr : & ' tcx Attribute ) {
251251 if let Some ( items) = & attr. meta_item_list ( ) {
252252 if let Some ( ident) = attr. ident ( ) {
253- let ident = & * ident. as_str ( ) ;
254- match ident {
255- "allow" | "warn" | "deny" | "forbid" => {
256- check_clippy_lint_names ( cx, ident, items) ;
257- } ,
258- _ => { } ,
253+ if is_lint_level ( ident. name ) {
254+ check_clippy_lint_names ( cx, ident. name , items) ;
259255 }
260256 if items. is_empty ( ) || !attr. has_name ( sym:: deprecated) {
261257 return ;
@@ -288,60 +284,54 @@ impl<'tcx> LateLintPass<'tcx> for Attributes {
288284 return ;
289285 }
290286 if let Some ( lint_list) = & attr. meta_item_list ( ) {
291- if let Some ( ident) = attr. ident ( ) {
292- match & * ident. as_str ( ) {
293- "allow" | "warn" | "deny" | "forbid" => {
294- // permit `unused_imports`, `deprecated`, `unreachable_pub`,
295- // `clippy::wildcard_imports`, and `clippy::enum_glob_use` for `use` items
296- // and `unused_imports` for `extern crate` items with `macro_use`
297- for lint in lint_list {
298- match item. kind {
299- ItemKind :: Use ( ..) => {
300- if is_word ( lint, sym ! ( unused_imports) )
301- || is_word ( lint, sym:: deprecated)
302- || is_word ( lint, sym ! ( unreachable_pub) )
303- || is_word ( lint, sym ! ( unused) )
304- || extract_clippy_lint ( lint)
305- . map_or ( false , |s| s == "wildcard_imports" )
306- || extract_clippy_lint ( lint) . map_or ( false , |s| s == "enum_glob_use" )
307- {
308- return ;
309- }
310- } ,
311- ItemKind :: ExternCrate ( ..) => {
312- if is_word ( lint, sym ! ( unused_imports) ) && skip_unused_imports {
313- return ;
314- }
315- if is_word ( lint, sym ! ( unused_extern_crates) ) {
316- return ;
317- }
318- } ,
319- _ => { } ,
287+ if attr. ident ( ) . map_or ( false , |ident| is_lint_level ( ident. name ) ) {
288+ // permit `unused_imports`, `deprecated`, `unreachable_pub`,
289+ // `clippy::wildcard_imports`, and `clippy::enum_glob_use` for `use` items
290+ // and `unused_imports` for `extern crate` items with `macro_use`
291+ for lint in lint_list {
292+ match item. kind {
293+ ItemKind :: Use ( ..) => {
294+ if is_word ( lint, sym ! ( unused_imports) )
295+ || is_word ( lint, sym:: deprecated)
296+ || is_word ( lint, sym ! ( unreachable_pub) )
297+ || is_word ( lint, sym ! ( unused) )
298+ || extract_clippy_lint ( lint) . map_or ( false , |s| s == "wildcard_imports" )
299+ || extract_clippy_lint ( lint) . map_or ( false , |s| s == "enum_glob_use" )
300+ {
301+ return ;
302+ }
303+ } ,
304+ ItemKind :: ExternCrate ( ..) => {
305+ if is_word ( lint, sym ! ( unused_imports) ) && skip_unused_imports {
306+ return ;
320307 }
321- }
322- let line_span = first_line_of_span ( cx, attr. span ) ;
323-
324- if let Some ( mut sugg) = snippet_opt ( cx, line_span) {
325- if sugg. contains ( "#[" ) {
326- span_lint_and_then (
327- cx,
328- USELESS_ATTRIBUTE ,
308+ if is_word ( lint, sym ! ( unused_extern_crates) ) {
309+ return ;
310+ }
311+ } ,
312+ _ => { } ,
313+ }
314+ }
315+ let line_span = first_line_of_span ( cx, attr. span ) ;
316+
317+ if let Some ( mut sugg) = snippet_opt ( cx, line_span) {
318+ if sugg. contains ( "#[" ) {
319+ span_lint_and_then (
320+ cx,
321+ USELESS_ATTRIBUTE ,
322+ line_span,
323+ "useless lint attribute" ,
324+ |diag| {
325+ sugg = sugg. replacen ( "#[" , "#![" , 1 ) ;
326+ diag. span_suggestion (
329327 line_span,
330- "useless lint attribute" ,
331- |diag| {
332- sugg = sugg. replacen ( "#[" , "#![" , 1 ) ;
333- diag. span_suggestion (
334- line_span,
335- "if you just forgot a `!`, use" ,
336- sugg,
337- Applicability :: MaybeIncorrect ,
338- ) ;
339- } ,
328+ "if you just forgot a `!`, use" ,
329+ sugg,
330+ Applicability :: MaybeIncorrect ,
340331 ) ;
341- }
342- }
343- } ,
344- _ => { } ,
332+ } ,
333+ ) ;
334+ }
345335 }
346336 }
347337 }
@@ -379,10 +369,10 @@ fn extract_clippy_lint(lint: &NestedMetaItem) -> Option<SymbolStr> {
379369 None
380370}
381371
382- fn check_clippy_lint_names ( cx : & LateContext < ' _ > , ident : & str , items : & [ NestedMetaItem ] ) {
372+ fn check_clippy_lint_names ( cx : & LateContext < ' _ > , name : Symbol , items : & [ NestedMetaItem ] ) {
383373 for lint in items {
384374 if let Some ( lint_name) = extract_clippy_lint ( lint) {
385- if lint_name == "restriction" && ident != " allow" {
375+ if lint_name == "restriction" && name != sym :: allow {
386376 span_lint_and_help (
387377 cx,
388378 BLANKET_CLIPPY_RESTRICTION_LINTS ,
@@ -647,3 +637,7 @@ fn check_mismatched_target_os(cx: &EarlyContext<'_>, attr: &Attribute) {
647637 }
648638 }
649639}
640+
641+ fn is_lint_level ( symbol : Symbol ) -> bool {
642+ matches ! ( symbol, sym:: allow | sym:: warn | sym:: deny | sym:: forbid)
643+ }
0 commit comments