1
Fork 0

Make '-A warnings' apply to all warnings, including feature gate warnings

This commit is contained in:
Brian Anderson 2015-01-26 15:42:24 -08:00
parent 5a6fb8eb98
commit abc56a011a
15 changed files with 106 additions and 13 deletions

View file

@ -305,9 +305,19 @@ pub fn build_session(sopts: config::Options,
local_crate_source_file: Option<Path>, local_crate_source_file: Option<Path>,
registry: diagnostics::registry::Registry) registry: diagnostics::registry::Registry)
-> Session { -> Session {
// FIXME: This is not general enough to make the warning lint completely override
// normal diagnostic warnings, since the warning lint can also be denied and changed
// later via the source code.
let can_print_warnings = sopts.lint_opts
.iter()
.filter(|&&(ref key, _)| *key == "warnings")
.map(|&(_, ref level)| *level != lint::Allow)
.last()
.unwrap_or(true);
let codemap = codemap::CodeMap::new(); let codemap = codemap::CodeMap::new();
let diagnostic_handler = let diagnostic_handler =
diagnostic::default_handler(sopts.color, Some(registry)); diagnostic::default_handler(sopts.color, Some(registry), can_print_warnings);
let span_diagnostic_handler = let span_diagnostic_handler =
diagnostic::mk_span_handler(diagnostic_handler, codemap); diagnostic::mk_span_handler(diagnostic_handler, codemap);

View file

@ -223,7 +223,7 @@ impl Target {
// this is 1. ugly, 2. error prone. // this is 1. ugly, 2. error prone.
let handler = diagnostic::default_handler(diagnostic::Auto, None); let handler = diagnostic::default_handler(diagnostic::Auto, None, true);
let get_req_field = |&: name: &str| { let get_req_field = |&: name: &str| {
match obj.find(name) match obj.find(name)

View file

@ -911,7 +911,7 @@ fn run_work_multithreaded(sess: &Session,
futures.push(rx); futures.push(rx);
thread::Builder::new().name(format!("codegen-{}", i)).spawn(move |:| { thread::Builder::new().name(format!("codegen-{}", i)).spawn(move |:| {
let diag_handler = mk_handler(box diag_emitter); let diag_handler = mk_handler(true, box diag_emitter);
// Must construct cgcx inside the proc because it has non-Send // Must construct cgcx inside the proc because it has non-Send
// fields. // fields.

View file

@ -108,7 +108,7 @@ pub fn run_core(search_paths: SearchPaths, cfgs: Vec<String>, externs: Externs,
}; };
let codemap = codemap::CodeMap::new(); let codemap = codemap::CodeMap::new();
let diagnostic_handler = diagnostic::default_handler(diagnostic::Auto, None); let diagnostic_handler = diagnostic::default_handler(diagnostic::Auto, None, true);
let span_diagnostic_handler = let span_diagnostic_handler =
diagnostic::mk_span_handler(diagnostic_handler, codemap); diagnostic::mk_span_handler(diagnostic_handler, codemap);

View file

@ -58,7 +58,7 @@ pub fn run(input: &str,
}; };
let codemap = CodeMap::new(); let codemap = CodeMap::new();
let diagnostic_handler = diagnostic::default_handler(diagnostic::Auto, None); let diagnostic_handler = diagnostic::default_handler(diagnostic::Auto, None, true);
let span_diagnostic_handler = let span_diagnostic_handler =
diagnostic::mk_span_handler(diagnostic_handler, codemap); diagnostic::mk_span_handler(diagnostic_handler, codemap);
@ -164,7 +164,7 @@ fn runtest(test: &str, cratename: &str, libs: SearchPaths,
// Compile the code // Compile the code
let codemap = CodeMap::new(); let codemap = CodeMap::new();
let diagnostic_handler = diagnostic::mk_handler(box emitter); let diagnostic_handler = diagnostic::mk_handler(true, box emitter);
let span_diagnostic_handler = let span_diagnostic_handler =
diagnostic::mk_span_handler(diagnostic_handler, codemap); diagnostic::mk_span_handler(diagnostic_handler, codemap);

View file

@ -143,6 +143,7 @@ impl SpanHandler {
pub struct Handler { pub struct Handler {
err_count: Cell<usize>, err_count: Cell<usize>,
emit: RefCell<Box<Emitter + Send>>, emit: RefCell<Box<Emitter + Send>>,
pub can_emit_warnings: bool
} }
impl Handler { impl Handler {
@ -195,6 +196,7 @@ impl Handler {
cmsp: Option<(&codemap::CodeMap, Span)>, cmsp: Option<(&codemap::CodeMap, Span)>,
msg: &str, msg: &str,
lvl: Level) { lvl: Level) {
if lvl == Warning && !self.can_emit_warnings { return }
self.emit.borrow_mut().emit(cmsp, msg, None, lvl); self.emit.borrow_mut().emit(cmsp, msg, None, lvl);
} }
pub fn emit_with_code(&self, pub fn emit_with_code(&self,
@ -202,10 +204,12 @@ impl Handler {
msg: &str, msg: &str,
code: &str, code: &str,
lvl: Level) { lvl: Level) {
if lvl == Warning && !self.can_emit_warnings { return }
self.emit.borrow_mut().emit(cmsp, msg, Some(code), lvl); self.emit.borrow_mut().emit(cmsp, msg, Some(code), lvl);
} }
pub fn custom_emit(&self, cm: &codemap::CodeMap, pub fn custom_emit(&self, cm: &codemap::CodeMap,
sp: RenderSpan, msg: &str, lvl: Level) { sp: RenderSpan, msg: &str, lvl: Level) {
if lvl == Warning && !self.can_emit_warnings { return }
self.emit.borrow_mut().custom_emit(cm, sp, msg, lvl); self.emit.borrow_mut().custom_emit(cm, sp, msg, lvl);
} }
} }
@ -218,14 +222,16 @@ pub fn mk_span_handler(handler: Handler, cm: codemap::CodeMap) -> SpanHandler {
} }
pub fn default_handler(color_config: ColorConfig, pub fn default_handler(color_config: ColorConfig,
registry: Option<diagnostics::registry::Registry>) -> Handler { registry: Option<diagnostics::registry::Registry>,
mk_handler(box EmitterWriter::stderr(color_config, registry)) can_emit_warnings: bool) -> Handler {
mk_handler(can_emit_warnings, box EmitterWriter::stderr(color_config, registry))
} }
pub fn mk_handler(e: Box<Emitter + Send>) -> Handler { pub fn mk_handler(can_emit_warnings: bool, e: Box<Emitter + Send>) -> Handler {
Handler { Handler {
err_count: Cell::new(0), err_count: Cell::new(0),
emit: RefCell::new(e), emit: RefCell::new(e),
can_emit_warnings: can_emit_warnings
} }
} }

View file

@ -191,9 +191,11 @@ pub fn emit_feature_err(diag: &SpanHandler, feature: &str, span: Span, explain:
pub fn emit_feature_warn(diag: &SpanHandler, feature: &str, span: Span, explain: &str) { pub fn emit_feature_warn(diag: &SpanHandler, feature: &str, span: Span, explain: &str) {
diag.span_warn(span, explain); diag.span_warn(span, explain);
diag.span_help(span, &format!("add #![feature({})] to the \ if diag.handler.can_emit_warnings {
crate attributes to silence this warning", diag.span_help(span, &format!("add #![feature({})] to the \
feature)[]); crate attributes to silence this warning",
feature)[]);
}
} }
struct MacroVisitor<'a> { struct MacroVisitor<'a> {

View file

@ -45,7 +45,7 @@ pub struct ParseSess {
pub fn new_parse_sess() -> ParseSess { pub fn new_parse_sess() -> ParseSess {
ParseSess { ParseSess {
span_diagnostic: mk_span_handler(default_handler(Auto, None), CodeMap::new()), span_diagnostic: mk_span_handler(default_handler(Auto, None, true), CodeMap::new()),
included_mod_stack: RefCell::new(Vec::new()), included_mod_stack: RefCell::new(Vec::new()),
node_id: Cell::new(1), node_id: Cell::new(1),
} }

View file

@ -0,0 +1,12 @@
-include ../tools.mk
# Test that -A warnings makes the 'empty trait list for derive' warning go away
OUT=$(shell $(RUSTC) foo.rs -A warnings 2>&1 | grep "warning" )
all: foo
test -z '$(OUT)'
# This is just to make sure the above command actually succeeds
foo:
$(RUSTC) foo.rs -A warnings

View file

@ -0,0 +1,15 @@
// Copyright 2015 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 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#[derive()]
#[derive(Copy)]
pub struct Foo;
pub fn main() { }

View file

@ -0,0 +1,19 @@
-include ../tools.mk
# Test that -A warnings makes the 'empty trait list for derive' warning go away
DEP=$(shell $(RUSTC) bar.rs)
OUT=$(shell $(RUSTC) foo.rs -A warnings 2>&1 | grep "warning" )
all: foo bar
test -z '$(OUT)'
# These are just to ensure that the above commands actually work
bar:
$(RUSTC) bar.rs
foo: bar
$(RUSTC) foo.rs -A warnings

View file

@ -0,0 +1,16 @@
// Copyright 2015 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 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![crate_type = "lib"]
#![feature(staged_api)]
#![staged_api]
#![unstable(feature = "test_feature")]
pub fn baz() { }

View file

@ -0,0 +1,13 @@
// Copyright 2015 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 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
extern crate bar;
pub fn main() { bar::baz() }