Skip to content

Commit

Permalink
Move Level to rustc_session
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark-Simulacrum committed Dec 3, 2019
1 parent 4351698 commit 433e546
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 41 deletions.
44 changes: 3 additions & 41 deletions src/librustc/lint/mod.rs
Expand Up @@ -39,14 +39,16 @@ use syntax::ast;
use syntax::source_map::{MultiSpan, ExpnKind, DesugaringKind};
use syntax::early_buffered_lints::BufferedEarlyLintId;
use syntax::edition::Edition;
use syntax::symbol::{Symbol, sym};
use syntax::symbol::Symbol;
use syntax_pos::hygiene::MacroKind;
use syntax_pos::Span;

pub use crate::lint::context::{LateContext, EarlyContext, LintContext, LintStore,
check_crate, check_ast_crate, late_lint_mod, CheckLintNameResult,
BufferedEarlyLint,};

pub use rustc_session::lint::Level;

/// Specification of a single lint.
#[derive(Copy, Clone, Debug)]
pub struct Lint {
Expand Down Expand Up @@ -542,46 +544,6 @@ impl LintId {
}
}

/// Setting for how to handle a lint.
#[derive(Clone, Copy, PartialEq, PartialOrd, Eq, Ord, Debug, Hash, HashStable)]
pub enum Level {
Allow, Warn, Deny, Forbid,
}

impl Level {
/// Converts a level to a lower-case string.
pub fn as_str(self) -> &'static str {
match self {
Allow => "allow",
Warn => "warn",
Deny => "deny",
Forbid => "forbid",
}
}

/// Converts a lower-case string to a level.
pub fn from_str(x: &str) -> Option<Level> {
match x {
"allow" => Some(Allow),
"warn" => Some(Warn),
"deny" => Some(Deny),
"forbid" => Some(Forbid),
_ => None,
}
}

/// Converts a symbol to a level.
pub fn from_symbol(x: Symbol) -> Option<Level> {
match x {
sym::allow => Some(Allow),
sym::warn => Some(Warn),
sym::deny => Some(Deny),
sym::forbid => Some(Forbid),
_ => None,
}
}
}

/// How a lint level was set.
#[derive(Clone, Copy, PartialEq, Eq, HashStable)]
pub enum LintSource {
Expand Down
1 change: 1 addition & 0 deletions src/librustc_session/lib.rs
@@ -1,2 +1,3 @@
pub mod cgu_reuse_tracker;
pub mod utils;
pub mod lint;
44 changes: 44 additions & 0 deletions src/librustc_session/lint.rs
@@ -0,0 +1,44 @@
use syntax_pos::{Symbol, sym};
pub use self::Level::*;

/// Setting for how to handle a lint.
#[derive(Clone, Copy, PartialEq, PartialOrd, Eq, Ord, Debug, Hash)]
pub enum Level {
Allow, Warn, Deny, Forbid,
}

rustc_data_structures::impl_stable_hash_via_hash!(Level);

impl Level {
/// Converts a level to a lower-case string.
pub fn as_str(self) -> &'static str {
match self {
Level::Allow => "allow",
Level::Warn => "warn",
Level::Deny => "deny",
Level::Forbid => "forbid",
}
}

/// Converts a lower-case string to a level.
pub fn from_str(x: &str) -> Option<Level> {
match x {
"allow" => Some(Level::Allow),
"warn" => Some(Level::Warn),
"deny" => Some(Level::Deny),
"forbid" => Some(Level::Forbid),
_ => None,
}
}

/// Converts a symbol to a level.
pub fn from_symbol(x: Symbol) -> Option<Level> {
match x {
sym::allow => Some(Level::Allow),
sym::warn => Some(Level::Warn),
sym::deny => Some(Level::Deny),
sym::forbid => Some(Level::Forbid),
_ => None,
}
}
}

0 comments on commit 433e546

Please sign in to comment.