1
Fork 0

Convert lints to a trait-based infrastructure

The immediate benefits are

* moving the state specific to a single lint out of Context, and
* replacing the soup of function calls in the Visitor impl with
  more structured control flow

But this is also a step towards loadable lints.
This commit is contained in:
Keegan McAllister 2014-06-02 15:27:15 -07:00
parent 5d4c96a8f2
commit 69b6bc5eee
2 changed files with 1397 additions and 1092 deletions

View file

@ -11,16 +11,15 @@
//! Lints built in to rustc.
use metadata::csearch;
use middle::def;
use middle::def::*;
use middle::pat_util;
use middle::trans::adt; // for `adt::is_ffi_safe`
use middle::ty;
use middle::typeck::astconv::{ast_ty_to_ty, AstConv};
use middle::typeck::infer;
use middle::typeck;
use middle::privacy::ExportedItems;
use middle::{typeck, ty, def, pat_util};
use util::ppaux::{ty_to_str};
use lint::Context;
use util::nodemap::NodeSet;
use lint::{Context, LintPass};
use lint;
use std::cmp;
@ -33,16 +32,41 @@ use std::u16;
use std::u32;
use std::u64;
use std::u8;
use std::default::Default;
use syntax::abi;
use syntax::ast_map;
use syntax::attr::AttrMetaMethods;
use syntax::attr;
use syntax::codemap::Span;
use syntax::parse::token;
use syntax::visit::Visitor;
use syntax::{ast, ast_util, visit};
pub fn check_while_true_expr(cx: &Context, e: &ast::Expr) {
/// Doesn't actually warn; just gathers information for use by
/// checks in trans.
#[deriving(Default)]
pub struct GatherNodeLevels;
impl LintPass for GatherNodeLevels {
fn check_item(&mut self, cx: &Context, it: &ast::Item) {
match it.node {
ast::ItemEnum(..) => {
match cx.cur.find(&(lint::VariantSizeDifference as uint)) {
Some(&(lvl, src)) if lvl != lint::Allow => {
cx.insert_node_level(it.id, lint::VariantSizeDifference, lvl, src);
},
_ => { }
}
},
_ => { }
}
}
}
#[deriving(Default)]
pub struct WhileTrue;
impl LintPass for WhileTrue {
fn check_expr(&mut self, cx: &Context, e: &ast::Expr) {
match e.node {
ast::ExprWhile(cond, _) => {
match cond.node {
@ -62,10 +86,15 @@ pub fn check_while_true_expr(cx: &Context, e: &ast::Expr) {
}
_ => ()
}
}
}
pub fn check_unused_casts(cx: &Context, e: &ast::Expr) {
return match e.node {
#[deriving(Default)]
pub struct UnusedCasts;
impl LintPass for UnusedCasts {
fn check_expr(&mut self, cx: &Context, e: &ast::Expr) {
match e.node {
ast::ExprCast(expr, ty) => {
let t_t = ast_ty_to_ty(cx, &infer::new_infer_ctxt(cx.tcx), ty);
if ty::get(ty::expr_ty(cx.tcx, expr)).sty == ty::get(t_t).sty {
@ -74,34 +103,58 @@ pub fn check_unused_casts(cx: &Context, e: &ast::Expr) {
}
}
_ => ()
};
}
}
}
pub fn check_type_limits(cx: &Context, e: &ast::Expr) {
return match e.node {
ast::ExprUnary(ast::UnNeg, ex) => {
match ex.node {
pub struct TypeLimits {
/// Id of the last visited negated expression
negated_expr_id: ast::NodeId,
}
impl Default for TypeLimits {
fn default() -> TypeLimits {
TypeLimits {
negated_expr_id: -1,
}
}
}
impl LintPass for TypeLimits {
fn check_expr(&mut self, cx: &Context, e: &ast::Expr) {
match e.node {
ast::ExprUnary(ast::UnNeg, expr) => {
match expr.node {
ast::ExprLit(lit) => {
match lit.node {
ast::LitUint(..) => {
cx.span_lint(lint::UnsignedNegate, e.span,
"negation of unsigned int literal may be unintentional");
"negation of unsigned int literal may \
be unintentional");
},
_ => ()
}
},
_ => {
let t = ty::expr_ty(cx.tcx, ex);
let t = ty::expr_ty(cx.tcx, expr);
match ty::get(t).sty {
ty::ty_uint(_) => {
cx.span_lint(lint::UnsignedNegate, e.span,
"negation of unsigned int variable may be unintentional");
"negation of unsigned int variable may \
be unintentional");
},
_ => ()
}
}
};
// propagate negation, if the negation itself isn't negated
if self.negated_expr_id != e.id {
self.negated_expr_id = expr.id;
}
},
ast::ExprParen(expr) if self.negated_expr_id == e.id => {
self.negated_expr_id = expr.id;
},
ast::ExprBinary(binop, l, r) => {
if is_comparison(binop) && !check_limits(cx.tcx, binop, l, r) {
cx.span_lint(lint::TypeLimits, e.span,
@ -121,7 +174,7 @@ pub fn check_type_limits(cx: &Context, e: &ast::Expr) {
ast::LitIntUnsuffixed(v) => v,
_ => fail!()
};
if cx.negated_expr_id == e.id {
if self.negated_expr_id == e.id {
lit_val *= -1;
}
if lit_val < min || lit_val > max {
@ -244,9 +297,14 @@ pub fn check_type_limits(cx: &Context, e: &ast::Expr) {
_ => false
}
}
}
}
pub fn check_item_ctypes(cx: &Context, it: &ast::Item) {
#[deriving(Default)]
pub struct CTypes;
impl LintPass for CTypes {
fn check_item(&mut self, cx: &Context, it: &ast::Item) {
fn check_ty(cx: &Context, ty: &ast::Ty) {
match ty.node {
ast::TyPath(_, _, id) => {
@ -295,9 +353,14 @@ pub fn check_item_ctypes(cx: &Context, it: &ast::Item) {
}
_ => {/* nothing to do */ }
}
}
}
pub fn check_heap_type(cx: &Context, span: Span, ty: ty::t) {
#[deriving(Default)]
pub struct HeapMemory;
impl HeapMemory {
fn check_heap_type(&self, cx: &Context, span: Span, ty: ty::t) {
let xs = [lint::ManagedHeapMemory, lint::OwnedHeapMemory, lint::HeapMemory];
for &lint in xs.iter() {
if cx.get_level(lint) == lint::Allow { continue }
@ -337,14 +400,16 @@ pub fn check_heap_type(cx: &Context, span: Span, ty: ty::t) {
cx.span_lint(lint, span, m.as_slice());
}
}
}
}
pub fn check_heap_item(cx: &Context, it: &ast::Item) {
impl LintPass for HeapMemory {
fn check_item(&mut self, cx: &Context, it: &ast::Item) {
match it.node {
ast::ItemFn(..) |
ast::ItemTy(..) |
ast::ItemEnum(..) |
ast::ItemStruct(..) => check_heap_type(cx, it.span,
ast::ItemStruct(..) => self.check_heap_type(cx, it.span,
ty::node_id_to_type(cx.tcx,
it.id)),
_ => ()
@ -354,20 +419,26 @@ pub fn check_heap_item(cx: &Context, it: &ast::Item) {
match it.node {
ast::ItemStruct(struct_def, _) => {
for struct_field in struct_def.fields.iter() {
check_heap_type(cx, struct_field.span,
self.check_heap_type(cx, struct_field.span,
ty::node_id_to_type(cx.tcx,
struct_field.node.id));
}
}
_ => ()
}
}
fn check_expr(&mut self, cx: &Context, e: &ast::Expr) {
let ty = ty::expr_ty(cx.tcx, e);
self.check_heap_type(cx, e.span, ty);
}
}
struct RawPtrDerivingVisitor<'a> {
cx: &'a Context<'a>
}
impl<'a> Visitor<()> for RawPtrDerivingVisitor<'a> {
impl<'a> visit::Visitor<()> for RawPtrDerivingVisitor<'a> {
fn visit_ty(&mut self, ty: &ast::Ty, _: ()) {
static MSG: &'static str = "use of `#[deriving]` with a raw pointer";
match ty.node {
@ -381,7 +452,20 @@ impl<'a> Visitor<()> for RawPtrDerivingVisitor<'a> {
fn visit_block(&mut self, _: &ast::Block, _: ()) {}
}
pub fn check_raw_ptr_deriving(cx: &mut Context, item: &ast::Item) {
pub struct RawPointerDeriving {
checked_raw_pointers: NodeSet,
}
impl Default for RawPointerDeriving {
fn default() -> RawPointerDeriving {
RawPointerDeriving {
checked_raw_pointers: NodeSet::new(),
}
}
}
impl LintPass for RawPointerDeriving {
fn check_item(&mut self, cx: &Context, item: &ast::Item) {
if !attr::contains_name(item.attrs.as_slice(), "automatically_derived") {
return
}
@ -400,7 +484,7 @@ pub fn check_raw_ptr_deriving(cx: &mut Context, item: &ast::Item) {
Some(ast_map::NodeItem(item)) => item,
_ => return,
};
if !cx.checked_raw_pointers.insert(item.id) { return }
if !self.checked_raw_pointers.insert(item.id) { return }
match item.node {
ast::ItemStruct(..) | ast::ItemEnum(..) => {
let mut visitor = RawPtrDerivingVisitor { cx: cx };
@ -408,9 +492,14 @@ pub fn check_raw_ptr_deriving(cx: &mut Context, item: &ast::Item) {
}
_ => {}
}
}
}
pub fn check_unused_attribute(cx: &Context, attr: &ast::Attribute) {
#[deriving(Default)]
pub struct UnusedAttribute;
impl LintPass for UnusedAttribute {
fn check_attribute(&mut self, cx: &Context, attr: &ast::Attribute) {
static ATTRIBUTE_WHITELIST: &'static [&'static str] = &'static [
// FIXME: #14408 whitelist docs since rustdoc looks at them
"doc",
@ -478,14 +567,14 @@ pub fn check_unused_attribute(cx: &Context, attr: &ast::Attribute) {
cx.span_lint(lint::UnusedAttribute, attr.span, msg);
}
}
}
}
pub fn check_heap_expr(cx: &Context, e: &ast::Expr) {
let ty = ty::expr_ty(cx.tcx, e);
check_heap_type(cx, e.span, ty);
}
#[deriving(Default)]
pub struct PathStatement;
pub fn check_path_statement(cx: &Context, s: &ast::Stmt) {
impl LintPass for PathStatement {
fn check_stmt(&mut self, cx: &Context, s: &ast::Stmt) {
match s.node {
ast::StmtSemi(expr, _) => {
match expr.node {
@ -499,9 +588,14 @@ pub fn check_path_statement(cx: &Context, s: &ast::Stmt) {
}
_ => ()
}
}
}
pub fn check_unused_result(cx: &Context, s: &ast::Stmt) {
#[deriving(Default)]
pub struct UnusedMustUse;
impl LintPass for UnusedMustUse {
fn check_stmt(&mut self, cx: &Context, s: &ast::Stmt) {
let expr = match s.node {
ast::StmtSemi(expr, _) => expr,
_ => return
@ -548,9 +642,14 @@ pub fn check_unused_result(cx: &Context, s: &ast::Stmt) {
if !warned {
cx.span_lint(lint::UnusedResult, s.span, "unused result");
}
}
}
pub fn check_deprecated_owned_vector(cx: &Context, e: &ast::Expr) {
#[deriving(Default)]
pub struct DeprecatedOwnedVector;
impl LintPass for DeprecatedOwnedVector {
fn check_expr(&mut self, cx: &Context, e: &ast::Expr) {
let t = ty::expr_ty(cx.tcx, e);
match ty::get(t).sty {
ty::ty_uniq(t) => match ty::get(t).sty {
@ -562,9 +661,14 @@ pub fn check_deprecated_owned_vector(cx: &Context, e: &ast::Expr) {
},
_ => {}
}
}
}
pub fn check_item_non_camel_case_types(cx: &Context, it: &ast::Item) {
#[deriving(Default)]
pub struct NonCamelCaseTypes;
impl LintPass for NonCamelCaseTypes {
fn check_item(&mut self, cx: &Context, it: &ast::Item) {
fn is_camel_case(ident: ast::Ident) -> bool {
let ident = token::get_ident(ident);
assert!(!ident.get().is_empty());
@ -608,9 +712,43 @@ pub fn check_item_non_camel_case_types(cx: &Context, it: &ast::Item) {
}
_ => ()
}
}
}
pub fn check_snake_case(cx: &Context, sort: &str, ident: ast::Ident, span: Span) {
#[deriving(PartialEq)]
enum MethodContext {
TraitDefaultImpl,
TraitImpl,
PlainImpl
}
fn method_context(cx: &Context, m: &ast::Method) -> MethodContext {
let did = ast::DefId {
krate: ast::LOCAL_CRATE,
node: m.id
};
match cx.tcx.methods.borrow().find_copy(&did) {
None => cx.tcx.sess.span_bug(m.span, "missing method descriptor?!"),
Some(md) => {
match md.container {
ty::TraitContainer(..) => TraitDefaultImpl,
ty::ImplContainer(cid) => {
match ty::impl_trait_ref(cx.tcx, cid) {
Some(..) => TraitImpl,
None => PlainImpl
}
}
}
}
}
}
#[deriving(Default)]
pub struct NonSnakeCaseFunctions;
impl NonSnakeCaseFunctions {
fn check_snake_case(&self, cx: &Context, sort: &str, ident: ast::Ident, span: Span) {
fn is_snake_case(ident: ast::Ident) -> bool {
let ident = token::get_ident(ident);
assert!(!ident.get().is_empty());
@ -651,9 +789,37 @@ pub fn check_snake_case(cx: &Context, sort: &str, ident: ast::Ident, span: Span)
format!("{} `{}` should have a snake case name such as `{}`",
sort, s, to_snake_case(s.get())).as_slice());
}
}
}
pub fn check_item_non_uppercase_statics(cx: &Context, it: &ast::Item) {
impl LintPass for NonSnakeCaseFunctions {
fn check_fn(&mut self, cx: &Context,
fk: &visit::FnKind, _: &ast::FnDecl,
_: &ast::Block, span: Span, _: ast::NodeId) {
match *fk {
visit::FkMethod(ident, _, m) => match method_context(cx, m) {
PlainImpl
=> self.check_snake_case(cx, "method", ident, span),
TraitDefaultImpl
=> self.check_snake_case(cx, "trait method", ident, span),
_ => (),
},
visit::FkItemFn(ident, _, _, _)
=> self.check_snake_case(cx, "function", ident, span),
_ => (),
}
}
fn check_ty_method(&mut self, cx: &Context, t: &ast::TypeMethod) {
self.check_snake_case(cx, "trait method", t.ident, t.span);
}
}
#[deriving(Default)]
pub struct NonUppercaseStatics;
impl LintPass for NonUppercaseStatics {
fn check_item(&mut self, cx: &Context, it: &ast::Item) {
match it.node {
// only check static constants
ast::ItemStatic(_, ast::MutImmutable, _) => {
@ -671,9 +837,9 @@ pub fn check_item_non_uppercase_statics(cx: &Context, it: &ast::Item) {
}
_ => {}
}
}
}
pub fn check_pat_non_uppercase_statics(cx: &Context, p: &ast::Pat) {
fn check_pat(&mut self, cx: &Context, p: &ast::Pat) {
// Lint for constants that look like binding identifiers (#7526)
match (&p.node, cx.tcx.def_map.borrow().find(&p.id)) {
(&ast::PatIdent(_, ref path, _), Some(&def::DefStatic(_, false))) => {
@ -690,9 +856,14 @@ pub fn check_pat_non_uppercase_statics(cx: &Context, p: &ast::Pat) {
}
_ => {}
}
}
}
pub fn check_pat_uppercase_variable(cx: &Context, p: &ast::Pat) {
#[deriving(Default)]
pub struct UppercaseVariables;
impl LintPass for UppercaseVariables {
fn check_pat(&mut self, cx: &Context, p: &ast::Pat) {
match &p.node {
&ast::PatIdent(_, ref path, _) => {
match cx.tcx.def_map.borrow().find(&p.id) {
@ -713,16 +884,16 @@ pub fn check_pat_uppercase_variable(cx: &Context, p: &ast::Pat) {
}
_ => {}
}
}
}
pub fn check_struct_uppercase_variable(cx: &Context, s: &ast::StructDef) {
fn check_struct_def(&mut self, cx: &Context, s: &ast::StructDef,
_: ast::Ident, _: &ast::Generics, _: ast::NodeId) {
for sf in s.fields.iter() {
match sf.node {
ast::StructField_ { kind: ast::NamedField(ident, _), .. } => {
let s = token::get_ident(ident);
if s.get().char_at(0).is_uppercase() {
cx.span_lint(lint::
UppercaseVariables,
cx.span_lint(lint::UppercaseVariables,
sf.span,
"structure field names should start with a lowercase character");
}
@ -730,9 +901,14 @@ pub fn check_struct_uppercase_variable(cx: &Context, s: &ast::StructDef) {
_ => {}
}
}
}
}
pub fn check_unnecessary_parens_core(cx: &Context, value: &ast::Expr, msg: &str) {
#[deriving(Default)]
pub struct UnnecessaryParens;
impl UnnecessaryParens {
fn check_unnecessary_parens_core(&self, cx: &Context, value: &ast::Expr, msg: &str) {
match value.node {
ast::ExprParen(_) => {
cx.span_lint(lint::UnnecessaryParens, value.span,
@ -741,9 +917,11 @@ pub fn check_unnecessary_parens_core(cx: &Context, value: &ast::Expr, msg: &str)
}
_ => {}
}
}
}
pub fn check_unnecessary_parens_expr(cx: &Context, e: &ast::Expr) {
impl LintPass for UnnecessaryParens {
fn check_expr(&mut self, cx: &Context, e: &ast::Expr) {
let (value, msg) = match e.node {
ast::ExprIf(cond, _, _) => (cond, "`if` condition"),
ast::ExprWhile(cond, _) => (cond, "`while` condition"),
@ -753,10 +931,10 @@ pub fn check_unnecessary_parens_expr(cx: &Context, e: &ast::Expr) {
ast::ExprAssignOp(_, _, value) => (value, "assigned value"),
_ => return
};
check_unnecessary_parens_core(cx, value, msg);
}
self.check_unnecessary_parens_core(cx, value, msg);
}
pub fn check_unnecessary_parens_stmt(cx: &Context, s: &ast::Stmt) {
fn check_stmt(&mut self, cx: &Context, s: &ast::Stmt) {
let (value, msg) = match s.node {
ast::StmtDecl(decl, _) => match decl.node {
ast::DeclLocal(local) => match local.init {
@ -767,10 +945,15 @@ pub fn check_unnecessary_parens_stmt(cx: &Context, s: &ast::Stmt) {
},
_ => return
};
check_unnecessary_parens_core(cx, value, msg);
self.check_unnecessary_parens_core(cx, value, msg);
}
}
pub fn check_unused_unsafe(cx: &Context, e: &ast::Expr) {
#[deriving(Default)]
pub struct UnusedUnsafe;
impl LintPass for UnusedUnsafe {
fn check_expr(&mut self, cx: &Context, e: &ast::Expr) {
match e.node {
// Don't warn about generated blocks, that'll just pollute the output.
ast::ExprBlock(ref blk) => {
@ -782,9 +965,14 @@ pub fn check_unused_unsafe(cx: &Context, e: &ast::Expr) {
}
_ => ()
}
}
}
pub fn check_unsafe_block(cx: &Context, e: &ast::Expr) {
#[deriving(Default)]
pub struct UnsafeBlock;
impl LintPass for UnsafeBlock {
fn check_expr(&mut self, cx: &Context, e: &ast::Expr) {
match e.node {
// Don't warn about generated blocks, that'll just pollute the output.
ast::ExprBlock(ref blk) if blk.rules == ast::UnsafeBlock(ast::UserProvided) => {
@ -792,9 +980,14 @@ pub fn check_unsafe_block(cx: &Context, e: &ast::Expr) {
}
_ => ()
}
}
}
pub fn check_unused_mut_pat(cx: &Context, pats: &[@ast::Pat]) {
#[deriving(Default)]
pub struct UnusedMut;
impl UnusedMut {
fn check_unused_mut_pat(&self, cx: &Context, pats: &[@ast::Pat]) {
// collect all mutable pattern and group their NodeIDs by their Identifier to
// avoid false warnings in match arms with multiple patterns
let mut mutables = HashMap::new();
@ -827,6 +1020,42 @@ pub fn check_unused_mut_pat(cx: &Context, pats: &[@ast::Pat]) {
"variable does not need to be mutable");
}
}
}
}
impl LintPass for UnusedMut {
fn check_expr(&mut self, cx: &Context, e: &ast::Expr) {
match e.node {
ast::ExprMatch(_, ref arms) => {
for a in arms.iter() {
self.check_unused_mut_pat(cx, a.pats.as_slice())
}
}
_ => {}
}
}
fn check_stmt(&mut self, cx: &Context, s: &ast::Stmt) {
match s.node {
ast::StmtDecl(d, _) => {
match d.node {
ast::DeclLocal(l) => {
self.check_unused_mut_pat(cx, &[l.pat]);
},
_ => {}
}
},
_ => {}
}
}
fn check_fn(&mut self, cx: &Context,
_: &visit::FnKind, decl: &ast::FnDecl,
_: &ast::Block, _: Span, _: ast::NodeId) {
for a in decl.inputs.iter() {
self.check_unused_mut_pat(cx, &[a.pat]);
}
}
}
enum Allocation {
@ -834,7 +1063,11 @@ enum Allocation {
BoxAllocation
}
pub fn check_unnecessary_allocation(cx: &Context, e: &ast::Expr) {
#[deriving(Default)]
pub struct UnnecessaryAllocation;
impl LintPass for UnnecessaryAllocation {
fn check_expr(&mut self, cx: &Context, e: &ast::Expr) {
// Warn if string and vector literals with sigils, or boxing expressions,
// are immediately borrowed.
let allocation = match e.node {
@ -881,12 +1114,40 @@ pub fn check_unnecessary_allocation(cx: &Context, e: &ast::Expr) {
_ => {}
}
}
_ => ()
}
}
}
pub fn check_missing_doc_attrs(cx: &Context,
pub struct MissingDoc {
/// Set of nodes exported from this module.
exported_items: Option<ExportedItems>,
/// Stack of IDs of struct definitions.
struct_def_stack: Vec<ast::NodeId>,
/// Stack of whether #[doc(hidden)] is set
/// at each level which has lint attributes.
doc_hidden_stack: Vec<bool>,
}
impl Default for MissingDoc {
fn default() -> MissingDoc {
MissingDoc {
exported_items: None,
struct_def_stack: vec!(),
doc_hidden_stack: vec!(false),
}
}
}
impl MissingDoc {
fn doc_hidden(&self) -> bool {
*self.doc_hidden_stack.last().expect("empty doc_hidden_stack")
}
fn check_missing_doc_attrs(&self,
cx: &Context,
id: Option<ast::NodeId>,
attrs: &[ast::Attribute],
sp: Span,
@ -896,12 +1157,14 @@ pub fn check_missing_doc_attrs(cx: &Context,
if cx.tcx.sess.opts.test { return }
// `#[doc(hidden)]` disables missing_doc check.
if cx.is_doc_hidden { return }
if self.doc_hidden() { return }
// Only check publicly-visible items, using the result from the privacy pass. It's an option so
// the crate root can also use this function (it doesn't have a NodeId).
// Only check publicly-visible items, using the result from the privacy pass.
// It's an option so the crate root can also use this function (it doesn't
// have a NodeId).
let exported = self.exported_items.as_ref().expect("exported_items not set");
match id {
Some(ref id) if !cx.exported_items.contains(id) => return,
Some(ref id) if !exported.contains(id) => return,
_ => ()
}
@ -917,9 +1180,44 @@ pub fn check_missing_doc_attrs(cx: &Context,
format!("missing documentation for {}",
desc).as_slice());
}
}
}
pub fn check_missing_doc_item(cx: &Context, it: &ast::Item) {
impl LintPass for MissingDoc {
fn enter_lint_attrs(&mut self, _: &Context, attrs: &[ast::Attribute]) {
let doc_hidden = self.doc_hidden() || attrs.iter().any(|attr| {
attr.check_name("doc") && match attr.meta_item_list() {
None => false,
Some(l) => attr::contains_name(l.as_slice(), "hidden"),
}
});
self.doc_hidden_stack.push(doc_hidden);
}
fn exit_lint_attrs(&mut self, _: &Context, _: &[ast::Attribute]) {
self.doc_hidden_stack.pop().expect("empty doc_hidden_stack");
}
fn check_struct_def(&mut self, _: &Context,
_: &ast::StructDef, _: ast::Ident, _: &ast::Generics, id: ast::NodeId) {
self.struct_def_stack.push(id);
}
fn check_struct_def_post(&mut self, _: &Context,
_: &ast::StructDef, _: ast::Ident, _: &ast::Generics, id: ast::NodeId) {
let popped = self.struct_def_stack.pop().expect("empty struct_def_stack");
assert!(popped == id);
}
fn check_crate(&mut self, cx: &Context, exported: &ExportedItems, krate: &ast::Crate) {
// FIXME: clone to avoid lifetime trickiness
self.exported_items = Some(exported.clone());
self.check_missing_doc_attrs(cx, None, krate.attrs.as_slice(),
krate.span, "crate");
}
fn check_item(&mut self, cx: &Context, it: &ast::Item) {
let desc = match it.node {
ast::ItemFn(..) => "a function",
ast::ItemMod(..) => "a module",
@ -928,57 +1226,55 @@ pub fn check_missing_doc_item(cx: &Context, it: &ast::Item) {
ast::ItemTrait(..) => "a trait",
_ => return
};
check_missing_doc_attrs(cx,
Some(it.id),
it.attrs.as_slice(),
it.span,
desc);
}
self.check_missing_doc_attrs(cx, Some(it.id), it.attrs.as_slice(),
it.span, desc);
}
pub fn check_missing_doc_method(cx: &Context, m: &ast::Method) {
fn check_fn(&mut self, cx: &Context,
fk: &visit::FnKind, _: &ast::FnDecl, _: &ast::Block, _: Span, _: ast::NodeId) {
match *fk {
visit::FkMethod(_, _, m) => {
// If the method is an impl for a trait, don't doc.
if lint::method_context(cx, m) == lint::TraitImpl { return; }
if method_context(cx, m) == TraitImpl { return; }
// Otherwise, doc according to privacy. This will also check
// doc for default methods defined on traits.
check_missing_doc_attrs(cx,
Some(m.id),
m.attrs.as_slice(),
m.span,
"a method");
}
pub fn check_missing_doc_ty_method(cx: &Context, tm: &ast::TypeMethod) {
check_missing_doc_attrs(cx,
Some(tm.id),
tm.attrs.as_slice(),
tm.span,
"a type method");
}
pub fn check_missing_doc_struct_field(cx: &Context, sf: &ast::StructField) {
match sf.node.kind {
ast::NamedField(_, vis) if vis == ast::Public =>
check_missing_doc_attrs(cx,
Some(cx.cur_struct_def_id),
sf.node.attrs.as_slice(),
sf.span,
"a struct field"),
self.check_missing_doc_attrs(cx, Some(m.id), m.attrs.as_slice(),
m.span, "a method");
}
_ => {}
}
}
}
pub fn check_missing_doc_variant(cx: &Context, v: &ast::Variant) {
check_missing_doc_attrs(cx,
Some(v.node.id),
v.node.attrs.as_slice(),
v.span,
"a variant");
fn check_ty_method(&mut self, cx: &Context, tm: &ast::TypeMethod) {
self.check_missing_doc_attrs(cx, Some(tm.id), tm.attrs.as_slice(),
tm.span, "a type method");
}
fn check_struct_field(&mut self, cx: &Context, sf: &ast::StructField) {
match sf.node.kind {
ast::NamedField(_, vis) if vis == ast::Public => {
let cur_struct_def = *self.struct_def_stack.last().expect("empty struct_def_stack");
self.check_missing_doc_attrs(cx, Some(cur_struct_def),
sf.node.attrs.as_slice(), sf.span, "a struct field")
}
_ => {}
}
}
fn check_variant(&mut self, cx: &Context, v: &ast::Variant, _: &ast::Generics) {
self.check_missing_doc_attrs(cx, Some(v.node.id), v.node.attrs.as_slice(),
v.span, "a variant");
}
}
/// Checks for use of items with #[deprecated], #[experimental] and
/// #[unstable] (or none of them) attributes.
pub fn check_stability(cx: &Context, e: &ast::Expr) {
#[deriving(Default)]
pub struct Stability;
impl LintPass for Stability {
fn check_expr(&mut self, cx: &Context, e: &ast::Expr) {
let id = match e.node {
ast::ExprPath(..) | ast::ExprStruct(..) => {
match cx.tcx.def_map.borrow().find(&e.id) {
@ -1064,18 +1360,5 @@ pub fn check_stability(cx: &Context, e: &ast::Expr) {
};
cx.span_lint(lint, e.span, msg.as_slice());
}
pub fn check_enum_variant_sizes(cx: &mut Context, it: &ast::Item) {
match it.node {
ast::ItemEnum(..) => {
match cx.cur.find(&(lint::VariantSizeDifference as uint)) {
Some(&(lvl, src)) if lvl != lint::Allow => {
cx.node_levels.insert((it.id, lint::VariantSizeDifference), (lvl, src));
},
_ => { }
}
},
_ => { }
}
}

View file

@ -28,36 +28,94 @@
//! upon. As the ast is traversed, this keeps track of the current lint level
//! for all lint attributes.
//!
//! To add a new lint warning, all you need to do is to either invoke `add_lint`
//! on the session at the appropriate time, or write a few linting functions and
//! modify the Context visitor appropriately. If you're adding lints from the
//! Context itself, span_lint should be used instead of add_lint.
//! Most of the lints built into `rustc` are structs implementing `LintPass`,
//! and are defined within `builtin.rs`. To add a new lint you can define such
//! a struct and add it to the `builtin_lints!` macro invocation in this file.
//! `LintPass` itself is not a subtrait of `Default`, but the `builtin_lints!`
//! macro requires `Default` (usually via `deriving`).
//!
//! Some lints are defined elsewhere in the compiler and work by calling
//! `add_lint()` on the overall `Session` object.
//!
//! If you're adding lints to the `Context` infrastructure itself, defined in
//! this file, use `span_lint` instead of `add_lint`.
#![allow(non_camel_case_types)]
use driver::session;
use middle::dead::DEAD_CODE_LINT_STR;
use middle::privacy;
use middle::privacy::ExportedItems;
use middle::ty;
use middle::typeck::astconv::AstConv;
use middle::typeck::infer;
use util::nodemap::NodeSet;
use std::collections::HashMap;
use std::rc::Rc;
use std::gc::Gc;
use std::to_str::ToStr;
use std::cell::RefCell;
use std::default::Default;
use std::collections::SmallIntMap;
use syntax::ast_util::IdVisitingOperation;
use syntax::attr::AttrMetaMethods;
use syntax::attr;
use syntax::codemap::Span;
use syntax::parse::token::InternedString;
use syntax::visit::Visitor;
use syntax::visit::{Visitor, FnKind};
use syntax::{ast, ast_util, visit};
mod builtin;
/// Trait for types providing lint checks. Each method checks a single syntax
/// node, and should not invoke methods recursively (unlike `Visitor`). Each
/// method has a default do-nothing implementation. The trait also contains a
/// few lint-specific methods with no equivalent in `Visitor`.
//
// FIXME: eliminate the duplication with `Visitor`
trait LintPass {
fn check_crate(&mut self, _: &Context, _: &ExportedItems, _: &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) { }
fn check_foreign_item(&mut self, _: &Context, _: &ast::ForeignItem) { }
fn check_item(&mut self, _: &Context, _: &ast::Item) { }
fn check_local(&mut self, _: &Context, _: &ast::Local) { }
fn check_block(&mut self, _: &Context, _: &ast::Block) { }
fn check_stmt(&mut self, _: &Context, _: &ast::Stmt) { }
fn check_arm(&mut self, _: &Context, _: &ast::Arm) { }
fn check_pat(&mut self, _: &Context, _: &ast::Pat) { }
fn check_decl(&mut self, _: &Context, _: &ast::Decl) { }
fn check_expr(&mut self, _: &Context, _: &ast::Expr) { }
fn check_expr_post(&mut self, _: &Context, _: &ast::Expr) { }
fn check_ty(&mut self, _: &Context, _: &ast::Ty) { }
fn check_generics(&mut self, _: &Context, _: &ast::Generics) { }
fn check_fn(&mut self, _: &Context,
_: &FnKind, _: &ast::FnDecl, _: &ast::Block, _: Span, _: ast::NodeId) { }
fn check_ty_method(&mut self, _: &Context, _: &ast::TypeMethod) { }
fn check_trait_method(&mut self, _: &Context, _: &ast::TraitMethod) { }
fn check_struct_def(&mut self, _: &Context,
_: &ast::StructDef, _: ast::Ident, _: &ast::Generics, _: ast::NodeId) { }
fn check_struct_def_post(&mut self, _: &Context,
_: &ast::StructDef, _: ast::Ident, _: &ast::Generics, _: ast::NodeId) { }
fn check_struct_field(&mut self, _: &Context, _: &ast::StructField) { }
fn check_variant(&mut self, _: &Context, _: &ast::Variant, _: &ast::Generics) { }
fn check_opt_lifetime_ref(&mut self, _: &Context, _: Span, _: &Option<ast::Lifetime>) { }
fn check_lifetime_ref(&mut self, _: &Context, _: &ast::Lifetime) { }
fn check_lifetime_decl(&mut self, _: &Context, _: &ast::Lifetime) { }
fn check_explicit_self(&mut self, _: &Context, _: &ast::ExplicitSelf) { }
fn check_mac(&mut self, _: &Context, _: &ast::Mac) { }
fn check_path(&mut self, _: &Context, _: &ast::Path, _: ast::NodeId) { }
fn check_attribute(&mut self, _: &Context, _: &ast::Attribute) { }
/// Called when entering a syntax node that can have lint attributes such
/// as `#[allow(...)]`. Called with *all* the attributes of that node.
fn enter_lint_attrs(&mut self, _: &Context, _: &[ast::Attribute]) { }
/// Counterpart to `enter_lint_attrs`.
fn exit_lint_attrs(&mut self, _: &Context, _: &[ast::Attribute]) { }
}
type LintPassObject = Box<LintPass + 'static>;
#[deriving(Clone, Show, PartialEq, PartialOrd, Eq, Ord, Hash)]
pub enum LintId {
CTypes,
@ -438,30 +496,27 @@ struct Context<'a> {
cur: SmallIntMap<(Level, LintSource)>,
/// Context we're checking in (used to access fields like sess)
tcx: &'a ty::ctxt,
/// Items exported by the crate; used by the missing_doc lint.
exported_items: &'a privacy::ExportedItems,
/// The id of the current `ast::StructDef` being walked.
cur_struct_def_id: ast::NodeId,
/// Whether some ancestor of the current node was marked
/// #[doc(hidden)].
is_doc_hidden: bool,
/// When recursing into an attributed node of the ast which modifies lint
/// levels, this stack keeps track of the previous lint levels of whatever
/// was modified.
lint_stack: Vec<(LintId, Level, LintSource)>,
/// Id of the last visited negated expression
negated_expr_id: ast::NodeId,
/// Ids of structs/enums which have been checked for raw_pointer_deriving
checked_raw_pointers: NodeSet,
level_stack: Vec<(LintId, Level, LintSource)>,
/// Level of lints for certain NodeIds, stored here because the body of
/// the lint needs to run in trans.
node_levels: HashMap<(ast::NodeId, LintId), (Level, LintSource)>,
node_levels: RefCell<HashMap<(ast::NodeId, LintId), (Level, LintSource)>>,
/// Trait objects for each lint.
lints: Vec<RefCell<LintPassObject>>,
}
/// Convenience macro for calling a `LintPass` method on every lint in the context.
macro_rules! run_lints ( ($cx:expr, $f:ident, $($args:expr),*) => (
for tl in $cx.lints.iter() {
tl.borrow_mut().$f($cx, $($args),*);
}
))
pub fn emit_lint(level: Level, src: LintSource, msg: &str, span: Span,
lint_str: &str, tcx: &ty::ctxt) {
if level == Allow { return }
@ -581,7 +636,7 @@ impl<'a> Context<'a> {
lintname).as_slice());
} else if now != level {
let src = self.get_source(lint);
self.lint_stack.push((lint, now, src));
self.level_stack.push((lint, now, src));
pushed += 1;
self.set_level(lint, level, Node(meta.span));
}
@ -590,26 +645,13 @@ impl<'a> Context<'a> {
true
});
let old_is_doc_hidden = self.is_doc_hidden;
self.is_doc_hidden =
self.is_doc_hidden ||
attrs.iter()
.any(|attr| {
attr.name().equiv(&("doc")) &&
match attr.meta_item_list() {
None => false,
Some(l) => {
attr::contains_name(l.as_slice(), "hidden")
}
}
});
run_lints!(self, enter_lint_attrs, attrs);
f(self);
run_lints!(self, exit_lint_attrs, attrs);
// rollback
self.is_doc_hidden = old_is_doc_hidden;
for _ in range(0, pushed) {
let (lint, lvl, src) = self.lint_stack.pop().unwrap();
let (lint, lvl, src) = self.level_stack.pop().unwrap();
self.set_level(lint, lvl, src);
}
}
@ -622,6 +664,10 @@ impl<'a> Context<'a> {
};
f(&mut v);
}
fn insert_node_level(&self, id: ast::NodeId, lint: LintId, lvl: Level, src: LintSource) {
self.node_levels.borrow_mut().insert((id, lint), (lvl, src));
}
}
/// Check that every lint from the list of attributes satisfies `f`.
@ -680,35 +726,6 @@ pub fn contains_lint(attrs: &[ast::Attribute],
false
}
#[deriving(PartialEq)]
enum MethodContext {
TraitDefaultImpl,
TraitImpl,
PlainImpl
}
fn method_context(cx: &Context, m: &ast::Method) -> MethodContext {
let did = ast::DefId {
krate: ast::LOCAL_CRATE,
node: m.id
};
match cx.tcx.methods.borrow().find_copy(&did) {
None => cx.tcx.sess.span_bug(m.span, "missing method descriptor?!"),
Some(md) => {
match md.container {
ty::TraitContainer(..) => TraitDefaultImpl,
ty::ImplContainer(cid) => {
match ty::impl_trait_ref(cx.tcx, cid) {
Some(..) => TraitImpl,
None => PlainImpl
}
}
}
}
}
}
impl<'a> AstConv for Context<'a>{
fn tcx<'a>(&'a self) -> &'a ty::ctxt { self.tcx }
@ -728,175 +745,170 @@ impl<'a> AstConv for Context<'a>{
impl<'a> Visitor<()> for Context<'a> {
fn visit_item(&mut self, it: &ast::Item, _: ()) {
self.with_lint_attrs(it.attrs.as_slice(), |cx| {
builtin::check_enum_variant_sizes(cx, it);
builtin::check_item_ctypes(cx, it);
builtin::check_item_non_camel_case_types(cx, it);
builtin::check_item_non_uppercase_statics(cx, it);
builtin::check_heap_item(cx, it);
builtin::check_missing_doc_item(cx, it);
builtin::check_raw_ptr_deriving(cx, it);
run_lints!(cx, check_item, it);
cx.visit_ids(|v| v.visit_item(it, ()));
visit::walk_item(cx, it, ());
})
}
fn visit_foreign_item(&mut self, it: &ast::ForeignItem, _: ()) {
self.with_lint_attrs(it.attrs.as_slice(), |cx| {
run_lints!(cx, check_foreign_item, it);
visit::walk_foreign_item(cx, it, ());
})
}
fn visit_view_item(&mut self, i: &ast::ViewItem, _: ()) {
self.with_lint_attrs(i.attrs.as_slice(), |cx| {
run_lints!(cx, check_view_item, i);
cx.visit_ids(|v| v.visit_view_item(i, ()));
visit::walk_view_item(cx, i, ());
})
}
fn visit_pat(&mut self, p: &ast::Pat, _: ()) {
builtin::check_pat_non_uppercase_statics(self, p);
builtin::check_pat_uppercase_variable(self, p);
run_lints!(self, check_pat, p);
visit::walk_pat(self, p, ());
}
fn visit_expr(&mut self, e: &ast::Expr, _: ()) {
match e.node {
ast::ExprUnary(ast::UnNeg, expr) => {
// propagate negation, if the negation itself isn't negated
if self.negated_expr_id != e.id {
self.negated_expr_id = expr.id;
}
},
ast::ExprParen(expr) => if self.negated_expr_id == e.id {
self.negated_expr_id = expr.id
},
ast::ExprMatch(_, ref arms) => {
for a in arms.iter() {
builtin::check_unused_mut_pat(self, a.pats.as_slice());
}
},
_ => ()
};
builtin::check_while_true_expr(self, e);
builtin::check_stability(self, e);
builtin::check_unnecessary_parens_expr(self, e);
builtin::check_unused_unsafe(self, e);
builtin::check_unsafe_block(self, e);
builtin::check_unnecessary_allocation(self, e);
builtin::check_heap_expr(self, e);
builtin::check_type_limits(self, e);
builtin::check_unused_casts(self, e);
run_lints!(self, check_expr, e);
visit::walk_expr(self, e, ());
}
fn visit_stmt(&mut self, s: &ast::Stmt, _: ()) {
builtin::check_path_statement(self, s);
builtin::check_unused_result(self, s);
builtin::check_unnecessary_parens_stmt(self, s);
match s.node {
ast::StmtDecl(d, _) => {
match d.node {
ast::DeclLocal(l) => {
builtin::check_unused_mut_pat(self, &[l.pat]);
},
_ => {}
}
},
_ => {}
}
run_lints!(self, check_stmt, s);
visit::walk_stmt(self, s, ());
}
fn visit_fn(&mut self, fk: &visit::FnKind, decl: &ast::FnDecl,
fn visit_fn(&mut self, fk: &FnKind, decl: &ast::FnDecl,
body: &ast::Block, span: Span, id: ast::NodeId, _: ()) {
let recurse = |this: &mut Context| {
visit::walk_fn(this, fk, decl, body, span, ());
};
for a in decl.inputs.iter(){
builtin::check_unused_mut_pat(self, &[a.pat]);
}
match *fk {
visit::FkMethod(ident, _, m) => {
visit::FkMethod(_, _, m) => {
self.with_lint_attrs(m.attrs.as_slice(), |cx| {
builtin::check_missing_doc_method(cx, m);
match method_context(cx, m) {
PlainImpl
=> builtin::check_snake_case(cx, "method", ident, span),
TraitDefaultImpl
=> builtin::check_snake_case(cx, "trait method", ident, span),
_ => (),
}
run_lints!(cx, check_fn, fk, decl, body, span, id);
cx.visit_ids(|v| {
v.visit_fn(fk, decl, body, span, id, ());
});
recurse(cx);
visit::walk_fn(cx, fk, decl, body, span, ());
})
},
visit::FkItemFn(ident, _, _, _) => {
builtin::check_snake_case(self, "function", ident, span);
recurse(self);
_ => {
run_lints!(self, check_fn, fk, decl, body, span, id);
visit::walk_fn(self, fk, decl, body, span, ());
}
_ => recurse(self),
}
}
fn visit_ty_method(&mut self, t: &ast::TypeMethod, _: ()) {
self.with_lint_attrs(t.attrs.as_slice(), |cx| {
builtin::check_missing_doc_ty_method(cx, t);
builtin::check_snake_case(cx, "trait method", t.ident, t.span);
run_lints!(cx, check_ty_method, t);
visit::walk_ty_method(cx, t, ());
})
}
fn visit_struct_def(&mut self,
s: &ast::StructDef,
_: ast::Ident,
_: &ast::Generics,
ident: ast::Ident,
g: &ast::Generics,
id: ast::NodeId,
_: ()) {
builtin::check_struct_uppercase_variable(self, s);
let old_id = self.cur_struct_def_id;
self.cur_struct_def_id = id;
run_lints!(self, check_struct_def, s, ident, g, id);
visit::walk_struct_def(self, s, ());
self.cur_struct_def_id = old_id;
run_lints!(self, check_struct_def_post, s, ident, g, id);
}
fn visit_struct_field(&mut self, s: &ast::StructField, _: ()) {
self.with_lint_attrs(s.node.attrs.as_slice(), |cx| {
builtin::check_missing_doc_struct_field(cx, s);
run_lints!(cx, check_struct_field, s);
visit::walk_struct_field(cx, s, ());
})
}
fn visit_variant(&mut self, v: &ast::Variant, g: &ast::Generics, _: ()) {
self.with_lint_attrs(v.node.attrs.as_slice(), |cx| {
builtin::check_missing_doc_variant(cx, v);
run_lints!(cx, check_variant, v, g);
visit::walk_variant(cx, v, g, ());
})
}
// FIXME(#10894) should continue recursing
fn visit_ty(&mut self, _t: &ast::Ty, _: ()) {}
fn visit_ty(&mut self, t: &ast::Ty, _: ()) {
run_lints!(self, check_ty, t);
}
fn visit_ident(&mut self, sp: Span, id: ast::Ident, _: ()) {
run_lints!(self, check_ident, sp, id);
}
fn visit_mod(&mut self, m: &ast::Mod, s: Span, n: ast::NodeId, _: ()) {
run_lints!(self, check_mod, m, s, n);
visit::walk_mod(self, m, ());
}
fn visit_local(&mut self, l: &ast::Local, _: ()) {
run_lints!(self, check_local, l);
visit::walk_local(self, l, ());
}
fn visit_block(&mut self, b: &ast::Block, _: ()) {
run_lints!(self, check_block, b);
visit::walk_block(self, b, ());
}
fn visit_arm(&mut self, a: &ast::Arm, _: ()) {
run_lints!(self, check_arm, a);
visit::walk_arm(self, a, ());
}
fn visit_decl(&mut self, d: &ast::Decl, _: ()) {
run_lints!(self, check_decl, d);
visit::walk_decl(self, d, ());
}
fn visit_expr_post(&mut self, e: &ast::Expr, _: ()) {
run_lints!(self, check_expr_post, e);
}
fn visit_generics(&mut self, g: &ast::Generics, _: ()) {
run_lints!(self, check_generics, g);
visit::walk_generics(self, g, ());
}
fn visit_trait_method(&mut self, m: &ast::TraitMethod, _: ()) {
run_lints!(self, check_trait_method, m);
visit::walk_trait_method(self, m, ());
}
fn visit_opt_lifetime_ref(&mut self, sp: Span, lt: &Option<ast::Lifetime>, _: ()) {
run_lints!(self, check_opt_lifetime_ref, sp, lt);
}
fn visit_lifetime_ref(&mut self, lt: &ast::Lifetime, _: ()) {
run_lints!(self, check_lifetime_ref, lt);
}
fn visit_lifetime_decl(&mut self, lt: &ast::Lifetime, _: ()) {
run_lints!(self, check_lifetime_decl, lt);
}
fn visit_explicit_self(&mut self, es: &ast::ExplicitSelf, _: ()) {
run_lints!(self, check_explicit_self, es);
visit::walk_explicit_self(self, es, ());
}
fn visit_mac(&mut self, mac: &ast::Mac, _: ()) {
run_lints!(self, check_mac, mac);
visit::walk_mac(self, mac, ());
}
fn visit_path(&mut self, p: &ast::Path, id: ast::NodeId, _: ()) {
run_lints!(self, check_path, p, id);
visit::walk_path(self, p, ());
}
fn visit_attribute(&mut self, attr: &ast::Attribute, _: ()) {
builtin::check_unused_attribute(self, attr);
run_lints!(self, check_attribute, attr);
}
}
@ -914,19 +926,33 @@ impl<'a> IdVisitingOperation for Context<'a> {
}
pub fn check_crate(tcx: &ty::ctxt,
exported_items: &privacy::ExportedItems,
exported_items: &ExportedItems,
krate: &ast::Crate) {
macro_rules! builtin_lints (( $($name:ident),*, ) => (
vec!($(
{
let obj: builtin::$name = Default::default();
RefCell::new(box obj as LintPassObject)
}
),*)
))
let builtin_lints = builtin_lints!(
GatherNodeLevels, WhileTrue, UnusedCasts, TypeLimits, CTypes,
HeapMemory, RawPointerDeriving, UnusedAttribute,
PathStatement, UnusedMustUse, DeprecatedOwnedVector,
NonCamelCaseTypes, NonSnakeCaseFunctions, NonUppercaseStatics,
UppercaseVariables, UnnecessaryParens, UnusedUnsafe, UnsafeBlock,
UnusedMut, UnnecessaryAllocation, MissingDoc, Stability,
);
let mut cx = Context {
dict: get_lint_dict(),
cur: SmallIntMap::new(),
tcx: tcx,
exported_items: exported_items,
cur_struct_def_id: -1,
is_doc_hidden: false,
lint_stack: Vec::new(),
negated_expr_id: -1,
checked_raw_pointers: NodeSet::new(),
node_levels: HashMap::new(),
level_stack: Vec::new(),
node_levels: RefCell::new(HashMap::new()),
lints: builtin_lints,
};
// Install default lint levels, followed by the command line levels, and
@ -946,13 +972,9 @@ pub fn check_crate(tcx: &ty::ctxt,
visit::walk_crate(v, krate, ());
});
// since the root module isn't visited as an item (because it isn't an item), warn for it
// here.
builtin::check_missing_doc_attrs(cx,
None,
krate.attrs.as_slice(),
krate.span,
"crate");
// since the root module isn't visited as an item (because it isn't an
// item), warn for it here.
run_lints!(cx, check_crate, exported_items, krate);
visit::walk_crate(cx, krate, ());
});
@ -967,5 +989,5 @@ pub fn check_crate(tcx: &ty::ctxt,
}
tcx.sess.abort_if_errors();
*tcx.node_lint_levels.borrow_mut() = cx.node_levels;
*tcx.node_lint_levels.borrow_mut() = cx.node_levels.unwrap();
}