about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorBrian Anderson <banderson@mozilla.com>2015-01-26 15:42:24 -0800
committerBrian Anderson <banderson@mozilla.com>2015-01-26 16:29:27 -0800
commitabc56a011a0c00ac85a896957ff6182d3d86f4aa (patch)
tree1fef69ab4bc5a385d29b84fa2b28b572f46bd9d3 /src
parent5a6fb8eb98f1e8d7188100ef83f25d01f30fff9f (diff)
downloadrust-abc56a011a0c00ac85a896957ff6182d3d86f4aa.tar.gz
rust-abc56a011a0c00ac85a896957ff6182d3d86f4aa.zip
Make '-A warnings' apply to all warnings, including feature gate warnings
Diffstat (limited to 'src')
-rw-r--r--src/librustc/session/mod.rs12
-rw-r--r--src/librustc_back/target/mod.rs2
-rw-r--r--src/librustc_trans/back/write.rs2
-rw-r--r--src/librustdoc/core.rs2
-rw-r--r--src/librustdoc/test.rs4
-rw-r--r--src/libsyntax/diagnostic.rs12
-rw-r--r--src/libsyntax/feature_gate.rs8
-rw-r--r--src/libsyntax/parse/mod.rs2
-rw-r--r--src/test/run-make/allow-non-lint-warnings-cmdline/10
-rw-r--r--src/test/run-make/allow-non-lint-warnings-cmdline/Makefile12
-rw-r--r--src/test/run-make/allow-non-lint-warnings-cmdline/foo.rs15
-rw-r--r--src/test/run-make/allow-warnings-cmdline-stability/10
-rw-r--r--src/test/run-make/allow-warnings-cmdline-stability/Makefile19
-rw-r--r--src/test/run-make/allow-warnings-cmdline-stability/bar.rs16
-rw-r--r--src/test/run-make/allow-warnings-cmdline-stability/foo.rs13
15 files changed, 106 insertions, 13 deletions
diff --git a/src/librustc/session/mod.rs b/src/librustc/session/mod.rs
index f90a60c9754..e62f3145e5a 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<Path>,
                      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 4626f2dc483..dd0fa527f17 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 5e48ce384be..4fd456d813a 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 04947e41663..a4cafe88bcd 100644
--- a/src/librustdoc/core.rs
+++ b/src/librustdoc/core.rs
@@ -108,7 +108,7 @@ pub fn run_core(search_paths: SearchPaths, cfgs: Vec<String>, 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 7f1bd9e6d59..656daf6de84 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 0c7f6befc4e..01bb0e7a51c 100644
--- a/src/libsyntax/diagnostic.rs
+++ b/src/libsyntax/diagnostic.rs
@@ -143,6 +143,7 @@ impl SpanHandler {
 pub struct Handler {
     err_count: Cell<usize>,
     emit: RefCell<Box<Emitter + Send>>,
+    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<diagnostics::registry::Registry>) -> Handler {
-    mk_handler(box EmitterWriter::stderr(color_config, registry))
+                       registry: Option<diagnostics::registry::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 {
         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 e6046fb50dd..6e797844c18 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 8cb7ee5b337..326aa1f3fc9 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 00000000000..e69de29bb2d
--- /dev/null
+++ b/src/test/run-make/allow-non-lint-warnings-cmdline/1
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 00000000000..961342591aa
--- /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 00000000000..19ce5d0a7ca
--- /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 <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() { }
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 00000000000..e69de29bb2d
--- /dev/null
+++ b/src/test/run-make/allow-warnings-cmdline-stability/1
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 00000000000..64b7f58caea
--- /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 00000000000..6a683d96b03
--- /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 <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() { }
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 00000000000..fb23a214016
--- /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 <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() }