]> git.lizzy.rs Git - rust.git/commitdiff
Move Lint to rustc_session
authorMark Rousskov <mark.simulacrum@gmail.com>
Tue, 12 Nov 2019 16:52:26 +0000 (11:52 -0500)
committerMark Rousskov <mark.simulacrum@gmail.com>
Tue, 3 Dec 2019 17:18:32 +0000 (12:18 -0500)
This commit breaks early-lint registration, which will be fixed in the
next commit. This movement will allow essentially all crates in the compiler
tree to declare lints (though not lint passes).

src/librustc/lint/levels.rs
src/librustc/lint/mod.rs
src/librustc/session/mod.rs
src/librustc_session/lint.rs

index 619ca724214c87b5d1464d563568e910bcebd60b..ca246994e5c8433da1f70c0aab54315fef1d1ed5 100644 (file)
@@ -93,7 +93,7 @@ fn get_lint_level(&self,
 
         // If `level` is none then we actually assume the default level for this
         // lint.
-        let mut level = level.unwrap_or_else(|| lint.default_level(sess));
+        let mut level = level.unwrap_or_else(|| lint.default_level(sess.edition()));
 
         // If we're about to issue a warning, check at the last minute for any
         // directives against the warnings "lint". If, for example, there's an
index 0cc2c356a1551880a103a35e56fb940c9d39d59f..3abda8023f3744a2dda7c0858953990e60487621 100644 (file)
@@ -27,8 +27,6 @@
 use crate::hir::intravisit;
 use crate::hir;
 use crate::lint::builtin::BuiltinLintDiagnostics;
-use crate::lint::builtin::parser::{ILL_FORMED_ATTRIBUTE_INPUT, META_VARIABLE_MISUSE};
-use crate::lint::builtin::parser::INCOMPLETE_INCLUDE;
 use crate::session::{Session, DiagnosticMessageId};
 use crate::ty::TyCtxt;
 use crate::ty::query::Providers;
@@ -37,8 +35,6 @@
 use std::{hash, ptr};
 use syntax::ast;
 use syntax::source_map::{MultiSpan, ExpnKind, DesugaringKind};
-use syntax::early_buffered_lints::BufferedEarlyLintId;
-use syntax::edition::Edition;
 use syntax::symbol::Symbol;
 use syntax_pos::hygiene::MacroKind;
 use syntax_pos::Span;
                         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 {
-    /// A string identifier for the lint.
-    ///
-    /// This identifies the lint in attributes and in command-line arguments.
-    /// In those contexts it is always lowercase, but this field is compared
-    /// in a way which is case-insensitive for ASCII characters. This allows
-    /// `declare_lint!()` invocations to follow the convention of upper-case
-    /// statics without repeating the name.
-    ///
-    /// The name is written with underscores, e.g., "unused_imports".
-    /// On the command line, underscores become dashes.
-    pub name: &'static str,
-
-    /// Default level for the lint.
-    pub default_level: Level,
-
-    /// Description of the lint or the issue it detects.
-    ///
-    /// e.g., "imports that are never used"
-    pub desc: &'static str,
-
-    /// Starting at the given edition, default to the given lint level. If this is `None`, then use
-    /// `default_level`.
-    pub edition_lint_opts: Option<(Edition, Level)>,
-
-    /// `true` if this lint is reported even inside expansions of external macros.
-    pub report_in_external_macro: bool,
-
-    pub future_incompatible: Option<FutureIncompatibleInfo>,
-
-    pub is_plugin: bool,
-}
-
-/// Extra information for a future incompatibility lint.
-#[derive(Copy, Clone, Debug)]
-pub struct FutureIncompatibleInfo {
-    /// e.g., a URL for an issue/PR/RFC or error code
-    pub reference: &'static str,
-    /// If this is an edition fixing lint, the edition in which
-    /// this lint becomes obsolete
-    pub edition: Option<Edition>,
-}
-
-impl Lint {
-    pub const fn default_fields_for_macro() -> Self {
-        Lint {
-            name: "",
-            default_level: Level::Forbid,
-            desc: "",
-            edition_lint_opts: None,
-            is_plugin: false,
-            report_in_external_macro: false,
-            future_incompatible: None,
-        }
-    }
-
-    /// Returns the `rust::lint::Lint` for a `syntax::early_buffered_lints::BufferedEarlyLintId`.
-    pub fn from_parser_lint_id(lint_id: BufferedEarlyLintId) -> &'static Self {
-        match lint_id {
-            BufferedEarlyLintId::IllFormedAttributeInput => ILL_FORMED_ATTRIBUTE_INPUT,
-            BufferedEarlyLintId::MetaVariableMisuse => META_VARIABLE_MISUSE,
-            BufferedEarlyLintId::IncompleteInclude => INCOMPLETE_INCLUDE,
-        }
-    }
-
-    /// Gets the lint's name, with ASCII letters converted to lowercase.
-    pub fn name_lower(&self) -> String {
-        self.name.to_ascii_lowercase()
-    }
-
-    pub fn default_level(&self, session: &Session) -> Level {
-        self.edition_lint_opts
-            .filter(|(e, _)| *e <= session.edition())
-            .map(|(_, l)| l)
-            .unwrap_or(self.default_level)
-    }
-}
+pub use rustc_session::lint::{Lint, Level, FutureIncompatibleInfo};
 
 /// Declares a static item of type `&'static Lint`.
 #[macro_export]
