about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMazdak Farrokhzad <twingoow@gmail.com>2020-01-09 05:20:28 +0100
committerMazdak Farrokhzad <twingoow@gmail.com>2020-01-11 07:42:26 +0100
commitf577b44712f0cba0404482b3e44d24ceb5b54a9e (patch)
treee266c59e5b19792b56bbc96b291f4ddc2bb72726
parent03bdfe9db3c7814e474413c4238f3eca7c2bf39a (diff)
downloadrust-f577b44712f0cba0404482b3e44d24ceb5b54a9e.tar.gz
rust-f577b44712f0cba0404482b3e44d24ceb5b54a9e.zip
move LintSource to levels
-rw-r--r--src/librustc/lint/levels.rs39
-rw-r--r--src/librustc/lint/mod.rs22
-rw-r--r--src/librustc/ty/context.rs6
3 files changed, 33 insertions, 34 deletions
diff --git a/src/librustc/lint/levels.rs b/src/librustc/lint/levels.rs
index 04028c03d43..d43bc57ea7a 100644
--- a/src/librustc/lint/levels.rs
+++ b/src/librustc/lint/levels.rs
@@ -1,8 +1,8 @@
 use std::cmp;
 
 use crate::ich::StableHashingContext;
+use crate::lint;
 use crate::lint::context::{CheckLintNameResult, LintStore};
-use crate::lint::{self, LintSource};
 use rustc_data_structures::fx::FxHashMap;
 use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
 use rustc_errors::{struct_span_err, Applicability, DiagnosticBuilder};
@@ -11,6 +11,7 @@ use rustc_session::lint::{builtin, Level, Lint, LintId};
 use rustc_session::Session;
 use rustc_span::source_map::MultiSpan;
 use rustc_span::symbol::{sym, Symbol};
+use rustc_span::Span;
 use syntax::ast;
 use syntax::attr;
 use syntax::print::pprust;
@@ -18,6 +19,22 @@ use syntax::sess::feature_err;
 
 use rustc_error_codes::*;
 
