Skip to content

Commit

Permalink
lint: add method to get level of a specific lint.
Browse files Browse the repository at this point in the history
This allows lint traversals to emit more information (when a lint is
non-allow), or avoid doing expensive computations (when a lint is
allow).
  • Loading branch information
huonw committed Jul 17, 2014
1 parent 32cb44b commit 46a3314
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/librustc/lint/context.rs
Expand Up @@ -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<Span>, msg: &str) {
let (level, src) = match self.lints.levels.find(&LintId::of(lint)) {
None => return,
Expand Down

5 comments on commit 46a3314

@bors
Copy link
Contributor

@bors bors commented on 46a3314 Jul 18, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from pnkfelix
at huonw@46a3314

@bors
Copy link
Contributor

@bors bors commented on 46a3314 Jul 18, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging huonw/rust/lint-level-here = 46a3314 into auto

@bors
Copy link
Contributor

@bors bors commented on 46a3314 Jul 18, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

huonw/rust/lint-level-here = 46a3314 merged ok, testing candidate = 5ddc7b4

@bors
Copy link
Contributor

@bors bors commented on 46a3314 Jul 18, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = 5ddc7b4

Please sign in to comment.