From 92424f0670723e417a96a96310a6ad871994c6b7 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Sat, 15 Jun 2013 20:58:11 -0700 Subject: [PATCH] Add the `warnings` lint attribute --- src/librustc/middle/lint.rs | 14 +++++++-- src/test/compile-fail/lint-change-warnings.rs | 30 +++++++++++++++++++ 2 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 src/test/compile-fail/lint-change-warnings.rs diff --git a/src/librustc/middle/lint.rs b/src/librustc/middle/lint.rs index 17ff5930078..5c36ab7750c 100644 --- a/src/librustc/middle/lint.rs +++ b/src/librustc/middle/lint.rs @@ -96,6 +96,8 @@ pub enum lint { missing_doc, unreachable_code, + + warnings, } pub fn level_to_str(lv: level) -> &'static str { @@ -280,6 +282,13 @@ static lint_table: &'static [(&'static str, LintSpec)] = &[ desc: "detects unreachable code", default: warn }), + + ("warnings", + LintSpec { + lint: warnings, + desc: "mass-change the level for lints which produce warnings", + default: warn + }), ]; /* @@ -362,10 +371,11 @@ impl Context { fn span_lint(&self, lint: lint, span: span, msg: &str) { let (level, src) = match self.curr.find(&(lint as uint)) { + None => { return } + Some(&(warn, src)) => (self.get_level(warnings), src), Some(&pair) => pair, - None => { return; } }; - if level == allow { return; } + if level == allow { return } let mut note = None; let msg = match src { diff --git a/src/test/compile-fail/lint-change-warnings.rs b/src/test/compile-fail/lint-change-warnings.rs new file mode 100644 index 00000000000..977abc4dc0d --- /dev/null +++ b/src/test/compile-fail/lint-change-warnings.rs @@ -0,0 +1,30 @@ +// Copyright 2013 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#[deny(warnings)]; + +fn main() { + while true {} //~ ERROR: infinite +} + +#[allow(warnings)] +fn foo() { + while true {} +} + +#[warn(warnings)] +fn bar() { + while true {} //~ WARNING: infinite +} + +#[forbid(warnings)] +fn baz() { + while true {} //~ ERROR: warnings +}