Skip to content

Commit 92424f0

Browse files
committed
Add the warnings lint attribute
1 parent 42b44b2 commit 92424f0

File tree

2 files changed

+42
-2
lines changed

2 files changed

+42
-2
lines changed

src/librustc/middle/lint.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ pub enum lint {
9696

9797
missing_doc,
9898
unreachable_code,
99+
100+
warnings,
99101
}
100102

101103
pub fn level_to_str(lv: level) -> &'static str {
@@ -280,6 +282,13 @@ static lint_table: &'static [(&'static str, LintSpec)] = &[
280282
desc: "detects unreachable code",
281283
default: warn
282284
}),
285+
286+
("warnings",
287+
LintSpec {
288+
lint: warnings,
289+
desc: "mass-change the level for lints which produce warnings",
290+
default: warn
291+
}),
283292
];
284293

285294
/*
@@ -362,10 +371,11 @@ impl Context {
362371

363372
fn span_lint(&self, lint: lint, span: span, msg: &str) {
364373
let (level, src) = match self.curr.find(&(lint as uint)) {
374+
None => { return }
375+
Some(&(warn, src)) => (self.get_level(warnings), src),
365376
Some(&pair) => pair,
366-
None => { return; }
367377
};
368-
if level == allow { return; }
378+
if level == allow { return }
369379

370380
let mut note = None;
371381
let msg = match src {
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Copyright 2013 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+
#[deny(warnings)];
12+
13+
fn main() {
14+
while true {} //~ ERROR: infinite
15+
}
16+
17+
#[allow(warnings)]
18+
fn foo() {
19+
while true {}
20+
}
21+
22+
#[warn(warnings)]
23+
fn bar() {
24+
while true {} //~ WARNING: infinite
25+
}
26+
27+
#[forbid(warnings)]
28+
fn baz() {
29+
while true {} //~ ERROR: warnings
30+
}

0 commit comments

Comments
 (0)