From 46a3314943ad9f0aa11f4aec50ae1e8c3e27b1a6 Mon Sep 17 00:00:00 2001 From: Huon Wilson Date: Thu, 17 Jul 2014 20:07:43 +1000 Subject: [PATCH] lint: add method to get level of a specific lint. This allows lint traversals to emit more information (when a lint is non-allow), or avoid doing expensive computations (when a lint is allow). --- src/librustc/lint/context.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/librustc/lint/context.rs b/src/librustc/lint/context.rs index 61aaf068c10..7d9ec29d701 100644 --- a/src/librustc/lint/context.rs +++ b/src/librustc/lint/context.rs @@ -317,6 +317,12 @@ impl<'a> Context<'a> { &self.tcx.sess } + /// Get the level of `lint` at the current position of the lint + /// traversal. + pub fn current_level(&self, lint: &'static Lint) -> Level { + self.lints.levels.find(&LintId::of(lint)).map_or(Allow, |&(lvl, _)| lvl) + } + fn lookup_and_emit(&self, lint: &'static Lint, span: Option, msg: &str) { let (level, src) = match self.lints.levels.find(&LintId::of(lint)) { None => return,