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
Original file line number Diff line number Diff line change
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

1 comment on commit 46a3314

@pnkfelix
Copy link

Choose a reason for hiding this comment

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

r+

Please sign in to comment.