Skip to content

Commit 7732ad8

Browse files
committed
Move lints to HIR
1 parent 1661947 commit 7732ad8

File tree

7 files changed

+328
-337
lines changed

7 files changed

+328
-337
lines changed

src/librustc/lint/context.rs

+44-47
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,14 @@ use std::cell::RefCell;
3737
use std::cmp;
3838
use std::mem;
3939
use syntax::ast_util::IdVisitingOperation;
40-
use syntax::attr::AttrMetaMethods;
41-
use syntax::attr;
40+
use rustc_front::attr::{self, AttrMetaMethods};
41+
use rustc_front::util;
4242
use syntax::codemap::Span;
43-
use syntax::visit::{Visitor, FnKind};
4443
use syntax::parse::token::InternedString;
45-
use syntax::{ast, ast_util, visit};
44+
use syntax::ast;
45+
use rustc_front::hir;
46+
use rustc_front::visit::{self, Visitor, FnKind};
47+
use syntax::visit::Visitor as SyntaxVisitor;
4648
use syntax::diagnostic;
4749

4850
/// Information about the registered lints.
@@ -252,7 +254,7 @@ pub struct Context<'a, 'tcx: 'a> {
252254
pub tcx: &'a ty::ctxt<'tcx>,
253255

254256
/// The crate being checked.
255-
pub krate: &'a ast::Crate,
257+
pub krate: &'a hir::Crate,
256258

