diff options
| author | Eduard Burtescu <edy.burt@gmail.com> | 2016-03-29 12:12:01 +0300 |
|---|---|---|
| committer | Eduard Burtescu <edy.burt@gmail.com> | 2016-04-06 09:04:15 +0300 |
| commit | 7bebe80bc28ff818c7990061275fa0ad6c8b3686 (patch) | |
| tree | 55cbc78dd15233353b37d8242e5ba6434b20be2e /src/librustc/lint | |
| parent | ef4c7241f82c08848938b8b2dafed01535559ec0 (diff) | |
| download | rust-7bebe80bc28ff818c7990061275fa0ad6c8b3686.tar.gz rust-7bebe80bc28ff818c7990061275fa0ad6c8b3686.zip | |
syntax: dismantle ast_util.
Diffstat (limited to 'src/librustc/lint')
| -rw-r--r-- | src/librustc/lint/context.rs | 39 |
1 files changed, 7 insertions, 32 deletions
diff --git a/src/librustc/lint/context.rs b/src/librustc/lint/context.rs index 18c82201924..fd45f58327f 100644 --- a/src/librustc/lint/context.rs +++ b/src/librustc/lint/context.rs @@ -39,7 +39,6 @@ use std::cell::RefCell; use std::cmp; use std::default::Default as StdDefault; use std::mem; -use syntax::ast_util::{self, IdVisitingOperation}; use syntax::attr::{self, AttrMetaMethods}; use syntax::codemap::Span; use syntax::errors::DiagnosticBuilder; @@ -48,7 +47,7 @@ use syntax::ast; use syntax::attr::ThinAttributesExt; use hir; use hir::intravisit as hir_visit; -use hir::intravisit::IdVisitor; +use hir::intravisit::{IdVisitor, IdVisitingOperation}; use syntax::visit as ast_visit; /// Information about the registered lints. @@ -654,16 +653,6 @@ impl<'a> EarlyContext<'a> { level_stack: vec![], } } - - fn visit_ids<F>(&mut self, f: F) - where F: FnOnce(&mut ast_util::IdVisitor<EarlyContext>) - { - let mut v = ast_util::IdVisitor { - operation: self, - visited_outermost: false, - }; - f(&mut v); - } } impl<'a, 'tcx> LateContext<'a, 'tcx> { @@ -928,7 +917,6 @@ impl<'a, 'v> ast_visit::Visitor<'v> for EarlyContext<'a> { fn visit_item(&mut self, it: &ast::Item) { self.with_lint_attrs(&it.attrs, |cx| { run_lints!(cx, check_item, early_passes, it); - cx.visit_ids(|v| v.visit_item(it)); ast_visit::walk_item(cx, it); run_lints!(cx, check_item_post, early_passes, it); }) @@ -1042,7 +1030,6 @@ impl<'a, 'v> ast_visit::Visitor<'v> for EarlyContext<'a> { fn visit_trait_item(&mut self, trait_item: &ast::TraitItem) { self.with_lint_attrs(&trait_item.attrs, |cx| { run_lints!(cx, check_trait_item, early_passes, trait_item); - cx.visit_ids(|v| v.visit_trait_item(trait_item)); ast_visit::walk_trait_item(cx, trait_item); run_lints!(cx, check_trait_item_post, early_passes, trait_item); }); @@ -1051,7 +1038,6 @@ impl<'a, 'v> ast_visit::Visitor<'v> for EarlyContext<'a> { fn visit_impl_item(&mut self, impl_item: &ast::ImplItem) { self.with_lint_attrs(&impl_item.attrs, |cx| { run_lints!(cx, check_impl_item, early_passes, impl_item); - cx.visit_ids(|v| v.visit_impl_item(impl_item)); ast_visit::walk_impl_item(cx, impl_item); run_lints!(cx, check_impl_item_post, early_passes, impl_item); }); @@ -1099,18 +1085,6 @@ impl<'a, 'tcx> IdVisitingOperation for LateContext<'a, 'tcx> { } } } -impl<'a> IdVisitingOperation for EarlyContext<'a> { - fn visit_id(&mut self, id: ast::NodeId) { - match self.sess.lints.borrow_mut().remove(&id) { - None => {} - Some(lints) => { - for (lint_id, span, msg) in lints { - self.span_lint(lint_id.lint, span, &msg[..]) - } - } - } - } -} // This lint pass is defined here because it touches parts of the `LateContext` // that we don't want to expose. It records the lint level at certain AST @@ -1292,11 +1266,12 @@ pub fn check_ast_crate(sess: &Session, krate: &ast::Crate) { // Visit the whole crate. cx.with_lint_attrs(&krate.attrs, |cx| { - cx.visit_id(ast::CRATE_NODE_ID); - cx.visit_ids(|v| { - v.visited_outermost = true; - ast_visit::walk_crate(v, krate); - }); + // Lints may be assigned to the whole crate. + if let Some(lints) = cx.sess.lints.borrow_mut().remove(&ast::CRATE_NODE_ID) { + for (lint_id, span, msg) in lints { + cx.span_lint(lint_id.lint, span, &msg[..]) + } + } // since the root module isn't visited as an item (because it isn't an // item), warn for it here. |