+/// How a lint level was set.
+#[derive(Clone, Copy, PartialEq, Eq, HashStable)]
+pub enum LintSource {
+    /// Lint is at the default level as declared
+    /// in rustc or a plugin.
+    Default,
+
+    /// Lint level was set by an attribute.
+    Node(Symbol, Span, Option<Symbol> /* RFC 2383 reason */),
+
+    /// Lint level was set by a command-line flag.
+    CommandLine(Symbol),
+}
+
+pub type LevelSource = (Level, LintSource);
+
 pub struct LintLevelSets {
     list: Vec<LintSet>,
     lint_cap: Level,
@@ -27,27 +44,27 @@ enum LintSet {
     CommandLine {
         // -A,-W,-D flags, a `Symbol` for the flag itself and `Level` for which
         // flag.
-        specs: FxHashMap<LintId, (Level, LintSource)>,
+        specs: FxHashMap<LintId, LevelSource>,
     },
 
     Node {
-        specs: FxHashMap<LintId, (Level, LintSource)>,
+        specs: FxHashMap<LintId, LevelSource>,
         parent: u32,
     },
 }
 
 impl LintLevelSets {
-    fn new() -> Self {
+    pub fn new() -> Self {
         LintLevelSets { list: Vec::new(), lint_cap: Level::Forbid }
     }
 
-    fn get_lint_level(
+    pub fn get_lint_level(
         &self,
         lint: &'static Lint,
         idx: u32,
-        aux: Option<&FxHashMap<LintId, (Level, LintSource)>>,
+        aux: Option<&FxHashMap<LintId, LevelSource>>,
         sess: &Session,
-    ) -> (Level, LintSource) {
+    ) -> LevelSource {
         let (level, mut src) = self.get_lint_id_level(LintId::of(lint), idx, aux);
 
         // If `level` is none then we actually assume the default level for this
@@ -59,7 +76,7 @@ impl LintLevelSets {
         // `allow(warnings)` in scope then we want to respect that instead.
         if level == Level::Warn {
             let (warnings_level, warnings_src) =
-                self.get_lint_id_level(LintId::of(lint::builtin::WARNINGS), idx, aux);
+                self.get_lint_id_level(LintId::of(builtin::WARNINGS), idx, aux);
             if let Some(configured_warning_level) = warnings_level {
                 if configured_warning_level != Level::Warn {
                     level = configured_warning_level;
@@ -79,11 +96,11 @@ impl LintLevelSets {
         return (level, src);
     }
 
-    fn get_lint_id_level(
+    pub fn get_lint_id_level(
         &self,
         id: LintId,
         mut idx: u32,
-        aux: Option<&FxHashMap<LintId, (Level, LintSource)>>,
+        aux: Option<&FxHashMap<LintId, LevelSource>>,
     ) -> (Option<Level>, LintSource) {
         if let Some(specs) = aux {
             if let Some(&(level, src)) = specs.get(&id) {
@@ -499,7 +516,7 @@ impl LintLevelMap {
         lint: &'static Lint,
         id: HirId,
         session: &Session,
-    ) -> Option<(Level, LintSource)> {
+    ) -> Option<LevelSource> {
         self.id_to_set.get(&id).map(|idx| self.sets.get_lint_level(lint, *idx, None, session))
     }
 }
diff --git a/src/librustc/lint/mod.rs b/src/librustc/lint/mod.rs
index 944868e7909..eefcb670d0e 100644
--- a/src/librustc/lint/mod.rs
+++ b/src/librustc/lint/mod.rs
@@ -18,8 +18,8 @@
 //! example) requires more effort. See `emit_lint` and `GatherNodeLevels`
 //! in `context.rs`.
 
+pub use self::levels::LintSource::{self, *};
 pub use self::Level::*;
-pub use self::LintSource::*;
 
 use crate::ty::TyCtxt;
 use rustc_data_structures::sync;
@@ -29,7 +29,6 @@ use rustc_session::lint::builtin::HardwiredLints;
 use rustc_session::{DiagnosticMessageId, Session};
 use rustc_span::hygiene::MacroKind;
 use rustc_span::source_map::{DesugaringKind, ExpnKind, MultiSpan};
-use rustc_span::symbol::Symbol;
 use rustc_span::Span;
 use syntax::ast;
 
@@ -38,9 +37,8 @@ pub use crate::lint::context::{
     LintContext, LintStore,
 };
 
-pub use rustc_session::lint::builtin;
+pub use rustc_session::lint::{builtin, LintArray, LintPass};
 pub use rustc_session::lint::{BufferedEarlyLint, FutureIncompatibleInfo, Level, Lint, LintId};
-pub use rustc_session::lint::{LintArray, LintPass};
 
 #[macro_export]
 macro_rules! late_lint_methods {
@@ -316,22 +314,6 @@ pub type EarlyLintPassObject = Box<dyn EarlyLintPass + sync::Send + sync::Sync +
 pub type LateLintPassObject =
     Box<dyn for<'a, 'tcx> LateLintPass<'a, 'tcx> + sync::Send + sync::Sync + 'static>;
 
-/// How a lint level was set.
-#[derive(Clone, Copy, PartialEq, Eq, HashStable)]
-pub enum LintSource {
-    /// Lint is at the default level as declared
-    /// in rustc or a plugin.
-    Default,
-
-    /// Lint level was set by an attribute.
-    Node(ast::Name, Span, Option<Symbol> /* RFC 2383 reason */),
-
-    /// Lint level was set by a command-line flag.
-    CommandLine(Symbol),
-}
-
-pub type LevelSource = (Level, LintSource);
-
 mod context;
 pub mod internal;
 mod levels;
diff --git a/src/librustc/ty/context.rs b/src/librustc/ty/context.rs
index 15ef6d44d46..86f82c1304c 100644
--- a/src/librustc/ty/context.rs
+++ b/src/librustc/ty/context.rs
@@ -20,9 +20,6 @@ use crate::mir::interpret::{Allocation, ConstValue, Scalar};
 use crate::mir::{
     interpret, BodyAndCache, Field, Local, Place, PlaceElem, ProjectionKind, Promoted,
 };
-use crate::session::config::CrateType;
-use crate::session::config::{BorrowckMode, OutputFilenames};
-use crate::session::Session;
 use crate::traits;
 use crate::traits::{Clause, Clauses, Goal, GoalKind, Goals};
 use crate::ty::free_region_map::FreeRegionMap;
@@ -49,6 +46,9 @@ use rustc_hir::def::{DefKind, Res};
 use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, DefIdSet, DefIndex, LOCAL_CRATE};
 use rustc_hir::{HirId, Node, TraitCandidate};
 use rustc_hir::{ItemKind, ItemLocalId, ItemLocalMap, ItemLocalSet};
+use rustc_session::config::CrateType;
+use rustc_session::config::{BorrowckMode, OutputFilenames};
+use rustc_session::Session;
 
 use arena::SyncDroplessArena;
 use rustc_data_structures::fx::{FxHashMap, FxHashSet};