]> git.lizzy.rs Git - rust.git/blob - src/librustc_session/lint.rs
Move Level to rustc_session
[rust.git] / src / librustc_session / lint.rs
1 use syntax_pos::{Symbol, sym};
2 pub use self::Level::*;
3
4 /// Setting for how to handle a lint.
5 #[derive(Clone, Copy, PartialEq, PartialOrd, Eq, Ord, Debug, Hash)]
6 pub enum Level {
7     Allow, Warn, Deny, Forbid,
8 }
9
10 rustc_data_structures::impl_stable_hash_via_hash!(Level);
11
12 impl Level {
13     /// Converts a level to a lower-case string.
14     pub fn as_str(self) -> &'static str {
15         match self {
16             Level::Allow => "allow",
17             Level::Warn => "warn",
18             Level::Deny => "deny",
19             Level::Forbid => "forbid",
20         }
21     }
22
23     /// Converts a lower-case string to a level.
24     pub fn from_str(x: &str) -> Option<Level> {
25         match x {
26             "allow" => Some(Level::Allow),
27             "warn" => Some(Level::Warn),
28             "deny" => Some(Level::Deny),
29             "forbid" => Some(Level::Forbid),
30             _ => None,
31         }
32     }
33
34     /// Converts a symbol to a level.
35     pub fn from_symbol(x: Symbol) -> Option<Level> {
36         match x {
37             sym::allow => Some(Level::Allow),
38             sym::warn => Some(Level::Warn),
39             sym::deny => Some(Level::Deny),
40             sym::forbid => Some(Level::Forbid),
41             _ => None,
42         }
43     }
44 }