about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJakub Bukaj <jakub@jakub.cc>2014-11-24 14:53:12 -0500
committerJakub Bukaj <jakub@jakub.cc>2014-11-26 22:21:52 +0000
commit9d01db1966a3ab073691eb8e5203e36624b9f992 (patch)
treeae15b481ed531e4fae600c41ca41107f6ad3e279
parent5804a306868aee5ff0a3d7829db7924978317f0e (diff)
downloadrust-9d01db1966a3ab073691eb8e5203e36624b9f992.tar.gz
rust-9d01db1966a3ab073691eb8e5203e36624b9f992.zip
Do not print any warnings if '-A warnings' is specified on the command line
-rw-r--r--src/librustc/session/config.rs34
-rw-r--r--src/librustc/session/mod.rs22
2 files changed, 53 insertions, 3 deletions
diff --git a/src/librustc/session/config.rs b/src/librustc/session/config.rs
index 8b4918b6db0..3c2dbae665f 100644
--- a/src/librustc/session/config.rs
+++ b/src/librustc/session/config.rs
@@ -948,4 +948,38 @@ mod test {
         assert!(test_items.next().is_some());
         assert!(test_items.next().is_none());
     }
+
+    #[test]
+    fn test_can_print_warnings() {
+        {
+            let matches = getopts(&[
+                "-Awarnings".to_string()
+            ], optgroups().as_slice()).unwrap();
+            let registry = diagnostics::registry::Registry::new(&[]);
+            let sessopts = build_session_options(&matches);
+            let sess = build_session(sessopts, None, registry);
+            assert!(!sess.can_print_warnings);
+        }
+
+        {
+            let matches = getopts(&[
+                "-Awarnings".to_string(),
+                "-Dwarnings".to_string()
+            ], optgroups().as_slice()).unwrap();
+            let registry = diagnostics::registry::Registry::new(&[]);
+            let sessopts = build_session_options(&matches);
+            let sess = build_session(sessopts, None, registry);
+            assert!(sess.can_print_warnings);
+        }
+
+        {
+            let matches = getopts(&[
+                "-Adead_code".to_string()
+            ], optgroups().as_slice()).unwrap();
+            let registry = diagnostics::registry::Registry::new(&[]);
+            let sessopts = build_session_options(&matches);
+            let sess = build_session(sessopts, None, registry);
+            assert!(sess.can_print_warnings);
+        }
+    }
 }
diff --git a/src/librustc/session/mod.rs b/src/librustc/session/mod.rs
index 89f6cda64d9..047e5985569 100644
--- a/src/librustc/session/mod.rs
+++ b/src/librustc/session/mod.rs
@@ -54,6 +54,8 @@ pub struct Session {
     /// The maximum recursion limit for potentially infinitely recursive
     /// operations such as auto-dereference and monomorphization.
     pub recursion_limit: Cell<uint>,
+
+    pub can_print_warnings: bool
 }
 
 impl Session {
@@ -82,13 +84,19 @@ impl Session {
         self.diagnostic().handler().abort_if_errors()
     }
     pub fn span_warn(&self, sp: Span, msg: &str) {
-        self.diagnostic().span_warn(sp, msg)
+        if self.can_print_warnings {
+            self.diagnostic().span_warn(sp, msg)
+        }
     }
     pub fn span_warn_with_code(&self, sp: Span, msg: &str, code: &str) {
-        self.diagnostic().span_warn_with_code(sp, msg, code)
+        if self.can_print_warnings {
+            self.diagnostic().span_warn_with_code(sp, msg, code)
+        }
     }
     pub fn warn(&self, msg: &str) {
-        self.diagnostic().handler().warn(msg)
+        if self.can_print_warnings {
+            self.diagnostic().handler().warn(msg)
+        }
     }
     pub fn opt_span_warn(&self, opt_sp: Option<Span>, msg: &str) {
         match opt_sp {
@@ -247,6 +255,13 @@ pub fn build_session_(sopts: config::Options,
         }
     );
 
+    let can_print_warnings = sopts.lint_opts
+        .iter()
+        .filter(|&&(ref key, _)| key.as_slice() == "warnings")
+        .map(|&(_, ref level)| *level != lint::Allow)
+        .last()
+        .unwrap_or(true);
+
     let sess = Session {
         target: target_cfg,
         opts: sopts,
@@ -265,6 +280,7 @@ pub fn build_session_(sopts: config::Options,
         crate_metadata: RefCell::new(Vec::new()),
         features: RefCell::new(feature_gate::Features::new()),
         recursion_limit: Cell::new(64),
+        can_print_warnings: can_print_warnings
     };
 
     sess.lint_store.borrow_mut().register_builtin(Some(&sess));