diff --git a/src/librustc/session/mod.rs b/src/librustc/session/mod.rs index f90a60c9754a0..e62f3145e5a2e 100644 --- a/src/librustc/session/mod.rs +++ b/src/librustc/session/mod.rs @@ -305,9 +305,19 @@ pub fn build_session(sopts: config::Options, local_crate_source_file: Option, registry: diagnostics::registry::Registry) -> 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 diagnostic_handler = - diagnostic::default_handler(sopts.color, Some(registry)); + diagnostic::default_handler(sopts.color, Some(registry), can_print_warnings); let span_diagnostic_handler = diagnostic::mk_span_handler(diagnostic_handler, codemap); diff --git a/src/librustc_back/target/mod.rs b/src/librustc_back/target/mod.rs index 4626f2dc48339..dd0fa527f1727 100644 --- a/src/librustc_back/target/mod.rs +++ b/src/librustc_back/target/mod.rs @@ -223,7 +223,7 @@ impl Target { // 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| { match obj.find(name) diff --git a/src/librustc_trans/back/write.rs b/src/librustc_trans/back/write.rs index 5e48ce384be51..4fd456d813a63 100644 --- a/src/librustc_trans/back/write.rs +++ b/src/librustc_trans/back/write.rs @@ -911,7 +911,7 @@ fn run_work_multithreaded(sess: &Session, futures.push(rx); 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 // fields. diff --git a/src/librustdoc/core.rs b/src/librustdoc/core.rs index 04947e41663ec..a4cafe88bcdbd 100644 --- a/src/librustdoc/core.rs +++ b/src/librustdoc/core.rs @@ -108,7 +108,7 @@ pub fn run_core(search_paths: SearchPaths, cfgs: Vec, externs: Externs, }; 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 = diagnostic::mk_span_handler(diagnostic_handler, codemap); diff --git a/src/librustdoc/test.rs b/src/librustdoc/test.rs index 7f1bd9e6d5965..656daf6de8431 100644 --- a/src/librustdoc/test.rs +++ b/src/librustdoc/test.rs @@ -58,7 +58,7 @@ pub fn run(input: &str, }; 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 = diagnostic::mk_span_handler(diagnostic_handler, codemap); @@ -164,7 +164,7 @@ fn runtest(test: &str, cratename: &str, libs: SearchPaths, // Compile the code 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 = diagnostic::mk_span_handler(diagnostic_handler, codemap); diff --git a/src/libsyntax/diagnostic.rs b/src/libsyntax/diagnostic.rs index 0c7f6befc4e3e..01bb0e7a51c98 100644 --- a/src/libsyntax/diagnostic.rs +++ b/src/libsyntax/diagnostic.rs @@ -143,6 +143,7 @@ impl SpanHandler { pub struct Handler { err_count: Cell, emit: RefCell>, + pub can_emit_warnings: bool } impl Handler { @@ -195,6 +196,7 @@ impl Handler { cmsp: Option<(&codemap::CodeMap, Span)>, msg: &str, lvl: Level) { + if lvl == Warning && !self.can_emit_warnings { return } self.emit.borrow_mut().emit(cmsp, msg, None, lvl); } pub fn emit_with_code(&self, @@ -202,10 +204,12 @@ impl Handler { msg: &str, code: &str, lvl: Level) { + if lvl == Warning && !self.can_emit_warnings { return } self.emit.borrow_mut().emit(cmsp, msg, Some(code), lvl); } pub fn custom_emit(&self, cm: &codemap::CodeMap, sp: RenderSpan, msg: &str, lvl: Level) { + if lvl == Warning && !self.can_emit_warnings { return } 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, - registry: Option) -> Handler { - mk_handler(box EmitterWriter::stderr(color_config, registry)) + registry: Option, + can_emit_warnings: bool) -> Handler { + mk_handler(can_emit_warnings, box EmitterWriter::stderr(color_config, registry)) } -pub fn mk_handler(e: Box) -> Handler { +pub fn mk_handler(can_emit_warnings: bool, e: Box) -> Handler { Handler { err_count: Cell::new(0), emit: RefCell::new(e), + can_emit_warnings: can_emit_warnings } } diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs index e6046fb50dd3c..6e797844c18c0 100644 --- a/src/libsyntax/feature_gate.rs +++ b/src/libsyntax/feature_gate.rs @@ -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) { diag.span_warn(span, explain); - diag.span_help(span, &format!("add #![feature({})] to the \ - crate attributes to silence this warning", - feature)[]); + if diag.handler.can_emit_warnings { + diag.span_help(span, &format!("add #![feature({})] to the \ + crate attributes to silence this warning", + feature)[]); + } } struct MacroVisitor<'a> { diff --git a/src/libsyntax/parse/mod.rs b/src/libsyntax/parse/mod.rs index 8cb7ee5b33746..326aa1f3fc98b 100644 --- a/src/libsyntax/parse/mod.rs +++ b/src/libsyntax/parse/mod.rs @@ -45,7 +45,7 @@ pub struct ParseSess { pub fn new_parse_sess() -> 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()), node_id: Cell::new(1), } diff --git a/src/test/run-make/allow-non-lint-warnings-cmdline/1 b/src/test/run-make/allow-non-lint-warnings-cmdline/1 new file mode 100644 index 0000000000000..e69de29bb2d1d diff --git a/src/test/run-make/allow-non-lint-warnings-cmdline/Makefile b/src/test/run-make/allow-non-lint-warnings-cmdline/Makefile new file mode 100644 index 0000000000000..961342591aa51 --- /dev/null +++ b/src/test/run-make/allow-non-lint-warnings-cmdline/Makefile @@ -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 + diff --git a/src/test/run-make/allow-non-lint-warnings-cmdline/foo.rs b/src/test/run-make/allow-non-lint-warnings-cmdline/foo.rs new file mode 100644 index 0000000000000..19ce5d0a7ca40 --- /dev/null +++ b/src/test/run-make/allow-non-lint-warnings-cmdline/foo.rs @@ -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 or the MIT license +// , 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() { } diff --git a/src/test/run-make/allow-warnings-cmdline-stability/1 b/src/test/run-make/allow-warnings-cmdline-stability/1 new file mode 100644 index 0000000000000..e69de29bb2d1d diff --git a/src/test/run-make/allow-warnings-cmdline-stability/Makefile b/src/test/run-make/allow-warnings-cmdline-stability/Makefile new file mode 100644 index 0000000000000..64b7f58caeaf3 --- /dev/null +++ b/src/test/run-make/allow-warnings-cmdline-stability/Makefile @@ -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 + + + + diff --git a/src/test/run-make/allow-warnings-cmdline-stability/bar.rs b/src/test/run-make/allow-warnings-cmdline-stability/bar.rs new file mode 100644 index 0000000000000..6a683d96b03a0 --- /dev/null +++ b/src/test/run-make/allow-warnings-cmdline-stability/bar.rs @@ -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 or the MIT license +// , 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() { } diff --git a/src/test/run-make/allow-warnings-cmdline-stability/foo.rs b/src/test/run-make/allow-warnings-cmdline-stability/foo.rs new file mode 100644 index 0000000000000..fb23a214016a7 --- /dev/null +++ b/src/test/run-make/allow-warnings-cmdline-stability/foo.rs @@ -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 or the MIT license +// , 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() }