]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc/lint/mod.rs
auto merge of #15999 : Kimundi/rust/fix_folder, r=nikomatsakis
[rust.git] / src / librustc / lint / mod.rs
index ea7023b3bc82c944955552c7882bab1946109420..9224647bc798b19eeb187f3e51a9c0537a564a5b 100644 (file)
@@ -19,6 +19,7 @@
 //! Most lints can be written as `LintPass` instances. These run just before
 //! translation to LLVM bytecode. The `LintPass`es built into rustc are defined
 //! within `builtin.rs`, which has further comments on how to add such a lint.
+//! rustc can also load user-defined lint plugins via the plugin mechanism.
 //!
 //! Some of rustc's lints are defined elsewhere in the compiler and work by
 //! calling `add_lint()` on the overall `Session` object. This works when
 
 #![macro_escape]
 
-use middle::privacy::ExportedItems;
 use std::hash;
+use std::ascii::AsciiExt;
 use syntax::codemap::Span;
 use syntax::visit::FnKind;
 use syntax::ast;
 
-pub use lint::context::{Context, LintStore, raw_emit_lint, check_crate};
+pub use lint::context::{Context, LintStore, raw_emit_lint, check_crate, gather_attrs};
 
 /// Specification of a single lint.
 pub struct Lint {
     /// A string identifier for the lint.
     ///
-    /// Written with underscores, e.g. "unused_imports".
-    /// This identifies the lint in attributes and in
-    /// command-line arguments. On the command line,
-    /// underscores become dashes.
+    /// 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.
@@ -56,6 +61,13 @@ pub struct Lint {
     pub desc: &'static str,
 }
 
+impl Lint {
+    /// Get the lint's name, with ASCII letters converted to lowercase.
+    pub fn name_lower(&self) -> String {
+        self.name.to_ascii_lower()
+    }
+}
+
 /// Build a `Lint` initializer.
 #[macro_export]
 macro_rules! lint_initializer (
@@ -110,7 +122,7 @@ pub trait LintPass {
     /// `Lint`, make it a private `static` item in its own module.
     fn get_lints(&self) -> LintArray;
 
-    fn check_crate(&mut self, _: &Context, _: &ExportedItems, _: &ast::Crate) { }
+    fn check_crate(&mut self, _: &Context, _: &ast::Crate) { }
     fn check_ident(&mut self, _: &Context, _: Span, _: ast::Ident) { }
     fn check_mod(&mut self, _: &Context, _: &ast::Mod, _: Span, _: ast::NodeId) { }
     fn check_view_item(&mut self, _: &Context, _: &ast::ViewItem) { }
@@ -164,7 +176,7 @@ pub struct LintId {
 
 impl PartialEq for LintId {
     fn eq(&self, other: &LintId) -> bool {
-        (self.lint as *Lint) == (other.lint as *Lint)
+        (self.lint as *const Lint) == (other.lint as *const Lint)
     }
 }
 
@@ -172,7 +184,7 @@ impl Eq for LintId { }
 
 impl<S: hash::Writer> hash::Hash<S> for LintId {
     fn hash(&self, state: &mut S) {
-        let ptr = self.lint as *Lint;
+        let ptr = self.lint as *const Lint;
         ptr.hash(state);
     }
 }
@@ -186,8 +198,8 @@ pub fn of(lint: &'static Lint) -> LintId {
     }
 
     /// Get the name of the lint.
-    pub fn as_str(&self) -> &'static str {
-        self.lint.name
+    pub fn as_str(&self) -> String {
+        self.lint.name_lower()
     }
 }