index fa32e666e89f7f60d5a790586e0d892359ba37d7..0e1e03e67b88f9b1a557806fa428c8fedce03132 100644 (file)
@@ -5,7 +5,7 @@
 use rustc_data_structures::fingerprint::Fingerprint;
 use rustc_data_structures::fx::{FxHashMap, FxHashSet};
 
-use crate::lint;
+use rustc_session::lint;
 use crate::session::config::{OutputType, PrintRequest, Sanitizer, SwitchWithOptPath};
 use crate::session::search_paths::{PathKind, SearchPath};
 use crate::util::common::{duration_to_secs_str, ErrorReported};
index 44b1f4ec25403742e6a10b2f089cbad7e0099f49..1078b46589d50900eaf6dcbaab31049bebf21ba3 100644 (file)
@@ -1,4 +1,5 @@
 use syntax_pos::{Symbol, sym};
+use syntax_pos::edition::Edition;
 pub use self::Level::*;
 
 /// Setting for how to handle a lint.
@@ -42,3 +43,74 @@ pub fn from_symbol(x: Symbol) -> Option<Level> {
         }
     }
 }
+
+/// Specification of a single lint.
+#[derive(Copy, Clone, Debug)]
+pub struct Lint {
+    /// A string identifier for the lint.
+    ///
+    /// This identifies the lint in attributes and in command-line arguments.
+    /// In those contexts it is always lowercase, but this field is compared
+    /// in a way which is case-insensitive for ASCII characters. This allows
+    /// `declare_lint!()` invocations to follow the convention of upper-case
+    /// statics without repeating the name.
+    ///
+    /// The name is written with underscores, e.g., "unused_imports".
+    /// On the command line, underscores become dashes.
+    pub name: &'static str,
+
+    /// Default level for the lint.
+    pub default_level: Level,
+
+    /// Description of the lint or the issue it detects.
+    ///
+    /// e.g., "imports that are never used"
+    pub desc: &'static str,
+
+    /// Starting at the given edition, default to the given lint level. If this is `None`, then use
+    /// `default_level`.
+    pub edition_lint_opts: Option<(Edition, Level)>,
+
+    /// `true` if this lint is reported even inside expansions of external macros.
+    pub report_in_external_macro: bool,
+
+    pub future_incompatible: Option<FutureIncompatibleInfo>,
+
+    pub is_plugin: bool,
+}
+
+/// Extra information for a future incompatibility lint.
+#[derive(Copy, Clone, Debug)]
+pub struct FutureIncompatibleInfo {
+    /// e.g., a URL for an issue/PR/RFC or error code
+    pub reference: &'static str,
+    /// If this is an edition fixing lint, the edition in which
+    /// this lint becomes obsolete
+    pub edition: Option<Edition>,
+}
+
+impl Lint {
+    pub const fn default_fields_for_macro() -> Self {
+        Lint {
+            name: "",
+            default_level: Level::Forbid,
+            desc: "",
+            edition_lint_opts: None,
+            is_plugin: false,
+            report_in_external_macro: false,
+            future_incompatible: None,
+        }
+    }
+
+    /// Gets the lint's name, with ASCII letters converted to lowercase.
+    pub fn name_lower(&self) -> String {
+        self.name.to_ascii_lowercase()
+    }
+
+    pub fn default_level(&self, edition: Edition) -> Level {
+        self.edition_lint_opts
+            .filter(|(e, _)| *e <= edition)
+            .map(|(_, l)| l)
+            .unwrap_or(self.default_level)
+    }
+}