257259
/// Items exported from the crate being checked.
258260
pub exported_items: &'a ExportedItems,
@@ -284,7 +286,7 @@ macro_rules! run_lints { ($cx:expr, $f:ident, $($args:expr),*) => ({
284286
/// Parse the lint attributes into a vector, with `Err`s for malformed lint
285287
/// attributes. Writing this as an iterator is an enormous mess.
286288
// See also the hir version just below.
287-
pub fn gather_attrs(attrs: &[ast::Attribute])
289+
pub fn gather_attrs(attrs: &[hir::Attribute])
288290
-> Vec<Result<(InternedString, Level, Span), Span>> {
289291
let mut out = vec!();
290292
for attr in attrs {
@@ -297,7 +299,7 @@ pub fn gather_attrs(attrs: &[ast::Attribute])
297299

298300
let meta = &attr.node.value;
299301
let metas = match meta.node {
300-
ast::MetaList(_, ref metas) => metas,
302+
hir::MetaList(_, ref metas) => metas,
301303
_ => {
302304
out.push(Err(meta.span));
303305
continue;
@@ -306,7 +308,7 @@ pub fn gather_attrs(attrs: &[ast::Attribute])
306308

307309
for meta in metas {
308310
out.push(match meta.node {
309-
ast::MetaWord(ref lint_name) => Ok((lint_name.clone(), level, meta.span)),
311+
hir::MetaWord(ref lint_name) => Ok((lint_name.clone(), level, meta.span)),
310312
_ => Err(meta.span),
311313
});
312314
}
@@ -398,7 +400,7 @@ pub fn raw_emit_lint(sess: &Session, lint: &'static Lint,
398400

399401
impl<'a, 'tcx> Context<'a, 'tcx> {
400402
fn new(tcx: &'a ty::ctxt<'tcx>,
401-
krate: &'a ast::Crate,
403+
krate: &'a hir::Crate,
402404
exported_items: &'a ExportedItems) -> Context<'a, 'tcx> {
403405
// We want to own the lint store, so move it out of the session.
404406
let lint_store = mem::replace(&mut *tcx.sess.lint_store.borrow_mut(),
@@ -452,7 +454,7 @@ impl<'a, 'tcx> Context<'a, 'tcx> {
452454
/// current lint context, call the provided function, then reset the
453455
/// lints in effect to their previous state.
454456
fn with_lint_attrs<F>(&mut self,
455-
attrs: &[ast::Attribute],
457+
attrs: &[hir::Attribute],
456458
f: F) where
457459
F: FnOnce(&mut Context),
458460
{
@@ -519,9 +521,9 @@ impl<'a, 'tcx> Context<'a, 'tcx> {
519521
}
520522

521523
fn visit_ids<F>(&mut self, f: F) where
522-
F: FnOnce(&mut ast_util::IdVisitor<Context>)
524+
F: FnOnce(&mut util::IdVisitor<Context>)
523525
{
524-
let mut v = ast_util::IdVisitor {
526+
let mut v = util::IdVisitor {
525527
operation: self,
526528
pass_through_items: false,
527529
visited_outermost: false,
@@ -531,68 +533,68 @@ impl<'a, 'tcx> Context<'a, 'tcx> {
531533
}
532534

533535
impl<'a, 'tcx, 'v> Visitor<'v> for Context<'a, 'tcx> {
534-
fn visit_item(&mut self, it: &ast::Item) {
536+
fn visit_item(&mut self, it: &hir::Item) {
535537
self.with_lint_attrs(&it.attrs, |cx| {
536538
run_lints!(cx, check_item, it);
537539
cx.visit_ids(|v| v.visit_item(it));
538540
visit::walk_item(cx, it);
539541
})
540542
}
541543

542-
fn visit_foreign_item(&mut self, it: &ast::ForeignItem) {
544+
fn visit_foreign_item(&mut self, it: &hir::ForeignItem) {
543545
self.with_lint_attrs(&it.attrs, |cx| {
544546
run_lints!(cx, check_foreign_item, it);
545547
visit::walk_foreign_item(cx, it);
546548
})
547549
}
548550

549-
fn visit_pat(&mut self, p: &ast::Pat) {
551+
fn visit_pat(&mut self, p: &hir::Pat) {
550552
run_lints!(self, check_pat, p);
551553
visit::walk_pat(self, p);
552554
}
553555

554-
fn visit_expr(&mut self, e: &ast::Expr) {
556+
fn visit_expr(&mut self, e: &hir::Expr) {
555557
run_lints!(self, check_expr, e);
556558
visit::walk_expr(self, e);
557559
}
558560

559-
fn visit_stmt(&mut self, s: &ast::Stmt) {
561+
fn visit_stmt(&mut self, s: &hir::Stmt) {
560562
run_lints!(self, check_stmt, s);
561563
visit::walk_stmt(self, s);
562564
}
563565

564-
fn visit_fn(&mut self, fk: FnKind<'v>, decl: &'v ast::FnDecl,
565-
body: &'v ast::Block, span: Span, id: ast::NodeId) {
566+
fn visit_fn(&mut self, fk: FnKind<'v>, decl: &'v hir::FnDecl,
567+
body: &'v hir::Block, span: Span, id: ast::NodeId) {
566568
run_lints!(self, check_fn, fk, decl, body, span, id);
567569
visit::walk_fn(self, fk, decl, body, span);
568570
}
569571

570572
fn visit_struct_def(&mut self,
571-
s: &ast::StructDef,
573+
s: &hir::StructDef,
572574
ident: ast::Ident,
573-
g: &ast::Generics,
575+
g: &hir::Generics,
574576
id: ast::NodeId) {
575577
run_lints!(self, check_struct_def, s, ident, g, id);
576578
visit::walk_struct_def(self, s);
577579
run_lints!(self, check_struct_def_post, s, ident, g, id);
578580
}
579581

580-
fn visit_struct_field(&mut self, s: &ast::StructField) {
582+
fn visit_struct_field(&mut self, s: &hir::StructField) {
581583
self.with_lint_attrs(&s.node.attrs, |cx| {
582584
run_lints!(cx, check_struct_field, s);
583585
visit::walk_struct_field(cx, s);
584586
})
585587
}
586588

587-
fn visit_variant(&mut self, v: &ast::Variant, g: &ast::Generics) {
589+
fn visit_variant(&mut self, v: &hir::Variant, g: &hir::Generics) {
588590
self.with_lint_attrs(&v.node.attrs, |cx| {
589591
run_lints!(cx, check_variant, v, g);
590592
visit::walk_variant(cx, v, g);
591593
run_lints!(cx, check_variant_post, v, g);
592594
})
593595
}
594596

595-
fn visit_ty(&mut self, t: &ast::Ty) {
597+
fn visit_ty(&mut self, t: &hir::Ty) {
596598
run_lints!(self, check_ty, t);
597599
visit::walk_ty(self, t);
598600
}
@@ -601,84 +603,79 @@ impl<'a, 'tcx, 'v> Visitor<'v> for Context<'a, 'tcx> {
601603
run_lints!(self, check_ident, sp, id);
602604
}
603605

604-
fn visit_mod(&mut self, m: &ast::Mod, s: Span, n: ast::NodeId) {
606+
fn visit_mod(&mut self, m: &hir::Mod, s: Span, n: ast::NodeId) {
605607
run_lints!(self, check_mod, m, s, n);
606608
visit::walk_mod(self, m);
607609
}
608610

609-
fn visit_local(&mut self, l: &ast::Local) {
611+
fn visit_local(&mut self, l: &hir::Local) {
610612
run_lints!(self, check_local, l);
611613
visit::walk_local(self, l);
612614
}
613615

614-
fn visit_block(&mut self, b: &ast::Block) {
616+
fn visit_block(&mut self, b: &hir::Block) {
615617
run_lints!(self, check_block, b);
616618
visit::walk_block(self, b);
617619
}
618620

619-
fn visit_arm(&mut self, a: &ast::Arm) {
621+
fn visit_arm(&mut self, a: &hir::Arm) {
620622
run_lints!(self, check_arm, a);
621623
visit::walk_arm(self, a);
622624
}
623625

624-
fn visit_decl(&mut self, d: &ast::Decl) {
626+
fn visit_decl(&mut self, d: &hir::Decl) {
625627
run_lints!(self, check_decl, d);
626628
visit::walk_decl(self, d);
627629
}
628630

629-
fn visit_expr_post(&mut self, e: &ast::Expr) {
631+
fn visit_expr_post(&mut self, e: &hir::Expr) {
630632
run_lints!(self, check_expr_post, e);
631633
}
632634

633-
fn visit_generics(&mut self, g: &ast::Generics) {
635+
fn visit_generics(&mut self, g: &hir::Generics) {
634636
run_lints!(self, check_generics, g);
635637
visit::walk_generics(self, g);
636638
}
637639

638-
fn visit_trait_item(&mut self, trait_item: &ast::TraitItem) {
640+
fn visit_trait_item(&mut self, trait_item: &hir::TraitItem) {
639641
self.with_lint_attrs(&trait_item.attrs, |cx| {
640642
run_lints!(cx, check_trait_item, trait_item);
641643
cx.visit_ids(|v| v.visit_trait_item(trait_item));
642644
visit::walk_trait_item(cx, trait_item);
643645
});
644646
}
645647

646-
fn visit_impl_item(&mut self, impl_item: &ast::ImplItem) {
648+
fn visit_impl_item(&mut self, impl_item: &hir::ImplItem) {
647649
self.with_lint_attrs(&impl_item.attrs, |cx| {
648650
run_lints!(cx, check_impl_item, impl_item);
649651
cx.visit_ids(|v| v.visit_impl_item(impl_item));
650652
visit::walk_impl_item(cx, impl_item);
651653
});
652654
}
653655

654-
fn visit_opt_lifetime_ref(&mut self, sp: Span, lt: &Option<ast::Lifetime>) {
656+
fn visit_opt_lifetime_ref(&mut self, sp: Span, lt: &Option<hir::Lifetime>) {
655657
run_lints!(self, check_opt_lifetime_ref, sp, lt);
656658
}
657659

658-
fn visit_lifetime_ref(&mut self, lt: &ast::Lifetime) {
660+
fn visit_lifetime_ref(&mut self, lt: &hir::Lifetime) {
659661
run_lints!(self, check_lifetime_ref, lt);
660662
}
661663

662-
fn visit_lifetime_def(&mut self, lt: &ast::LifetimeDef) {
664+
fn visit_lifetime_def(&mut self, lt: &hir::LifetimeDef) {
663665
run_lints!(self, check_lifetime_def, lt);
664666
}
665667

666-
fn visit_explicit_self(&mut self, es: &ast::ExplicitSelf) {
668+
fn visit_explicit_self(&mut self, es: &hir::ExplicitSelf) {
667669
run_lints!(self, check_explicit_self, es);
668670
visit::walk_explicit_self(self, es);
669671
}
670672

671-
fn visit_mac(&mut self, mac: &ast::Mac) {
672-
run_lints!(self, check_mac, mac);
673-
visit::walk_mac(self, mac);
674-
}
675-
676-
fn visit_path(&mut self, p: &ast::Path, id: ast::NodeId) {
673+
fn visit_path(&mut self, p: &hir::Path, id: ast::NodeId) {
677674
run_lints!(self, check_path, p, id);
678675
visit::walk_path(self, p);
679676
}
680677

681-
fn visit_attribute(&mut self, attr: &ast::Attribute) {
678+
fn visit_attribute(&mut self, attr: &hir::Attribute) {
682679
run_lints!(self, check_attribute, attr);
683680
}
684681
}
@@ -709,9 +706,9 @@ impl LintPass for GatherNodeLevels {
709706
lint_array!()
710707
}
711708

712-
fn check_item(&mut self, cx: &Context, it: &ast::Item) {
709+
fn check_item(&mut self, cx: &Context, it: &hir::Item) {
713710
match it.node {
714-
ast::ItemEnum(..) => {
711+
hir::ItemEnum(..) => {
715712
let lint_id = LintId::of(builtin::VARIANT_SIZE_DIFFERENCES);
716713
let lvlsrc = cx.lints.get_level_source(lint_id);
717714
match lvlsrc {
@@ -731,7 +728,7 @@ impl LintPass for GatherNodeLevels {
731728
///
732729
/// Consumes the `lint_store` field of the `Session`.
733730
pub fn check_crate(tcx: &ty::ctxt,
734-
krate: &ast::Crate,
731+
krate: &hir::Crate,
735732
exported_items: &ExportedItems) {
736733

737734
let mut cx = Context::new(tcx, krate, exported_items);

src/librustc/lint/mod.rs

+32-31
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,9 @@ pub use self::LintSource::*;
3434
use std::hash;
3535
use std::ascii::AsciiExt;
3636
use syntax::codemap::Span;
37-
use syntax::visit::FnKind;
37+
use rustc_front::visit::FnKind;
3838
use syntax::ast;
39+
use rustc_front::hir;
3940

4041
pub use lint::context::{Context, LintStore, raw_emit_lint, check_crate, gather_attrs,
4142
gather_attrs_from_hir, GatherNodeLevels};
@@ -125,46 +126,46 @@ pub trait LintPass {
125126
/// `Lint`, make it a private `static` item in its own module.
126127
fn get_lints(&self) -> LintArray;
127128

128-
fn check_crate(&mut self, _: &Context, _: &ast::Crate) { }
129+
fn check_crate(&mut self, _: &Context, _: &hir::Crate) { }
129130
fn check_ident(&mut self, _: &Context, _: Span, _: ast::Ident) { }
130-
fn check_mod(&mut self, _: &Context, _: &ast::Mod, _: Span, _: ast::NodeId) { }
131-
fn check_foreign_item(&mut self, _: &Context, _: &ast::ForeignItem) { }
132-
fn check_item(&mut self, _: &Context, _: &ast::Item) { }
133-
fn check_local(&mut self, _: &Context, _: &ast::Local) { }
134-
fn check_block(&mut self, _: &Context, _: &ast::Block) { }
135-
fn check_stmt(&mut self, _: &Context, _: &ast::Stmt) { }
136-
fn check_arm(&mut self, _: &Context, _: &ast::Arm) { }
137-
fn check_pat(&mut self, _: &Context, _: &ast::Pat) { }
138-
fn check_decl(&mut self, _: &Context, _: &ast::Decl) { }
139-
fn check_expr(&mut self, _: &Context, _: &ast::Expr) { }
140-
fn check_expr_post(&mut self, _: &Context, _: &ast::Expr) { }
141-
fn check_ty(&mut self, _: &Context, _: &ast::Ty) { }
142-
fn check_generics(&mut self, _: &Context, _: &ast::Generics) { }
131+
fn check_mod(&mut self, _: &Context, _: &hir::Mod, _: Span, _: ast::NodeId) { }
132+
fn check_foreign_item(&mut self, _: &Context, _: &hir::ForeignItem) { }
133+
fn check_item(&mut self, _: &Context, _: &hir::Item) { }
134+
fn check_local(&mut self, _: &Context, _: &hir::Local) { }
135+
fn check_block(&mut self, _: &Context, _: &hir::Block) { }
136+
fn check_stmt(&mut self, _: &Context, _: &hir::Stmt) { }
137+
fn check_arm(&mut self, _: &Context, _: &hir::Arm) { }
138+
fn check_pat(&mut self, _: &Context, _: &hir::Pat) { }
139+
fn check_decl(&mut self, _: &Context, _: &hir::Decl) { }
140+
fn check_expr(&mut self, _: &Context, _: &hir::Expr) { }
141+
fn check_expr_post(&mut self, _: &Context, _: &hir::Expr) { }
142+
fn check_ty(&mut self, _: &Context, _: &hir::Ty) { }
143+
fn check_generics(&mut self, _: &Context, _: &hir::Generics) { }
143144
fn check_fn(&mut self, _: &Context,
144-
_: FnKind, _: &ast::FnDecl, _: &ast::Block, _: Span, _: ast::NodeId) { }
145-
fn check_trait_item(&mut self, _: &Context, _: &ast::TraitItem) { }
146-
fn check_impl_item(&mut self, _: &Context, _: &ast::ImplItem) { }
145+
_: FnKind, _: &hir::FnDecl, _: &hir::Block, _: Span, _: ast::NodeId) { }
146+
fn check_trait_item(&mut self, _: &Context, _: &hir::TraitItem) { }
147+
fn check_impl_item(&mut self, _: &Context, _: &hir::ImplItem) { }
147148
fn check_struct_def(&mut self, _: &Context,
148-
_: &ast::StructDef, _: ast::Ident, _: &ast::Generics, _: ast::NodeId) { }
149+
_: &hir::StructDef, _: ast::Ident, _: &hir::Generics, _: ast::NodeId) { }
149150
fn check_struct_def_post(&mut self, _: &Context,
150-
_: &ast::StructDef, _: ast::Ident, _: &ast::Generics, _: ast::NodeId) { }
151-
fn check_struct_field(&mut self, _: &Context, _: &ast::StructField) { }
152-
fn check_variant(&mut self, _: &Context, _: &ast::Variant, _: &ast::Generics) { }
153-
fn check_variant_post(&mut self, _: &Context, _: &ast::Variant, _: &ast::Generics) { }
154-
fn check_opt_lifetime_ref(&mut self, _: &Context, _: Span, _: &Option<ast::Lifetime>) { }
155-
fn check_lifetime_ref(&mut self, _: &Context, _: &ast::Lifetime) { }
156-
fn check_lifetime_def(&mut self, _: &Context, _: &ast::LifetimeDef) { }
157-
fn check_explicit_self(&mut self, _: &Context, _: &ast::ExplicitSelf) { }
151+
_: &hir::StructDef, _: ast::Ident, _: &hir::Generics, _: ast::NodeId) { }
152+
fn check_struct_field(&mut self, _: &Context, _: &hir::StructField) { }
153+
fn check_variant(&mut self, _: &Context, _: &hir::Variant, _: &hir::Generics) { }
154+
fn check_variant_post(&mut self, _: &Context, _: &hir::Variant, _: &hir::Generics) { }
155+
fn check_opt_lifetime_ref(&mut self, _: &Context, _: Span, _: &Option<hir::Lifetime>) { }
156+
fn check_lifetime_ref(&mut self, _: &Context, _: &hir::Lifetime) { }
157+
fn check_lifetime_def(&mut self, _: &Context, _: &hir::LifetimeDef) { }
158+
fn check_explicit_self(&mut self, _: &Context, _: &hir::ExplicitSelf) { }
158159
fn check_mac(&mut self, _: &Context, _: &ast::Mac) { }
159-
fn check_path(&mut self, _: &Context, _: &ast::Path, _: ast::NodeId) { }
160-
fn check_attribute(&mut self, _: &Context, _: &ast::Attribute) { }
160+
fn check_path(&mut self, _: &Context, _: &hir::Path, _: ast::NodeId) { }
161+
fn check_attribute(&mut self, _: &Context, _: &hir::Attribute) { }
161162

162163
/// Called when entering a syntax node that can have lint attributes such
163164
/// as `#[allow(...)]`. Called with *all* the attributes of that node.
164-
fn enter_lint_attrs(&mut self, _: &Context, _: &[ast::Attribute]) { }
165+
fn enter_lint_attrs(&mut self, _: &Context, _: &[hir::Attribute]) { }
165166

166167
/// Counterpart to `enter_lint_attrs`.
167-
fn exit_lint_attrs(&mut self, _: &Context, _: &[ast::Attribute]) { }
168+
fn exit_lint_attrs(&mut self, _: &Context, _: &[hir::Attribute]) { }
168169
}
169170

170171
/// A lint pass boxed up as a trait object.

src/librustc_driver/driver.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -761,7 +761,7 @@ pub fn phase_3_run_analysis_passes<'tcx, F, R>(sess: Session,
761761
&tcx.sess, lib_features_used));
762762

763763
time(time_passes, "lint checking", ||
764-
lint::check_crate(tcx, ast_crate, &exported_items));
764+
lint::check_crate(tcx, &lower_crate(ast_crate), &exported_items));
765765

766766
// The above three passes generate errors w/o aborting
767767
tcx.sess.abort_if_errors();

0 commit comments

Comments
 (0)