]> git.lizzy.rs Git - rust.git/blob - clippy_lints/src/attrs.rs
Auto merge of #92252 - GuillaumeGomez:update-pulldown, r=camelid,xFrednet
[rust.git] / clippy_lints / src / attrs.rs
1 //! checks for attributes
2
3 use clippy_utils::diagnostics::{span_lint, span_lint_and_help, span_lint_and_sugg, span_lint_and_then};
4 use clippy_utils::msrvs;
5 use clippy_utils::source::{first_line_of_span, is_present_in_source, snippet_opt, without_block_comments};
6 use clippy_utils::{extract_msrv_attr, match_panic_def_id, meets_msrv};
7 use if_chain::if_chain;
8 use rustc_ast::{AttrKind, AttrStyle, Attribute, Lit, LitKind, MetaItemKind, NestedMetaItem};
9 use rustc_errors::Applicability;
10 use rustc_hir::{
11     Block, Expr, ExprKind, ImplItem, ImplItemKind, Item, ItemKind, StmtKind, TraitFn, TraitItem, TraitItemKind,
12 };
13 use rustc_lint::{EarlyContext, EarlyLintPass, LateContext, LateLintPass, LintContext};
14 use rustc_middle::lint::in_external_macro;
15 use rustc_middle::ty;
16 use rustc_semver::RustcVersion;
17 use rustc_session::{declare_lint_pass, declare_tool_lint, impl_lint_pass};
18 use rustc_span::source_map::Span;
19 use rustc_span::sym;
20 use rustc_span::symbol::Symbol;
21 use semver::Version;
22
23 static UNIX_SYSTEMS: &[&str] = &[
24     "android",
25     "dragonfly",
26     "emscripten",
27     "freebsd",
28     "fuchsia",
29     "haiku",
30     "illumos",
31     "ios",
32     "l4re",
33     "linux",
34     "macos",
35     "netbsd",
36     "openbsd",
37     "redox",
38     "solaris",
39     "vxworks",
40 ];
41
42 // NOTE: windows is excluded from the list because it's also a valid target family.
43 static NON_UNIX_SYSTEMS: &[&str] = &["hermit", "none", "wasi"];
44
45 declare_clippy_lint! {
46     /// ### What it does
47     /// Checks for items annotated with `#[inline(always)]`,
48     /// unless the annotated function is empty or simply panics.
49     ///
50     /// ### Why is this bad?
51     /// While there are valid uses of this annotation (and once
52     /// you know when to use it, by all means `allow` this lint), it's a common
53     /// newbie-mistake to pepper one's code with it.
54     ///
55     /// As a rule of thumb, before slapping `#[inline(always)]` on a function,
56     /// measure if that additional function call really affects your runtime profile
57     /// sufficiently to make up for the increase in compile time.
58     ///
59     /// ### Known problems
60     /// False positives, big time. This lint is meant to be
61     /// deactivated by everyone doing serious performance work. This means having
62     /// done the measurement.
63     ///
64     /// ### Example
65     /// ```ignore
66     /// #[inline(always)]
67     /// fn not_quite_hot_code(..) { ... }
68     /// ```
69     #[clippy::version = "pre 1.29.0"]
70     pub INLINE_ALWAYS,
71     pedantic,
72     "use of `#[inline(always)]`"
73 }
74
75 declare_clippy_lint! {
76     /// ### What it does
77     /// Checks for `extern crate` and `use` items annotated with
78     /// lint attributes.
79     ///
80     /// This lint permits `#[allow(unused_imports)]`, `#[allow(deprecated)]`,
81     /// `#[allow(unreachable_pub)]`, `#[allow(clippy::wildcard_imports)]` and
82     /// `#[allow(clippy::enum_glob_use)]` on `use` items and `#[allow(unused_imports)]` on
83     /// `extern crate` items with a `#[macro_use]` attribute.
84     ///
85     /// ### Why is this bad?
86     /// Lint attributes have no effect on crate imports. Most
87     /// likely a `!` was forgotten.
88     ///
89     /// ### Example
90     /// ```ignore
91     /// // Bad
92     /// #[deny(dead_code)]
93     /// extern crate foo;
94     /// #[forbid(dead_code)]
95     /// use foo::bar;
96     ///
97     /// // Ok
98     /// #[allow(unused_imports)]
99     /// use foo::baz;
100     /// #[allow(unused_imports)]
101     /// #[macro_use]
102     /// extern crate baz;
103     /// ```
104     #[clippy::version = "pre 1.29.0"]
105     pub USELESS_ATTRIBUTE,
106     correctness,
107     "use of lint attributes on `extern crate` items"
108 }
109
110 declare_clippy_lint! {
111     /// ### What it does
112     /// Checks for `#[deprecated]` annotations with a `since`
113     /// field that is not a valid semantic version.
114     ///
115     /// ### Why is this bad?
116     /// For checking the version of the deprecation, it must be
117     /// a valid semver. Failing that, the contained information is useless.
118     ///
119     /// ### Example
120     /// ```rust
121     /// #[deprecated(since = "forever")]
122     /// fn something_else() { /* ... */ }
123     /// ```
124     #[clippy::version = "pre 1.29.0"]
125     pub DEPRECATED_SEMVER,
126     correctness,
127     "use of `#[deprecated(since = \"x\")]` where x is not semver"
128 }
129
130 declare_clippy_lint! {
131     /// ### What it does
132     /// Checks for empty lines after outer attributes
133     ///
134     /// ### Why is this bad?
135     /// Most likely the attribute was meant to be an inner attribute using a '!'.
136     /// If it was meant to be an outer attribute, then the following item
137     /// should not be separated by empty lines.
138     ///
139     /// ### Known problems
140     /// Can cause false positives.
141     ///
142     /// From the clippy side it's difficult to detect empty lines between an attributes and the
143     /// following item because empty lines and comments are not part of the AST. The parsing
144     /// currently works for basic cases but is not perfect.
145     ///
146     /// ### Example
147     /// ```rust
148     /// // Good (as inner attribute)
149     /// #![allow(dead_code)]
150     ///
151     /// fn this_is_fine() { }
152     ///
153     /// // Bad
154     /// #[allow(dead_code)]
155     ///
156     /// fn not_quite_good_code() { }
157     ///
158     /// // Good (as outer attribute)
159     /// #[allow(dead_code)]
160     /// fn this_is_fine_too() { }
161     /// ```
162     #[clippy::version = "pre 1.29.0"]
163     pub EMPTY_LINE_AFTER_OUTER_ATTR,
164     nursery,
165     "empty line after outer attribute"
166 }
167
168 declare_clippy_lint! {
169     /// ### What it does
170     /// Checks for `warn`/`deny`/`forbid` attributes targeting the whole clippy::restriction category.
171     ///
172     /// ### Why is this bad?
173     /// Restriction lints sometimes are in contrast with other lints or even go against idiomatic rust.
174     /// These lints should only be enabled on a lint-by-lint basis and with careful consideration.
175     ///
176     /// ### Example
177     /// Bad:
178     /// ```rust
179     /// #![deny(clippy::restriction)]
180     /// ```
181     ///
182     /// Good:
183     /// ```rust
184     /// #![deny(clippy::as_conversions)]
185     /// ```
186     #[clippy::version = "1.47.0"]
187     pub BLANKET_CLIPPY_RESTRICTION_LINTS,
188     suspicious,
189     "enabling the complete restriction group"
190 }
191
192 declare_clippy_lint! {
193     /// ### What it does
194     /// Checks for `#[cfg_attr(rustfmt, rustfmt_skip)]` and suggests to replace it
195     /// with `#[rustfmt::skip]`.
196     ///
197     /// ### Why is this bad?
198     /// Since tool_attributes ([rust-lang/rust#44690](https://github.com/rust-lang/rust/issues/44690))
199     /// are stable now, they should be used instead of the old `cfg_attr(rustfmt)` attributes.
200     ///
201     /// ### Known problems
202     /// This lint doesn't detect crate level inner attributes, because they get
203     /// processed before the PreExpansionPass lints get executed. See
204     /// [#3123](https://github.com/rust-lang/rust-clippy/pull/3123#issuecomment-422321765)
205     ///
206     /// ### Example
207     /// Bad:
208     /// ```rust
209     /// #[cfg_attr(rustfmt, rustfmt_skip)]
210     /// fn main() { }
211     /// ```
212     ///
213     /// Good:
214     /// ```rust
215     /// #[rustfmt::skip]
216     /// fn main() { }
217     /// ```
218     #[clippy::version = "1.32.0"]
219     pub DEPRECATED_CFG_ATTR,
220     complexity,
221     "usage of `cfg_attr(rustfmt)` instead of tool attributes"
222 }
223
224 declare_clippy_lint! {
225     /// ### What it does
226     /// Checks for cfg attributes having operating systems used in target family position.
227     ///
228     /// ### Why is this bad?
229     /// The configuration option will not be recognised and the related item will not be included
230     /// by the conditional compilation engine.
231     ///
232     /// ### Example
233     /// Bad:
234     /// ```rust
235     /// #[cfg(linux)]
236     /// fn conditional() { }
237     /// ```
238     ///
239     /// Good:
240     /// ```rust
241     /// #[cfg(target_os = "linux")]
242     /// fn conditional() { }
243     /// ```
244     ///
245     /// Or:
246     /// ```rust
247     /// #[cfg(unix)]
248     /// fn conditional() { }
249     /// ```
250     /// Check the [Rust Reference](https://doc.rust-lang.org/reference/conditional-compilation.html#target_os) for more details.
251     #[clippy::version = "1.45.0"]
252     pub MISMATCHED_TARGET_OS,
253     correctness,
254     "usage of `cfg(operating_system)` instead of `cfg(target_os = \"operating_system\")`"
255 }
256
257 declare_lint_pass!(Attributes => [
258     INLINE_ALWAYS,
259     DEPRECATED_SEMVER,
260     USELESS_ATTRIBUTE,
261     BLANKET_CLIPPY_RESTRICTION_LINTS,
262 ]);
263
264 impl<'tcx> LateLintPass<'tcx> for Attributes {
265     fn check_attribute(&mut self, cx: &LateContext<'tcx>, attr: &'tcx Attribute) {
266         if let Some(items) = &attr.meta_item_list() {
267             if let Some(ident) = attr.ident() {
268                 if is_lint_level(ident.name) {
269                     check_clippy_lint_names(cx, ident.name, items);
270                 }
271                 if items.is_empty() || !attr.has_name(sym::deprecated) {
272                     return;
273                 }
274                 for item in items {
275                     if_chain! {
276                         if let NestedMetaItem::MetaItem(mi) = &item;
277                         if let MetaItemKind::NameValue(lit) = &mi.kind;
278                         if mi.has_name(sym::since);
279                         then {
280                             check_semver(cx, item.span(), lit);
281                         }
282                     }
283                 }
284             }
285         }
286     }
287
288     fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) {
289         let attrs = cx.tcx.hir().attrs(item.hir_id());
290         if is_relevant_item(cx, item) {
291             check_attrs(cx, item.span, item.ident.name, attrs);
292         }
293         match item.kind {
294             ItemKind::ExternCrate(..) | ItemKind::Use(..) => {
295                 let skip_unused_imports = attrs.iter().any(|attr| attr.has_name(sym::macro_use));
296
297                 for attr in attrs {
298                     if in_external_macro(cx.sess(), attr.span) {
299                         return;
300                     }
301                     if let Some(lint_list) = &attr.meta_item_list() {
302                         if attr.ident().map_or(false, |ident| is_lint_level(ident.name)) {
303                             // permit `unused_imports`, `deprecated`, `unreachable_pub`,
304                             // `clippy::wildcard_imports`, and `clippy::enum_glob_use` for `use` items
305                             // and `unused_imports` for `extern crate` items with `macro_use`
306                             for lint in lint_list {
307                                 match item.kind {
308                                     ItemKind::Use(..) => {
309                                         if is_word(lint, sym!(unused_imports))
310                                             || is_word(lint, sym::deprecated)
311                                             || is_word(lint, sym!(unreachable_pub))
312                                             || is_word(lint, sym!(unused))
313                                             || extract_clippy_lint(lint)
314                                                 .map_or(false, |s| s.as_str() == "wildcard_imports")
315                                             || extract_clippy_lint(lint)
316                                                 .map_or(false, |s| s.as_str() == "enum_glob_use")
317                                         {
318                                             return;
319                                         }
320                                     },
321                                     ItemKind::ExternCrate(..) => {
322                                         if is_word(lint, sym!(unused_imports)) && skip_unused_imports {
323                                             return;
324                                         }
325                                         if is_word(lint, sym!(unused_extern_crates)) {
326                                             return;
327                                         }
328                                     },
329                                     _ => {},
330                                 }
331                             }
332                             let line_span = first_line_of_span(cx, attr.span);
333
334                             if let Some(mut sugg) = snippet_opt(cx, line_span) {
335                                 if sugg.contains("#[") {
336                                     span_lint_and_then(
337                                         cx,
338                                         USELESS_ATTRIBUTE,
339                                         line_span,
340                                         "useless lint attribute",
341                                         |diag| {
342                                             sugg = sugg.replacen("#[", "#![", 1);
343                                             diag.span_suggestion(
344                                                 line_span,
345                                                 "if you just forgot a `!`, use",
346                                                 sugg,
347                                                 Applicability::MaybeIncorrect,
348                                             );
349                                         },
350                                     );
351                                 }
352                             }
353                         }
354                     }
355                 }
356             },
357             _ => {},
358         }
359     }
360
361     fn check_impl_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx ImplItem<'_>) {
362         if is_relevant_impl(cx, item) {
363             check_attrs(cx, item.span, item.ident.name, cx.tcx.hir().attrs(item.hir_id()));
364         }
365     }
366
367     fn check_trait_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx TraitItem<'_>) {
368         if is_relevant_trait(cx, item) {
369             check_attrs(cx, item.span, item.ident.name, cx.tcx.hir().attrs(item.hir_id()));
370         }
371     }
372 }
373
374 /// Returns the lint name if it is clippy lint.
375 fn extract_clippy_lint(lint: &NestedMetaItem) -> Option<Symbol> {
376     if_chain! {
377         if let Some(meta_item) = lint.meta_item();
378         if meta_item.path.segments.len() > 1;
379         if let tool_name = meta_item.path.segments[0].ident;
380         if tool_name.name == sym::clippy;
381         then {
382             let lint_name = meta_item.path.segments.last().unwrap().ident.name;
383             return Some(lint_name);
384         }
385     }
386     None
387 }
388
389 fn check_clippy_lint_names(cx: &LateContext<'_>, name: Symbol, items: &[NestedMetaItem]) {
390     for lint in items {
391         if let Some(lint_name) = extract_clippy_lint(lint) {
392             if lint_name.as_str() == "restriction" && name != sym::allow {
393                 span_lint_and_help(
394                     cx,
395                     BLANKET_CLIPPY_RESTRICTION_LINTS,
396                     lint.span(),
397                     "restriction lints are not meant to be all enabled",
398                     None,
399                     "try enabling only the lints you really need",
400                 );
401             }
402         }
403     }
404 }
405
406 fn is_relevant_item(cx: &LateContext<'_>, item: &Item<'_>) -> bool {
407     if let ItemKind::Fn(_, _, eid) = item.kind {
408         is_relevant_expr(cx, cx.tcx.typeck_body(eid), &cx.tcx.hir().body(eid).value)
409     } else {
410         true
411     }
412 }
413
414 fn is_relevant_impl(cx: &LateContext<'_>, item: &ImplItem<'_>) -> bool {
415     match item.kind {
416         ImplItemKind::Fn(_, eid) => is_relevant_expr(cx, cx.tcx.typeck_body(eid), &cx.tcx.hir().body(eid).value),
417         _ => false,
418     }
419 }
420
421 fn is_relevant_trait(cx: &LateContext<'_>, item: &TraitItem<'_>) -> bool {
422     match item.kind {
423         TraitItemKind::Fn(_, TraitFn::Required(_)) => true,
424         TraitItemKind::Fn(_, TraitFn::Provided(eid)) => {
425             is_relevant_expr(cx, cx.tcx.typeck_body(eid), &cx.tcx.hir().body(eid).value)
426         },
427         _ => false,
428     }
429 }
430
431 fn is_relevant_block(cx: &LateContext<'_>, typeck_results: &ty::TypeckResults<'_>, block: &Block<'_>) -> bool {
432     block.stmts.first().map_or(
433         block
434             .expr
435             .as_ref()
436             .map_or(false, |e| is_relevant_expr(cx, typeck_results, e)),
437         |stmt| match &stmt.kind {
438             StmtKind::Local(_) => true,
439             StmtKind::Expr(expr) | StmtKind::Semi(expr) => is_relevant_expr(cx, typeck_results, expr),
440             StmtKind::Item(_) => false,
441         },
442     )
443 }
444
445 fn is_relevant_expr(cx: &LateContext<'_>, typeck_results: &ty::TypeckResults<'_>, expr: &Expr<'_>) -> bool {
446     match &expr.kind {
447         ExprKind::Block(block, _) => is_relevant_block(cx, typeck_results, block),
448         ExprKind::Ret(Some(e)) => is_relevant_expr(cx, typeck_results, e),
449         ExprKind::Ret(None) | ExprKind::Break(_, None) => false,
450         ExprKind::Call(path_expr, _) => {
451             if let ExprKind::Path(qpath) = &path_expr.kind {
452                 typeck_results
453                     .qpath_res(qpath, path_expr.hir_id)
454                     .opt_def_id()
455                     .map_or(true, |fun_id| !match_panic_def_id(cx, fun_id))
456             } else {
457                 true
458             }
459         },
460         _ => true,
461     }
462 }
463
464 fn check_attrs(cx: &LateContext<'_>, span: Span, name: Symbol, attrs: &[Attribute]) {
465     if span.from_expansion() {
466         return;
467     }
468
469     for attr in attrs {
470         if let Some(values) = attr.meta_item_list() {
471             if values.len() != 1 || !attr.has_name(sym::inline) {
472                 continue;
473             }
474             if is_word(&values[0], sym::always) {
475                 span_lint(
476                     cx,
477                     INLINE_ALWAYS,
478                     attr.span,
479                     &format!(
480                         "you have declared `#[inline(always)]` on `{}`. This is usually a bad idea",
481                         name
482                     ),
483                 );
484             }
485         }
486     }
487 }
488
489 fn check_semver(cx: &LateContext<'_>, span: Span, lit: &Lit) {
490     if let LitKind::Str(is, _) = lit.kind {
491         if Version::parse(is.as_str()).is_ok() {
492             return;
493         }
494     }
495     span_lint(
496         cx,
497         DEPRECATED_SEMVER,
498         span,
499         "the since field must contain a semver-compliant version",
500     );
501 }
502
503 fn is_word(nmi: &NestedMetaItem, expected: Symbol) -> bool {
504     if let NestedMetaItem::MetaItem(mi) = &nmi {
505         mi.is_word() && mi.has_name(expected)
506     } else {
507         false
508     }
509 }
510
511 pub struct EarlyAttributes {
512     pub msrv: Option<RustcVersion>,
513 }
514
515 impl_lint_pass!(EarlyAttributes => [
516     DEPRECATED_CFG_ATTR,
517     MISMATCHED_TARGET_OS,
518     EMPTY_LINE_AFTER_OUTER_ATTR,
519 ]);
520
521 impl EarlyLintPass for EarlyAttributes {
522     fn check_item(&mut self, cx: &EarlyContext<'_>, item: &rustc_ast::Item) {
523         check_empty_line_after_outer_attr(cx, item);
524     }
525
526     fn check_attribute(&mut self, cx: &EarlyContext<'_>, attr: &Attribute) {
527         check_deprecated_cfg_attr(cx, attr, self.msrv);
528         check_mismatched_target_os(cx, attr);
529     }
530
531     extract_msrv_attr!(EarlyContext);
532 }
533
534 fn check_empty_line_after_outer_attr(cx: &EarlyContext<'_>, item: &rustc_ast::Item) {
535     for attr in &item.attrs {
536         let attr_item = if let AttrKind::Normal(ref attr, _) = attr.kind {
537             attr
538         } else {
539             return;
540         };
541
542         if attr.style == AttrStyle::Outer {
543             if attr_item.args.inner_tokens().is_empty() || !is_present_in_source(cx, attr.span) {
544                 return;
545             }
546
547             let begin_of_attr_to_item = Span::new(attr.span.lo(), item.span.lo(), item.span.ctxt(), item.span.parent());
548             let end_of_attr_to_item = Span::new(attr.span.hi(), item.span.lo(), item.span.ctxt(), item.span.parent());
549
550             if let Some(snippet) = snippet_opt(cx, end_of_attr_to_item) {
551                 let lines = snippet.split('\n').collect::<Vec<_>>();
552                 let lines = without_block_comments(lines);
553
554                 if lines.iter().filter(|l| l.trim().is_empty()).count() > 2 {
555                     span_lint(
556                         cx,
557                         EMPTY_LINE_AFTER_OUTER_ATTR,
558                         begin_of_attr_to_item,
559                         "found an empty line after an outer attribute. \
560                         Perhaps you forgot to add a `!` to make it an inner attribute?",
561                     );
562                 }
563             }
564         }
565     }
566 }
567
568 fn check_deprecated_cfg_attr(cx: &EarlyContext<'_>, attr: &Attribute, msrv: Option<RustcVersion>) {
569     if_chain! {
570         if meets_msrv(msrv.as_ref(), &msrvs::TOOL_ATTRIBUTES);
571         // check cfg_attr
572         if attr.has_name(sym::cfg_attr);
573         if let Some(items) = attr.meta_item_list();
574         if items.len() == 2;
575         // check for `rustfmt`
576         if let Some(feature_item) = items[0].meta_item();
577         if feature_item.has_name(sym::rustfmt);
578         // check for `rustfmt_skip` and `rustfmt::skip`
579         if let Some(skip_item) = &items[1].meta_item();
580         if skip_item.has_name(sym!(rustfmt_skip)) ||
581             skip_item.path.segments.last().expect("empty path in attribute").ident.name == sym::skip;
582         // Only lint outer attributes, because custom inner attributes are unstable
583         // Tracking issue: https://github.com/rust-lang/rust/issues/54726
584         if attr.style == AttrStyle::Outer;
585         then {
586             span_lint_and_sugg(
587                 cx,
588                 DEPRECATED_CFG_ATTR,
589                 attr.span,
590                 "`cfg_attr` is deprecated for rustfmt and got replaced by tool attributes",
591                 "use",
592                 "#[rustfmt::skip]".to_string(),
593                 Applicability::MachineApplicable,
594             );
595         }
596     }
597 }
598
599 fn check_mismatched_target_os(cx: &EarlyContext<'_>, attr: &Attribute) {
600     fn find_os(name: &str) -> Option<&'static str> {
601         UNIX_SYSTEMS
602             .iter()
603             .chain(NON_UNIX_SYSTEMS.iter())
604             .find(|&&os| os == name)
605             .copied()
606     }
607
608     fn is_unix(name: &str) -> bool {
609         UNIX_SYSTEMS.iter().any(|&os| os == name)
610     }
611
612     fn find_mismatched_target_os(items: &[NestedMetaItem]) -> Vec<(&str, Span)> {
613         let mut mismatched = Vec::new();
614
615         for item in items {
616             if let NestedMetaItem::MetaItem(meta) = item {
617                 match &meta.kind {
618                     MetaItemKind::List(list) => {
619                         mismatched.extend(find_mismatched_target_os(list));
620                     },
621                     MetaItemKind::Word => {
622                         if_chain! {
623                             if let Some(ident) = meta.ident();
624                             if let Some(os) = find_os(ident.name.as_str());
625                             then {
626                                 mismatched.push((os, ident.span));
627                             }
628                         }
629                     },
630                     MetaItemKind::NameValue(..) => {},
631                 }
632             }
633         }
634
635         mismatched
636     }
637
638     if_chain! {
639         if attr.has_name(sym::cfg);
640         if let Some(list) = attr.meta_item_list();
641         let mismatched = find_mismatched_target_os(&list);
642         if !mismatched.is_empty();
643         then {
644             let mess = "operating system used in target family position";
645
646             span_lint_and_then(cx, MISMATCHED_TARGET_OS, attr.span, mess, |diag| {
647                 // Avoid showing the unix suggestion multiple times in case
648                 // we have more than one mismatch for unix-like systems
649                 let mut unix_suggested = false;
650
651                 for (os, span) in mismatched {
652                     let sugg = format!("target_os = \"{}\"", os);
653                     diag.span_suggestion(span, "try", sugg, Applicability::MaybeIncorrect);
654
655                     if !unix_suggested && is_unix(os) {
656                         diag.help("did you mean `unix`?");
657                         unix_suggested = true;
658                     }
659                 }
660             });
661         }
662     }
663 }
664
665 fn is_lint_level(symbol: Symbol) -> bool {
666     matches!(symbol, sym::allow | sym::warn | sym::deny | sym::forbid)
667 }