1 use syntax_pos::{Symbol, sym};
2 use syntax_pos::edition::Edition;
3 pub use self::Level::*;
5 /// Setting for how to handle a lint.
6 #[derive(Clone, Copy, PartialEq, PartialOrd, Eq, Ord, Debug, Hash)]
8 Allow, Warn, Deny, Forbid,
11 rustc_data_structures::impl_stable_hash_via_hash!(Level);
14 /// Converts a level to a lower-case string.
15 pub fn as_str(self) -> &'static str {
17 Level::Allow => "allow",
18 Level::Warn => "warn",
19 Level::Deny => "deny",
20 Level::Forbid => "forbid",
24 /// Converts a lower-case string to a level.
25 pub fn from_str(x: &str) -> Option<Level> {
27 "allow" => Some(Level::Allow),
28 "warn" => Some(Level::Warn),
29 "deny" => Some(Level::Deny),
30 "forbid" => Some(Level::Forbid),
35 /// Converts a symbol to a level.
36 pub fn from_symbol(x: Symbol) -> Option<Level> {
38 sym::allow => Some(Level::Allow),
39 sym::warn => Some(Level::Warn),
40 sym::deny => Some(Level::Deny),
41 sym::forbid => Some(Level::Forbid),
47 /// Specification of a single lint.
48 #[derive(Copy, Clone, Debug)]
50 /// A string identifier for the lint.
52 /// This identifies the lint in attributes and in command-line arguments.
53 /// In those contexts it is always lowercase, but this field is compared
54 /// in a way which is case-insensitive for ASCII characters. This allows
55 /// `declare_lint!()` invocations to follow the convention of upper-case
56 /// statics without repeating the name.
58 /// The name is written with underscores, e.g., "unused_imports".
59 /// On the command line, underscores become dashes.
60 pub name: &'static str,
62 /// Default level for the lint.
63 pub default_level: Level,
65 /// Description of the lint or the issue it detects.
67 /// e.g., "imports that are never used"
68 pub desc: &'static str,
70 /// Starting at the given edition, default to the given lint level. If this is `None`, then use
72 pub edition_lint_opts: Option<(Edition, Level)>,
74 /// `true` if this lint is reported even inside expansions of external macros.
75 pub report_in_external_macro: bool,
77 pub future_incompatible: Option<FutureIncompatibleInfo>,
82 /// Extra information for a future incompatibility lint.
83 #[derive(Copy, Clone, Debug)]
84 pub struct FutureIncompatibleInfo {
85 /// e.g., a URL for an issue/PR/RFC or error code
86 pub reference: &'static str,
87 /// If this is an edition fixing lint, the edition in which
88 /// this lint becomes obsolete
89 pub edition: Option<Edition>,
93 pub const fn default_fields_for_macro() -> Self {
96 default_level: Level::Forbid,
98 edition_lint_opts: None,
100 report_in_external_macro: false,
101 future_incompatible: None,
105 /// Gets the lint's name, with ASCII letters converted to lowercase.
106 pub fn name_lower(&self) -> String {
107 self.name.to_ascii_lowercase()
110 pub fn default_level(&self, edition: Edition) -> Level {
111 self.edition_lint_opts
112 .filter(|(e, _)| *e <= edition)
114 .unwrap_or(self.default_level)