]> git.lizzy.rs Git - rust.git/blob - src/librustc/lint/mod.rs
Update bootstrap compiler
[rust.git] / src / librustc / lint / mod.rs
1 // Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 //! Lints, aka compiler warnings.
12 //!
13 //! A 'lint' check is a kind of miscellaneous constraint that a user _might_
14 //! want to enforce, but might reasonably want to permit as well, on a
15 //! module-by-module basis. They contrast with static constraints enforced by
16 //! other phases of the compiler, which are generally required to hold in order
17 //! to compile the program at all.
18 //!
19 //! Most lints can be written as `LintPass` instances. These run just before
20 //! translation to LLVM bytecode. The `LintPass`es built into rustc are defined
21 //! within `builtin.rs`, which has further comments on how to add such a lint.
22 //! rustc can also load user-defined lint plugins via the plugin mechanism.
23 //!
24 //! Some of rustc's lints are defined elsewhere in the compiler and work by
25 //! calling `add_lint()` on the overall `Session` object. This works when
26 //! it happens before the main lint pass, which emits the lints stored by
27 //! `add_lint()`. To emit lints after the main lint pass (from trans, for
28 //! example) requires more effort. See `emit_lint` and `GatherNodeLevels`
29 //! in `context.rs`.
30
31 pub use self::Level::*;
32 pub use self::LintSource::*;
33
34 use std::rc::Rc;
35
36 use errors::{DiagnosticBuilder, DiagnosticId};
37 use hir::def_id::{CrateNum, LOCAL_CRATE};
38 use hir::intravisit::{self, FnKind};
39 use hir;
40 use session::Session;
41 use std::hash;
42 use syntax::ast;
43 use syntax::codemap::MultiSpan;
44 use syntax::symbol::Symbol;
45 use syntax::visit as ast_visit;
46 use syntax_pos::Span;
47 use ty::TyCtxt;
48 use ty::maps::Providers;
49 use util::nodemap::NodeMap;
50
51 pub use lint::context::{LateContext, EarlyContext, LintContext, LintStore,
52                         check_crate, check_ast_crate,
53                         FutureIncompatibleInfo, BufferedEarlyLint};
54
55 /// Specification of a single lint.
56 #[derive(Copy, Clone, Debug)]
57 pub struct Lint {
58     /// A string identifier for the lint.
59     ///
60     /// This identifies the lint in attributes and in command-line arguments.
61     /// In those contexts it is always lowercase, but this field is compared
62     /// in a way which is case-insensitive for ASCII characters. This allows
63     /// `declare_lint!()` invocations to follow the convention of upper-case
64     /// statics without repeating the name.
65     ///
66     /// The name is written with underscores, e.g. "unused_imports".
67     /// On the command line, underscores become dashes.
68     pub name: &'static str,
69
70     /// Default level for the lint.
71     pub default_level: Level,
72
73     /// Description of the lint or the issue it detects.
74     ///
75     /// e.g. "imports that are never used"
76     pub desc: &'static str,
77 }
78
79 impl Lint {
80     /// Get the lint's name, with ASCII letters converted to lowercase.
81     pub fn name_lower(&self) -> String {
82         self.name.to_ascii_lowercase()
83     }
84 }
85
86 /// Declare a static item of type `&'static Lint`.
87 #[macro_export]
88 macro_rules! declare_lint {
89     ($vis: vis $NAME: ident, $Level: ident, $desc: expr) => (
90         $vis static $NAME: &$crate::lint::Lint = &$crate::lint::Lint {
91             name: stringify!($NAME),
92             default_level: $crate::lint::$Level,
93             desc: $desc
94         };
95     )
96 }
97
98 /// Declare a static `LintArray` and return it as an expression.
99 #[macro_export]
100 macro_rules! lint_array { ($( $lint:expr ),*) => (
101     {
102         static ARRAY: LintArray = &[ $( &$lint ),* ];
103         ARRAY
104     }
105 ) }
106
107 pub type LintArray = &'static [&'static &'static Lint];
108
109 pub trait LintPass {
110     /// Get descriptions of the lints this `LintPass` object can emit.
111     ///
112     /// NB: there is no enforcement that the object only emits lints it registered.
113     /// And some `rustc` internal `LintPass`es register lints to be emitted by other
114     /// parts of the compiler. If you want enforced access restrictions for your
115     /// `Lint`, make it a private `static` item in its own module.
116     fn get_lints(&self) -> LintArray;
117 }
118
119
120 /// Trait for types providing lint checks.
121 ///
122 /// Each `check` method checks a single syntax node, and should not
123 /// invoke methods recursively (unlike `Visitor`). By default they
124 /// do nothing.
125 //
126 // FIXME: eliminate the duplication with `Visitor`. But this also
127 // contains a few lint-specific methods with no equivalent in `Visitor`.
128 pub trait LateLintPass<'a, 'tcx>: LintPass {
129     fn check_body(&mut self, _: &LateContext, _: &'tcx hir::Body) { }
130     fn check_body_post(&mut self, _: &LateContext, _: &'tcx hir::Body) { }
131     fn check_name(&mut self, _: &LateContext, _: Span, _: ast::Name) { }
132     fn check_crate(&mut self, _: &LateContext<'a, 'tcx>, _: &'tcx hir::Crate) { }
133     fn check_crate_post(&mut self, _: &LateContext<'a, 'tcx>, _: &'tcx hir::Crate) { }
134     fn check_mod(&mut self,
135                  _: &LateContext<'a, 'tcx>,
136                  _: &'tcx hir::Mod,
137                  _: Span,
138                  _: ast::NodeId) { }
139     fn check_mod_post(&mut self,
140                       _: &LateContext<'a, 'tcx>,
141                       _: &'tcx hir::Mod,
142                       _: Span,
143                       _: ast::NodeId) { }
144     fn check_foreign_item(&mut self, _: &LateContext<'a, 'tcx>, _: &'tcx hir::ForeignItem) { }
145     fn check_foreign_item_post(&mut self, _: &LateContext<'a, 'tcx>, _: &'tcx hir::ForeignItem) { }
146     fn check_item(&mut self, _: &LateContext<'a, 'tcx>, _: &'tcx hir::Item) { }
147     fn check_item_post(&mut self, _: &LateContext<'a, 'tcx>, _: &'tcx hir::Item) { }
148     fn check_local(&mut self, _: &LateContext<'a, 'tcx>, _: &'tcx hir::Local) { }
149     fn check_block(&mut self, _: &LateContext<'a, 'tcx>, _: &'tcx hir::Block) { }
150     fn check_block_post(&mut self, _: &LateContext<'a, 'tcx>, _: &'tcx hir::Block) { }
151     fn check_stmt(&mut self, _: &LateContext<'a, 'tcx>, _: &'tcx hir::Stmt) { }
152     fn check_arm(&mut self, _: &LateContext<'a, 'tcx>, _: &'tcx hir::Arm) { }
153     fn check_pat(&mut self, _: &LateContext<'a, 'tcx>, _: &'tcx hir::Pat) { }
154     fn check_decl(&mut self, _: &LateContext<'a, 'tcx>, _: &'tcx hir::Decl) { }
155     fn check_expr(&mut self, _: &LateContext<'a, 'tcx>, _: &'tcx hir::Expr) { }
156     fn check_expr_post(&mut self, _: &LateContext<'a, 'tcx>, _: &'tcx hir::Expr) { }
157     fn check_ty(&mut self, _: &LateContext<'a, 'tcx>, _: &'tcx hir::Ty) { }
158     fn check_generics(&mut self, _: &LateContext<'a, 'tcx>, _: &'tcx hir::Generics) { }
159     fn check_fn(&mut self,
160                 _: &LateContext<'a, 'tcx>,
161                 _: FnKind<'tcx>,
162                 _: &'tcx hir::FnDecl,
163                 _: &'tcx hir::Body,
164                 _: Span,
165                 _: ast::NodeId) { }
166     fn check_fn_post(&mut self,
167                      _: &LateContext<'a, 'tcx>,
168                      _: FnKind<'tcx>,
169                      _: &'tcx hir::FnDecl,
170                      _: &'tcx hir::Body,
171                      _: Span,
172                      _: ast::NodeId) { }
173     fn check_trait_item(&mut self, _: &LateContext<'a, 'tcx>, _: &'tcx hir::TraitItem) { }
174     fn check_trait_item_post(&mut self, _: &LateContext<'a, 'tcx>, _: &'tcx hir::TraitItem) { }
175     fn check_impl_item(&mut self, _: &LateContext<'a, 'tcx>, _: &'tcx hir::ImplItem) { }
176     fn check_impl_item_post(&mut self, _: &LateContext<'a, 'tcx>, _: &'tcx hir::ImplItem) { }
177     fn check_struct_def(&mut self,
178                         _: &LateContext<'a, 'tcx>,
179                         _: &'tcx hir::VariantData,
180                         _: ast::Name,
181                         _: &'tcx hir::Generics,
182                         _: ast::NodeId) { }
183     fn check_struct_def_post(&mut self,
184                              _: &LateContext<'a, 'tcx>,
185                              _: &'tcx hir::VariantData,
186                              _: ast::Name,
187                              _: &'tcx hir::Generics,
188                              _: ast::NodeId) { }
189     fn check_struct_field(&mut self, _: &LateContext<'a, 'tcx>, _: &'tcx hir::StructField) { }
190     fn check_variant(&mut self,
191                      _: &LateContext<'a, 'tcx>,
192                      _: &'tcx hir::Variant,
193                      _: &'tcx hir::Generics) { }
194     fn check_variant_post(&mut self,
195                           _: &LateContext<'a, 'tcx>,
196                           _: &'tcx hir::Variant,
197                           _: &'tcx hir::Generics) { }
198     fn check_lifetime(&mut self, _: &LateContext<'a, 'tcx>, _: &'tcx hir::Lifetime) { }
199     fn check_lifetime_def(&mut self, _: &LateContext<'a, 'tcx>, _: &'tcx hir::LifetimeDef) { }
200     fn check_path(&mut self, _: &LateContext<'a, 'tcx>, _: &'tcx hir::Path, _: ast::NodeId) { }
201     fn check_attribute(&mut self, _: &LateContext<'a, 'tcx>, _: &'tcx ast::Attribute) { }
202
203     /// Called when entering a syntax node that can have lint attributes such
204     /// as `#[allow(...)]`. Called with *all* the attributes of that node.
205     fn enter_lint_attrs(&mut self, _: &LateContext<'a, 'tcx>, _: &'tcx [ast::Attribute]) { }
206
207     /// Counterpart to `enter_lint_attrs`.
208     fn exit_lint_attrs(&mut self, _: &LateContext<'a, 'tcx>, _: &'tcx [ast::Attribute]) { }
209 }
210
211 pub trait EarlyLintPass: LintPass {
212     fn check_ident(&mut self, _: &EarlyContext, _: Span, _: ast::Ident) { }
213     fn check_crate(&mut self, _: &EarlyContext, _: &ast::Crate) { }
214     fn check_crate_post(&mut self, _: &EarlyContext, _: &ast::Crate) { }
215     fn check_mod(&mut self, _: &EarlyContext, _: &ast::Mod, _: Span, _: ast::NodeId) { }
216     fn check_mod_post(&mut self, _: &EarlyContext, _: &ast::Mod, _: Span, _: ast::NodeId) { }
217     fn check_foreign_item(&mut self, _: &EarlyContext, _: &ast::ForeignItem) { }
218     fn check_foreign_item_post(&mut self, _: &EarlyContext, _: &ast::ForeignItem) { }
219     fn check_item(&mut self, _: &EarlyContext, _: &ast::Item) { }
220     fn check_item_post(&mut self, _: &EarlyContext, _: &ast::Item) { }
221     fn check_local(&mut self, _: &EarlyContext, _: &ast::Local) { }
222     fn check_block(&mut self, _: &EarlyContext, _: &ast::Block) { }
223     fn check_block_post(&mut self, _: &EarlyContext, _: &ast::Block) { }
224     fn check_stmt(&mut self, _: &EarlyContext, _: &ast::Stmt) { }
225     fn check_arm(&mut self, _: &EarlyContext, _: &ast::Arm) { }
226     fn check_pat(&mut self, _: &EarlyContext, _: &ast::Pat) { }
227     fn check_expr(&mut self, _: &EarlyContext, _: &ast::Expr) { }
228     fn check_expr_post(&mut self, _: &EarlyContext, _: &ast::Expr) { }
229     fn check_ty(&mut self, _: &EarlyContext, _: &ast::Ty) { }
230     fn check_generics(&mut self, _: &EarlyContext, _: &ast::Generics) { }
231     fn check_fn(&mut self, _: &EarlyContext,
232         _: ast_visit::FnKind, _: &ast::FnDecl, _: Span, _: ast::NodeId) { }
233     fn check_fn_post(&mut self, _: &EarlyContext,
234         _: ast_visit::FnKind, _: &ast::FnDecl, _: Span, _: ast::NodeId) { }
235     fn check_trait_item(&mut self, _: &EarlyContext, _: &ast::TraitItem) { }
236     fn check_trait_item_post(&mut self, _: &EarlyContext, _: &ast::TraitItem) { }
237     fn check_impl_item(&mut self, _: &EarlyContext, _: &ast::ImplItem) { }
238     fn check_impl_item_post(&mut self, _: &EarlyContext, _: &ast::ImplItem) { }
239     fn check_struct_def(&mut self, _: &EarlyContext,
240         _: &ast::VariantData, _: ast::Ident, _: &ast::Generics, _: ast::NodeId) { }
241     fn check_struct_def_post(&mut self, _: &EarlyContext,
242         _: &ast::VariantData, _: ast::Ident, _: &ast::Generics, _: ast::NodeId) { }
243     fn check_struct_field(&mut self, _: &EarlyContext, _: &ast::StructField) { }
244     fn check_variant(&mut self, _: &EarlyContext, _: &ast::Variant, _: &ast::Generics) { }
245     fn check_variant_post(&mut self, _: &EarlyContext, _: &ast::Variant, _: &ast::Generics) { }
246     fn check_lifetime(&mut self, _: &EarlyContext, _: &ast::Lifetime) { }
247     fn check_lifetime_def(&mut self, _: &EarlyContext, _: &ast::LifetimeDef) { }
248     fn check_path(&mut self, _: &EarlyContext, _: &ast::Path, _: ast::NodeId) { }
249     fn check_path_list_item(&mut self, _: &EarlyContext, _: &ast::PathListItem) { }
250     fn check_attribute(&mut self, _: &EarlyContext, _: &ast::Attribute) { }
251
252     /// Called when entering a syntax node that can have lint attributes such
253     /// as `#[allow(...)]`. Called with *all* the attributes of that node.
254     fn enter_lint_attrs(&mut self, _: &EarlyContext, _: &[ast::Attribute]) { }
255
256     /// Counterpart to `enter_lint_attrs`.
257     fn exit_lint_attrs(&mut self, _: &EarlyContext, _: &[ast::Attribute]) { }
258 }
259
260 /// A lint pass boxed up as a trait object.
261 pub type EarlyLintPassObject = Box<EarlyLintPass + 'static>;
262 pub type LateLintPassObject = Box<for<'a, 'tcx> LateLintPass<'a, 'tcx> + 'static>;
263
264 /// Identifies a lint known to the compiler.
265 #[derive(Clone, Copy, Debug)]
266 pub struct LintId {
267     // Identity is based on pointer equality of this field.
268     lint: &'static Lint,
269 }
270
271 impl PartialEq for LintId {
272     fn eq(&self, other: &LintId) -> bool {
273         (self.lint as *const Lint) == (other.lint as *const Lint)
274     }
275 }
276
277 impl Eq for LintId { }
278
279 impl hash::Hash for LintId {
280     fn hash<H: hash::Hasher>(&self, state: &mut H) {
281         let ptr = self.lint as *const Lint;
282         ptr.hash(state);
283     }
284 }
285
286 impl LintId {
287     /// Get the `LintId` for a `Lint`.
288     pub fn of(lint: &'static Lint) -> LintId {
289         LintId {
290             lint,
291         }
292     }
293
294     pub fn lint_name_raw(&self) -> &'static str {
295         self.lint.name
296     }
297
298     /// Get the name of the lint.
299     pub fn to_string(&self) -> String {
300         self.lint.name_lower()
301     }
302 }
303
304 /// Setting for how to handle a lint.
305 #[derive(Clone, Copy, PartialEq, PartialOrd, Eq, Ord, Debug, Hash)]
306 pub enum Level {
307     Allow, Warn, Deny, Forbid
308 }
309
310 impl_stable_hash_for!(enum self::Level {
311     Allow,
312     Warn,
313     Deny,
314     Forbid
315 });
316
317 impl Level {
318     /// Convert a level to a lower-case string.
319     pub fn as_str(self) -> &'static str {
320         match self {
321             Allow => "allow",
322             Warn => "warn",
323             Deny => "deny",
324             Forbid => "forbid",
325         }
326     }
327
328     /// Convert a lower-case string to a level.
329     pub fn from_str(x: &str) -> Option<Level> {
330         match x {
331             "allow" => Some(Allow),
332             "warn" => Some(Warn),
333             "deny" => Some(Deny),
334             "forbid" => Some(Forbid),
335             _ => None,
336         }
337     }
338 }
339
340 /// How a lint level was set.
341 #[derive(Clone, Copy, PartialEq, Eq)]
342 pub enum LintSource {
343     /// Lint is at the default level as declared
344     /// in rustc or a plugin.
345     Default,
346
347     /// Lint level was set by an attribute.
348     Node(ast::Name, Span),
349
350     /// Lint level was set by a command-line flag.
351     CommandLine(Symbol),
352 }
353
354 impl_stable_hash_for!(enum self::LintSource {
355     Default,
356     Node(name, span),
357     CommandLine(text)
358 });
359
360 pub type LevelSource = (Level, LintSource);
361
362 pub mod builtin;
363 mod context;
364 mod levels;
365
366 pub use self::levels::{LintLevelSets, LintLevelMap};
367
368 pub struct LintBuffer {
369     map: NodeMap<Vec<BufferedEarlyLint>>,
370 }
371
372 impl LintBuffer {
373     pub fn new() -> LintBuffer {
374         LintBuffer { map: NodeMap() }
375     }
376
377     pub fn add_lint(&mut self,
378                     lint: &'static Lint,
379                     id: ast::NodeId,
380                     sp: MultiSpan,
381                     msg: &str) {
382         let early_lint = BufferedEarlyLint {
383             lint_id: LintId::of(lint),
384             ast_id: id,
385             span: sp,
386             msg: msg.to_string(),
387         };
388         let arr = self.map.entry(id).or_insert(Vec::new());
389         if !arr.contains(&early_lint) {
390             arr.push(early_lint);
391         }
392     }
393
394     pub fn take(&mut self, id: ast::NodeId) -> Vec<BufferedEarlyLint> {
395         self.map.remove(&id).unwrap_or(Vec::new())
396     }
397
398     pub fn get_any(&self) -> Option<&[BufferedEarlyLint]> {
399         let key = self.map.keys().next().map(|k| *k);
400         key.map(|k| &self.map[&k][..])
401     }
402 }
403
404 pub fn struct_lint_level<'a>(sess: &'a Session,
405                              lint: &'static Lint,
406                              level: Level,
407                              src: LintSource,
408                              span: Option<MultiSpan>,
409                              msg: &str)
410     -> DiagnosticBuilder<'a>
411 {
412     let mut err = match (level, span) {
413         (Level::Allow, _) => return sess.diagnostic().struct_dummy(),
414         (Level::Warn, Some(span)) => sess.struct_span_warn(span, msg),
415         (Level::Warn, None) => sess.struct_warn(msg),
416         (Level::Deny, Some(span)) |
417         (Level::Forbid, Some(span)) => sess.struct_span_err(span, msg),
418         (Level::Deny, None) |
419         (Level::Forbid, None) => sess.struct_err(msg),
420     };
421
422     let name = lint.name_lower();
423     match src {
424         LintSource::Default => {
425             sess.diag_note_once(
426                 &mut err,
427                 lint,
428                 &format!("#[{}({})] on by default", level.as_str(), name));
429         }
430         LintSource::CommandLine(lint_flag_val) => {
431             let flag = match level {
432                 Level::Warn => "-W",
433                 Level::Deny => "-D",
434                 Level::Forbid => "-F",
435                 Level::Allow => panic!(),
436             };
437             let hyphen_case_lint_name = name.replace("_", "-");
438             if lint_flag_val.as_str() == name {
439                 sess.diag_note_once(
440                     &mut err,
441                     lint,
442                     &format!("requested on the command line with `{} {}`",
443                              flag, hyphen_case_lint_name));
444             } else {
445                 let hyphen_case_flag_val = lint_flag_val.as_str().replace("_", "-");
446                 sess.diag_note_once(
447                     &mut err,
448                     lint,
449                     &format!("`{} {}` implied by `{} {}`",
450                              flag, hyphen_case_lint_name, flag,
451                              hyphen_case_flag_val));
452             }
453         }
454         LintSource::Node(lint_attr_name, src) => {
455             sess.diag_span_note_once(&mut err, lint, src, "lint level defined here");
456             if lint_attr_name.as_str() != name {
457                 let level_str = level.as_str();
458                 sess.diag_note_once(&mut err, lint,
459                                     &format!("#[{}({})] implied by #[{}({})]",
460                                              level_str, name, level_str, lint_attr_name));
461             }
462         }
463     }
464
465     err.code(DiagnosticId::Lint(name));
466
467     // Check for future incompatibility lints and issue a stronger warning.
468     let lints = sess.lint_store.borrow();
469     if let Some(future_incompatible) = lints.future_incompatible(LintId::of(lint)) {
470         let explanation = format!("this was previously accepted by the compiler \
471                                    but is being phased out; \
472                                    it will become a hard error in a future release!");
473         let citation = format!("for more information, see {}",
474                                future_incompatible.reference);
475         err.warn(&explanation);
476         err.note(&citation);
477     }
478
479     return err
480 }
481
482 fn lint_levels<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, cnum: CrateNum)
483     -> Rc<LintLevelMap>
484 {
485     assert_eq!(cnum, LOCAL_CRATE);
486     let mut builder = LintLevelMapBuilder {
487         levels: LintLevelSets::builder(tcx.sess),
488         tcx: tcx,
489     };
490     let krate = tcx.hir.krate();
491
492     builder.with_lint_attrs(ast::CRATE_NODE_ID, &krate.attrs, |builder| {
493         intravisit::walk_crate(builder, krate);
494     });
495
496     Rc::new(builder.levels.build_map())
497 }
498
499 struct LintLevelMapBuilder<'a, 'tcx: 'a> {
500     levels: levels::LintLevelsBuilder<'tcx>,
501     tcx: TyCtxt<'a, 'tcx, 'tcx>,
502 }
503
504 impl<'a, 'tcx> LintLevelMapBuilder<'a, 'tcx> {
505     fn with_lint_attrs<F>(&mut self,
506                           id: ast::NodeId,
507                           attrs: &[ast::Attribute],
508                           f: F)
509         where F: FnOnce(&mut Self)
510     {
511         let push = self.levels.push(attrs);
512         self.levels.register_id(self.tcx.hir.definitions().node_to_hir_id(id));
513         f(self);
514         self.levels.pop(push);
515     }
516 }
517
518 impl<'a, 'tcx> intravisit::Visitor<'tcx> for LintLevelMapBuilder<'a, 'tcx> {
519     fn nested_visit_map<'this>(&'this mut self) -> intravisit::NestedVisitorMap<'this, 'tcx> {
520         intravisit::NestedVisitorMap::All(&self.tcx.hir)
521     }
522
523     fn visit_item(&mut self, it: &'tcx hir::Item) {
524         self.with_lint_attrs(it.id, &it.attrs, |builder| {
525             intravisit::walk_item(builder, it);
526         });
527     }
528
529     fn visit_foreign_item(&mut self, it: &'tcx hir::ForeignItem) {
530         self.with_lint_attrs(it.id, &it.attrs, |builder| {
531             intravisit::walk_foreign_item(builder, it);
532         })
533     }
534
535     fn visit_expr(&mut self, e: &'tcx hir::Expr) {
536         self.with_lint_attrs(e.id, &e.attrs, |builder| {
537             intravisit::walk_expr(builder, e);
538         })
539     }
540
541     fn visit_struct_field(&mut self, s: &'tcx hir::StructField) {
542         self.with_lint_attrs(s.id, &s.attrs, |builder| {
543             intravisit::walk_struct_field(builder, s);
544         })
545     }
546
547     fn visit_variant(&mut self,
548                      v: &'tcx hir::Variant,
549                      g: &'tcx hir::Generics,
550                      item_id: ast::NodeId) {
551         self.with_lint_attrs(v.node.data.id(), &v.node.attrs, |builder| {
552             intravisit::walk_variant(builder, v, g, item_id);
553         })
554     }
555
556     fn visit_local(&mut self, l: &'tcx hir::Local) {
557         self.with_lint_attrs(l.id, &l.attrs, |builder| {
558             intravisit::walk_local(builder, l);
559         })
560     }
561
562     fn visit_trait_item(&mut self, trait_item: &'tcx hir::TraitItem) {
563         self.with_lint_attrs(trait_item.id, &trait_item.attrs, |builder| {
564             intravisit::walk_trait_item(builder, trait_item);
565         });
566     }
567
568     fn visit_impl_item(&mut self, impl_item: &'tcx hir::ImplItem) {
569         self.with_lint_attrs(impl_item.id, &impl_item.attrs, |builder| {
570             intravisit::walk_impl_item(builder, impl_item);
571         });
572     }
573 }
574
575 pub fn provide(providers: &mut Providers) {
576     providers.lint_levels = lint_levels;
577 }