//! 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.
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 (
/// `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) { }
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)
}
}
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);
}
}
}
/// 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()
}
}