1
Fork 0

Auto merge of #28192 - Manishearth:lint-hir, r=eddyb

LintPass still uses the AST, though there isn't any need to. This makes it hard to move lints to the HIR.

r? @eddyb @nrc
This commit is contained in:
bors 2015-09-03 15:42:16 +00:00
commit 0762f58c11
7 changed files with 328 additions and 337 deletions

View file

@ -37,12 +37,14 @@ use std::cell::RefCell;
use std::cmp; use std::cmp;
use std::mem; use std::mem;
use syntax::ast_util::IdVisitingOperation; use syntax::ast_util::IdVisitingOperation;
use syntax::attr::AttrMetaMethods; use rustc_front::attr::{self, AttrMetaMethods};
use syntax::attr; use rustc_front::util;
use syntax::codemap::Span; use syntax::codemap::Span;
use syntax::visit::{Visitor, FnKind};
use syntax::parse::token::InternedString; use syntax::parse::token::InternedString;
use syntax::{ast, ast_util, visit}; use syntax::ast;
use rustc_front::hir;
use rustc_front::visit::{self, Visitor, FnKind};
use syntax::visit::Visitor as SyntaxVisitor;
use syntax::diagnostic; use syntax::diagnostic;
/// Information about the registered lints. /// Information about the registered lints.
@ -252,7 +254,7 @@ pub struct Context<'a, 'tcx: 'a> {
pub tcx: &'a ty::ctxt<'tcx>, pub tcx: &'a ty::ctxt<'tcx>,
/// The crate being checked. /// The crate being checked.
pub krate: &'a ast::Crate, pub krate: &'a hir::Crate,
/// Items exported from the crate being checked. /// Items exported from the crate being checked.
pub exported_items: &'a ExportedItems, pub exported_items: &'a ExportedItems,
@ -284,7 +286,7 @@ macro_rules! run_lints { ($cx:expr, $f:ident, $($args:expr),*) => ({
/// Parse the lint attributes into a vector, with `Err`s for malformed lint /// Parse the lint attributes into a vector, with `Err`s for malformed lint
/// attributes. Writing this as an iterator is an enormous mess. /// attributes. Writing this as an iterator is an enormous mess.
// See also the hir version just below. // See also the hir version just below.
pub fn gather_attrs(attrs: &[ast::Attribute]) pub fn gather_attrs(attrs: &[hir::Attribute])
-> Vec<Result<(InternedString, Level, Span), Span>> { -> Vec<Result<(InternedString, Level, Span), Span>> {
let mut out = vec!(); let mut out = vec!();
for attr in attrs { for attr in attrs {
@ -297,7 +299,7 @@ pub fn gather_attrs(attrs: &[ast::Attribute])
let meta = &attr.node.value; let meta = &attr.node.value;
let metas = match meta.node { let metas = match meta.node {
ast::MetaList(_, ref metas) => metas, hir::MetaList(_, ref metas) => metas,
_ => { _ => {
out.push(Err(meta.span)); out.push(Err(meta.span));
continue; continue;
@ -306,7 +308,7 @@ pub fn gather_attrs(attrs: &[ast::Attribute])
for meta in metas { for meta in metas {
out.push(match meta.node { out.push(match meta.node {
ast::MetaWord(ref lint_name) => Ok((lint_name.clone(), level, meta.span)), hir::MetaWord(ref lint_name) => Ok((lint_name.clone(), level, meta.span)),
_ => Err(meta.span), _ => Err(meta.span),
}); });
} }
@ -398,7 +400,7 @@ pub fn raw_emit_lint(sess: &Session, lint: &'static Lint,
impl<'a, 'tcx> Context<'a, 'tcx> { impl<'a, 'tcx> Context<'a, 'tcx> {
fn new(tcx: &'a ty::ctxt<'tcx>, fn new(tcx: &'a ty::ctxt<'tcx>,
krate: &'a ast::Crate, krate: &'a hir::Crate,
exported_items: &'a ExportedItems) -> Context<'a, 'tcx> { exported_items: &'a ExportedItems) -> Context<'a, 'tcx> {
// We want to own the lint store, so move it out of the session. // We want to own the lint store, so move it out of the session.
let lint_store = mem::replace(&mut *tcx.sess.lint_store.borrow_mut(), let lint_store = mem::replace(&mut *tcx.sess.lint_store.borrow_mut(),
@ -452,7 +454,7 @@ impl<'a, 'tcx> Context<'a, 'tcx> {
/// current lint context, call the provided function, then reset the /// current lint context, call the provided function, then reset the
/// lints in effect to their previous state. /// lints in effect to their previous state.
fn with_lint_attrs<F>(&mut self, fn with_lint_attrs<F>(&mut self,
attrs: &[ast::Attribute], attrs: &[hir::Attribute],
f: F) where f: F) where
F: FnOnce(&mut Context), F: FnOnce(&mut Context),
{ {
@ -519,9 +521,9 @@ impl<'a, 'tcx> Context<'a, 'tcx> {
} }
fn visit_ids<F>(&mut self, f: F) where fn visit_ids<F>(&mut self, f: F) where
F: FnOnce(&mut ast_util::IdVisitor<Context>) F: FnOnce(&mut util::IdVisitor<Context>)
{ {
let mut v = ast_util::IdVisitor { let mut v = util::IdVisitor {
operation: self, operation: self,
pass_through_items: false, pass_through_items: false,
visited_outermost: false, visited_outermost: false,
@ -531,7 +533,7 @@ impl<'a, 'tcx> Context<'a, 'tcx> {
} }
impl<'a, 'tcx, 'v> Visitor<'v> for Context<'a, 'tcx> { impl<'a, 'tcx, 'v> Visitor<'v> for Context<'a, 'tcx> {
fn visit_item(&mut self, it: &ast::Item) { fn visit_item(&mut self, it: &hir::Item) {
self.with_lint_attrs(&it.attrs, |cx| { self.with_lint_attrs(&it.attrs, |cx| {
run_lints!(cx, check_item, it); run_lints!(cx, check_item, it);
cx.visit_ids(|v| v.visit_item(it)); cx.visit_ids(|v| v.visit_item(it));
@ -539,52 +541,52 @@ impl<'a, 'tcx, 'v> Visitor<'v> for Context<'a, 'tcx> {
}) })
} }
fn visit_foreign_item(&mut self, it: &ast::ForeignItem) { fn visit_foreign_item(&mut self, it: &hir::ForeignItem) {
self.with_lint_attrs(&it.attrs, |cx| { self.with_lint_attrs(&it.attrs, |cx| {
run_lints!(cx, check_foreign_item, it); run_lints!(cx, check_foreign_item, it);
visit::walk_foreign_item(cx, it); visit::walk_foreign_item(cx, it);
}) })
} }
fn visit_pat(&mut self, p: &ast::Pat) { fn visit_pat(&mut self, p: &hir::Pat) {
run_lints!(self, check_pat, p); run_lints!(self, check_pat, p);
visit::walk_pat(self, p); visit::walk_pat(self, p);
} }
fn visit_expr(&mut self, e: &ast::Expr) { fn visit_expr(&mut self, e: &hir::Expr) {
run_lints!(self, check_expr, e); run_lints!(self, check_expr, e);
visit::walk_expr(self, e); visit::walk_expr(self, e);
} }
fn visit_stmt(&mut self, s: &ast::Stmt) { fn visit_stmt(&mut self, s: &hir::Stmt) {
run_lints!(self, check_stmt, s); run_lints!(self, check_stmt, s);
visit::walk_stmt(self, s); visit::walk_stmt(self, s);
} }
fn visit_fn(&mut self, fk: FnKind<'v>, decl: &'v ast::FnDecl, fn visit_fn(&mut self, fk: FnKind<'v>, decl: &'v hir::FnDecl,
body: &'v ast::Block, span: Span, id: ast::NodeId) { body: &'v hir::Block, span: Span, id: ast::NodeId) {
run_lints!(self, check_fn, fk, decl, body, span, id); run_lints!(self, check_fn, fk, decl, body, span, id);
visit::walk_fn(self, fk, decl, body, span); visit::walk_fn(self, fk, decl, body, span);
} }
fn visit_struct_def(&mut self, fn visit_struct_def(&mut self,
s: &ast::StructDef, s: &hir::StructDef,
ident: ast::Ident, ident: ast::Ident,
g: &ast::Generics, g: &hir::Generics,
id: ast::NodeId) { id: ast::NodeId) {
run_lints!(self, check_struct_def, s, ident, g, id); run_lints!(self, check_struct_def, s, ident, g, id);
visit::walk_struct_def(self, s); visit::walk_struct_def(self, s);
run_lints!(self, check_struct_def_post, s, ident, g, id); run_lints!(self, check_struct_def_post, s, ident, g, id);
} }
fn visit_struct_field(&mut self, s: &ast::StructField) { fn visit_struct_field(&mut self, s: &hir::StructField) {
self.with_lint_attrs(&s.node.attrs, |cx| { self.with_lint_attrs(&s.node.attrs, |cx| {
run_lints!(cx, check_struct_field, s); run_lints!(cx, check_struct_field, s);
visit::walk_struct_field(cx, s); visit::walk_struct_field(cx, s);
}) })
} }
fn visit_variant(&mut self, v: &ast::Variant, g: &ast::Generics) { fn visit_variant(&mut self, v: &hir::Variant, g: &hir::Generics) {
self.with_lint_attrs(&v.node.attrs, |cx| { self.with_lint_attrs(&v.node.attrs, |cx| {
run_lints!(cx, check_variant, v, g); run_lints!(cx, check_variant, v, g);
visit::walk_variant(cx, v, g); visit::walk_variant(cx, v, g);
@ -592,7 +594,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for Context<'a, 'tcx> {
}) })
} }
fn visit_ty(&mut self, t: &ast::Ty) { fn visit_ty(&mut self, t: &hir::Ty) {
run_lints!(self, check_ty, t); run_lints!(self, check_ty, t);
visit::walk_ty(self, t); visit::walk_ty(self, t);
} }
@ -601,41 +603,41 @@ impl<'a, 'tcx, 'v> Visitor<'v> for Context<'a, 'tcx> {
run_lints!(self, check_ident, sp, id); run_lints!(self, check_ident, sp, id);
} }
fn visit_mod(&mut self, m: &ast::Mod, s: Span, n: ast::NodeId) { fn visit_mod(&mut self, m: &hir::Mod, s: Span, n: ast::NodeId) {
run_lints!(self, check_mod, m, s, n); run_lints!(self, check_mod, m, s, n);
visit::walk_mod(self, m); visit::walk_mod(self, m);
} }
fn visit_local(&mut self, l: &ast::Local) { fn visit_local(&mut self, l: &hir::Local) {
run_lints!(self, check_local, l); run_lints!(self, check_local, l);
visit::walk_local(self, l); visit::walk_local(self, l);
} }
fn visit_block(&mut self, b: &ast::Block) { fn visit_block(&mut self, b: &hir::Block) {
run_lints!(self, check_block, b); run_lints!(self, check_block, b);
visit::walk_block(self, b); visit::walk_block(self, b);
} }
fn visit_arm(&mut self, a: &ast::Arm) { fn visit_arm(&mut self, a: &hir::Arm) {
run_lints!(self, check_arm, a); run_lints!(self, check_arm, a);
visit::walk_arm(self, a); visit::walk_arm(self, a);
} }
fn visit_decl(&mut self, d: &ast::Decl) { fn visit_decl(&mut self, d: &hir::Decl) {
run_lints!(self, check_decl, d); run_lints!(self, check_decl, d);
visit::walk_decl(self, d); visit::walk_decl(self, d);
} }
fn visit_expr_post(&mut self, e: &ast::Expr) { fn visit_expr_post(&mut self, e: &hir::Expr) {
run_lints!(self, check_expr_post, e); run_lints!(self, check_expr_post, e);
} }
fn visit_generics(&mut self, g: &ast::Generics) { fn visit_generics(&mut self, g: &hir::Generics) {
run_lints!(self, check_generics, g); run_lints!(self, check_generics, g);
visit::walk_generics(self, g); visit::walk_generics(self, g);
} }
fn visit_trait_item(&mut self, trait_item: &ast::TraitItem) { fn visit_trait_item(&mut self, trait_item: &hir::TraitItem) {
self.with_lint_attrs(&trait_item.attrs, |cx| { self.with_lint_attrs(&trait_item.attrs, |cx| {
run_lints!(cx, check_trait_item, trait_item); run_lints!(cx, check_trait_item, trait_item);
cx.visit_ids(|v| v.visit_trait_item(trait_item)); cx.visit_ids(|v| v.visit_trait_item(trait_item));
@ -643,7 +645,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for Context<'a, 'tcx> {
}); });
} }
fn visit_impl_item(&mut self, impl_item: &ast::ImplItem) { fn visit_impl_item(&mut self, impl_item: &hir::ImplItem) {
self.with_lint_attrs(&impl_item.attrs, |cx| { self.with_lint_attrs(&impl_item.attrs, |cx| {
run_lints!(cx, check_impl_item, impl_item); run_lints!(cx, check_impl_item, impl_item);
cx.visit_ids(|v| v.visit_impl_item(impl_item)); cx.visit_ids(|v| v.visit_impl_item(impl_item));
@ -651,34 +653,29 @@ impl<'a, 'tcx, 'v> Visitor<'v> for Context<'a, 'tcx> {
}); });
} }
fn visit_opt_lifetime_ref(&mut self, sp: Span, lt: &Option<ast::Lifetime>) { fn visit_opt_lifetime_ref(&mut self, sp: Span, lt: &Option<hir::Lifetime>) {
run_lints!(self, check_opt_lifetime_ref, sp, lt); run_lints!(self, check_opt_lifetime_ref, sp, lt);
} }
fn visit_lifetime_ref(&mut self, lt: &ast::Lifetime) { fn visit_lifetime_ref(&mut self, lt: &hir::Lifetime) {
run_lints!(self, check_lifetime_ref, lt); run_lints!(self, check_lifetime_ref, lt);
} }
fn visit_lifetime_def(&mut self, lt: &ast::LifetimeDef) { fn visit_lifetime_def(&mut self, lt: &hir::LifetimeDef) {
run_lints!(self, check_lifetime_def, lt); run_lints!(self, check_lifetime_def, lt);
} }
fn visit_explicit_self(&mut self, es: &ast::ExplicitSelf) { fn visit_explicit_self(&mut self, es: &hir::ExplicitSelf) {
run_lints!(self, check_explicit_self, es); run_lints!(self, check_explicit_self, es);
visit::walk_explicit_self(self, es); visit::walk_explicit_self(self, es);
} }
fn visit_mac(&mut self, mac: &ast::Mac) { fn visit_path(&mut self, p: &hir::Path, id: ast::NodeId) {
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); run_lints!(self, check_path, p, id);
visit::walk_path(self, p); visit::walk_path(self, p);
} }
fn visit_attribute(&mut self, attr: &ast::Attribute) { fn visit_attribute(&mut self, attr: &hir::Attribute) {
run_lints!(self, check_attribute, attr); run_lints!(self, check_attribute, attr);
} }
} }
@ -709,9 +706,9 @@ impl LintPass for GatherNodeLevels {
lint_array!() lint_array!()
} }
fn check_item(&mut self, cx: &Context, it: &ast::Item) { fn check_item(&mut self, cx: &Context, it: &hir::Item) {
match it.node { match it.node {
ast::ItemEnum(..) => { hir::ItemEnum(..) => {
let lint_id = LintId::of(builtin::VARIANT_SIZE_DIFFERENCES); let lint_id = LintId::of(builtin::VARIANT_SIZE_DIFFERENCES);
let lvlsrc = cx.lints.get_level_source(lint_id); let lvlsrc = cx.lints.get_level_source(lint_id);
match lvlsrc { match lvlsrc {
@ -731,7 +728,7 @@ impl LintPass for GatherNodeLevels {
/// ///
/// Consumes the `lint_store` field of the `Session`. /// Consumes the `lint_store` field of the `Session`.
pub fn check_crate(tcx: &ty::ctxt, pub fn check_crate(tcx: &ty::ctxt,
krate: &ast::Crate, krate: &hir::Crate,
exported_items: &ExportedItems) { exported_items: &ExportedItems) {
let mut cx = Context::new(tcx, krate, exported_items); let mut cx = Context::new(tcx, krate, exported_items);

View file

@ -34,8 +34,9 @@ pub use self::LintSource::*;
use std::hash; use std::hash;
use std::ascii::AsciiExt; use std::ascii::AsciiExt;
use syntax::codemap::Span; use syntax::codemap::Span;
use syntax::visit::FnKind; use rustc_front::visit::FnKind;
use syntax::ast; use syntax::ast;
use rustc_front::hir;
pub use lint::context::{Context, LintStore, raw_emit_lint, check_crate, gather_attrs, pub use lint::context::{Context, LintStore, raw_emit_lint, check_crate, gather_attrs,
gather_attrs_from_hir, GatherNodeLevels}; gather_attrs_from_hir, GatherNodeLevels};
@ -125,46 +126,46 @@ pub trait LintPass {
/// `Lint`, make it a private `static` item in its own module. /// `Lint`, make it a private `static` item in its own module.
fn get_lints(&self) -> LintArray; fn get_lints(&self) -> LintArray;
fn check_crate(&mut self, _: &Context, _: &ast::Crate) { } fn check_crate(&mut self, _: &Context, _: &hir::Crate) { }
fn check_ident(&mut self, _: &Context, _: Span, _: ast::Ident) { } fn check_ident(&mut self, _: &Context, _: Span, _: ast::Ident) { }
fn check_mod(&mut self, _: &Context, _: &ast::Mod, _: Span, _: ast::NodeId) { } fn check_mod(&mut self, _: &Context, _: &hir::Mod, _: Span, _: ast::NodeId) { }
fn check_foreign_item(&mut self, _: &Context, _: &ast::ForeignItem) { } fn check_foreign_item(&mut self, _: &Context, _: &hir::ForeignItem) { }
fn check_item(&mut self, _: &Context, _: &ast::Item) { } fn check_item(&mut self, _: &Context, _: &hir::Item) { }
fn check_local(&mut self, _: &Context, _: &ast::Local) { } fn check_local(&mut self, _: &Context, _: &hir::Local) { }
fn check_block(&mut self, _: &Context, _: &ast::Block) { } fn check_block(&mut self, _: &Context, _: &hir::Block) { }
fn check_stmt(&mut self, _: &Context, _: &ast::Stmt) { } fn check_stmt(&mut self, _: &Context, _: &hir::Stmt) { }
fn check_arm(&mut self, _: &Context, _: &ast::Arm) { } fn check_arm(&mut self, _: &Context, _: &hir::Arm) { }
fn check_pat(&mut self, _: &Context, _: &ast::Pat) { } fn check_pat(&mut self, _: &Context, _: &hir::Pat) { }
fn check_decl(&mut self, _: &Context, _: &ast::Decl) { } fn check_decl(&mut self, _: &Context, _: &hir::Decl) { }
fn check_expr(&mut self, _: &Context, _: &ast::Expr) { } fn check_expr(&mut self, _: &Context, _: &hir::Expr) { }
fn check_expr_post(&mut self, _: &Context, _: &ast::Expr) { } fn check_expr_post(&mut self, _: &Context, _: &hir::Expr) { }
fn check_ty(&mut self, _: &Context, _: &ast::Ty) { } fn check_ty(&mut self, _: &Context, _: &hir::Ty) { }
fn check_generics(&mut self, _: &Context, _: &ast::Generics) { } fn check_generics(&mut self, _: &Context, _: &hir::Generics) { }
fn check_fn(&mut self, _: &Context, fn check_fn(&mut self, _: &Context,
_: FnKind, _: &ast::FnDecl, _: &ast::Block, _: Span, _: ast::NodeId) { } _: FnKind, _: &hir::FnDecl, _: &hir::Block, _: Span, _: ast::NodeId) { }
fn check_trait_item(&mut self, _: &Context, _: &ast::TraitItem) { } fn check_trait_item(&mut self, _: &Context, _: &hir::TraitItem) { }
fn check_impl_item(&mut self, _: &Context, _: &ast::ImplItem) { } fn check_impl_item(&mut self, _: &Context, _: &hir::ImplItem) { }
fn check_struct_def(&mut self, _: &Context, fn check_struct_def(&mut self, _: &Context,
_: &ast::StructDef, _: ast::Ident, _: &ast::Generics, _: ast::NodeId) { } _: &hir::StructDef, _: ast::Ident, _: &hir::Generics, _: ast::NodeId) { }
fn check_struct_def_post(&mut self, _: &Context, fn check_struct_def_post(&mut self, _: &Context,
_: &ast::StructDef, _: ast::Ident, _: &ast::Generics, _: ast::NodeId) { } _: &hir::StructDef, _: ast::Ident, _: &hir::Generics, _: ast::NodeId) { }
fn check_struct_field(&mut self, _: &Context, _: &ast::StructField) { } fn check_struct_field(&mut self, _: &Context, _: &hir::StructField) { }
fn check_variant(&mut self, _: &Context, _: &ast::Variant, _: &ast::Generics) { } fn check_variant(&mut self, _: &Context, _: &hir::Variant, _: &hir::Generics) { }
fn check_variant_post(&mut self, _: &Context, _: &ast::Variant, _: &ast::Generics) { } fn check_variant_post(&mut self, _: &Context, _: &hir::Variant, _: &hir::Generics) { }
fn check_opt_lifetime_ref(&mut self, _: &Context, _: Span, _: &Option<ast::Lifetime>) { } fn check_opt_lifetime_ref(&mut self, _: &Context, _: Span, _: &Option<hir::Lifetime>) { }
fn check_lifetime_ref(&mut self, _: &Context, _: &ast::Lifetime) { } fn check_lifetime_ref(&mut self, _: &Context, _: &hir::Lifetime) { }
fn check_lifetime_def(&mut self, _: &Context, _: &ast::LifetimeDef) { } fn check_lifetime_def(&mut self, _: &Context, _: &hir::LifetimeDef) { }
fn check_explicit_self(&mut self, _: &Context, _: &ast::ExplicitSelf) { } fn check_explicit_self(&mut self, _: &Context, _: &hir::ExplicitSelf) { }
fn check_mac(&mut self, _: &Context, _: &ast::Mac) { } fn check_mac(&mut self, _: &Context, _: &ast::Mac) { }
fn check_path(&mut self, _: &Context, _: &ast::Path, _: ast::NodeId) { } fn check_path(&mut self, _: &Context, _: &hir::Path, _: ast::NodeId) { }
fn check_attribute(&mut self, _: &Context, _: &ast::Attribute) { } fn check_attribute(&mut self, _: &Context, _: &hir::Attribute) { }
/// Called when entering a syntax node that can have lint attributes such /// Called when entering a syntax node that can have lint attributes such
/// as `#[allow(...)]`. Called with *all* the attributes of that node. /// as `#[allow(...)]`. Called with *all* the attributes of that node.
fn enter_lint_attrs(&mut self, _: &Context, _: &[ast::Attribute]) { } fn enter_lint_attrs(&mut self, _: &Context, _: &[hir::Attribute]) { }
/// Counterpart to `enter_lint_attrs`. /// Counterpart to `enter_lint_attrs`.
fn exit_lint_attrs(&mut self, _: &Context, _: &[ast::Attribute]) { } fn exit_lint_attrs(&mut self, _: &Context, _: &[hir::Attribute]) { }
} }
/// A lint pass boxed up as a trait object. /// A lint pass boxed up as a trait object.

View file

@ -761,7 +761,7 @@ pub fn phase_3_run_analysis_passes<'tcx, F, R>(sess: Session,
&tcx.sess, lib_features_used)); &tcx.sess, lib_features_used));
time(time_passes, "lint checking", || time(time_passes, "lint checking", ||
lint::check_crate(tcx, ast_crate, &exported_items)); lint::check_crate(tcx, &lower_crate(ast_crate), &exported_items));
// The above three passes generate errors w/o aborting // The above three passes generate errors w/o aborting
tcx.sess.abort_if_errors(); tcx.sess.abort_if_errors();

File diff suppressed because it is too large Load diff

View file

@ -13,12 +13,12 @@
#![feature(plugin_registrar, rustc_private)] #![feature(plugin_registrar, rustc_private)]
#![feature(box_syntax)] #![feature(box_syntax)]
extern crate syntax;
#[macro_use] extern crate rustc; #[macro_use] extern crate rustc;
extern crate rustc_front;
use syntax::{ast, attr};
use rustc::lint::{Context, LintPass, LintPassObject, LintArray}; use rustc::lint::{Context, LintPass, LintPassObject, LintArray};
use rustc::plugin::Registry; use rustc::plugin::Registry;
use rustc_front::{hir, attr};
declare_lint!(CRATE_NOT_OKAY, Warn, "crate not marked with #![crate_okay]"); declare_lint!(CRATE_NOT_OKAY, Warn, "crate not marked with #![crate_okay]");
@ -29,7 +29,7 @@ impl LintPass for Pass {
lint_array!(CRATE_NOT_OKAY) lint_array!(CRATE_NOT_OKAY)
} }
fn check_crate(&mut self, cx: &Context, krate: &ast::Crate) { fn check_crate(&mut self, cx: &Context, krate: &hir::Crate) {
if !attr::contains_name(&krate.attrs, "crate_okay") { if !attr::contains_name(&krate.attrs, "crate_okay") {
cx.span_lint(CRATE_NOT_OKAY, krate.span, cx.span_lint(CRATE_NOT_OKAY, krate.span,
"crate is not marked with #![crate_okay]"); "crate is not marked with #![crate_okay]");

View file

@ -13,13 +13,13 @@
#![feature(plugin_registrar)] #![feature(plugin_registrar)]
#![feature(box_syntax, rustc_private)] #![feature(box_syntax, rustc_private)]
extern crate syntax; extern crate rustc_front;
// Load rustc as a plugin to get macros // Load rustc as a plugin to get macros
#[macro_use] #[macro_use]
extern crate rustc; extern crate rustc;
use syntax::ast; use rustc_front::hir;
use rustc::lint::{Context, LintPass, LintPassObject, LintArray}; use rustc::lint::{Context, LintPass, LintPassObject, LintArray};
use rustc::plugin::Registry; use rustc::plugin::Registry;
@ -34,7 +34,7 @@ impl LintPass for Pass {
lint_array!(TEST_LINT, PLEASE_LINT) lint_array!(TEST_LINT, PLEASE_LINT)
} }
fn check_item(&mut self, cx: &Context, it: &ast::Item) { fn check_item(&mut self, cx: &Context, it: &hir::Item) {
match &*it.ident.name.as_str() { match &*it.ident.name.as_str() {
"lintme" => cx.span_lint(TEST_LINT, it.span, "item is named 'lintme'"), "lintme" => cx.span_lint(TEST_LINT, it.span, "item is named 'lintme'"),
"pleaselintme" => cx.span_lint(PLEASE_LINT, it.span, "item is named 'pleaselintme'"), "pleaselintme" => cx.span_lint(PLEASE_LINT, it.span, "item is named 'pleaselintme'"),

View file

@ -13,16 +13,15 @@
#![feature(plugin_registrar)] #![feature(plugin_registrar)]
#![feature(box_syntax, rustc_private)] #![feature(box_syntax, rustc_private)]
extern crate syntax; extern crate rustc_front;
// Load rustc as a plugin to get macros // Load rustc as a plugin to get macros
#[macro_use] #[macro_use]
extern crate rustc; extern crate rustc;
use syntax::ast;
use rustc::lint::{Context, LintPass, LintPassObject, LintArray}; use rustc::lint::{Context, LintPass, LintPassObject, LintArray};
use rustc::plugin::Registry; use rustc::plugin::Registry;
use rustc_front::hir;
declare_lint!(TEST_LINT, Warn, "Warn about items named 'lintme'"); declare_lint!(TEST_LINT, Warn, "Warn about items named 'lintme'");
struct Pass; struct Pass;
@ -32,7 +31,7 @@ impl LintPass for Pass {
lint_array!(TEST_LINT) lint_array!(TEST_LINT)
} }
fn check_item(&mut self, cx: &Context, it: &ast::Item) { fn check_item(&mut self, cx: &Context, it: &hir::Item) {
if it.ident.name == "lintme" { if it.ident.name == "lintme" {
cx.span_lint(TEST_LINT, it.span, "item is named 'lintme'"); cx.span_lint(TEST_LINT, it.span, "item is named 'lintme'");
} }