Skip to content

Commit 9d01db1

Browse files
author
Jakub Bukaj
committed
Do not print any warnings if '-A warnings' is specified on the command line
1 parent 5804a30 commit 9d01db1

File tree

2 files changed

+53
-3
lines changed

2 files changed

+53
-3
lines changed

src/librustc/session/config.rs

+34
Original file line numberDiff line numberDiff line change
@@ -948,4 +948,38 @@ mod test {
948948
assert!(test_items.next().is_some());
949949
assert!(test_items.next().is_none());
950950
}
951+
952+
#[test]
953+
fn test_can_print_warnings() {
954+
{
955+
let matches = getopts(&[
956+
"-Awarnings".to_string()
957+
], optgroups().as_slice()).unwrap();
958+
let registry = diagnostics::registry::Registry::new(&[]);
959+
let sessopts = build_session_options(&matches);
960+
let sess = build_session(sessopts, None, registry);
961+
assert!(!sess.can_print_warnings);
962+
}
963+
964+
{
965+
let matches = getopts(&[
966+
"-Awarnings".to_string(),
967+
"-Dwarnings".to_string()
968+
], optgroups().as_slice()).unwrap();
969+
let registry = diagnostics::registry::Registry::new(&[]);
970+
let sessopts = build_session_options(&matches);
971+
let sess = build_session(sessopts, None, registry);
972+
assert!(sess.can_print_warnings);
973+
}
974+
975+
{
976+
let matches = getopts(&[
977+
"-Adead_code".to_string()
978+
], optgroups().as_slice()).unwrap();
979+
let registry = diagnostics::registry::Registry::new(&[]);
980+
let sessopts = build_session_options(&matches);
981+
let sess = build_session(sessopts, None, registry);
982+
assert!(sess.can_print_warnings);
983+
}
984+
}
951985
}

src/librustc/session/mod.rs

+19-3
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ pub struct Session {
5454
/// The maximum recursion limit for potentially infinitely recursive
5555
/// operations such as auto-dereference and monomorphization.
5656
pub recursion_limit: Cell<uint>,
57+
58+
pub can_print_warnings: bool
5759
}
5860

5961
impl Session {
@@ -82,13 +84,19 @@ impl Session {
8284
self.diagnostic().handler().abort_if_errors()
8385
}
8486
pub fn span_warn(&self, sp: Span, msg: &str) {
85-
self.diagnostic().span_warn(sp, msg)
87+
if self.can_print_warnings {
88+
self.diagnostic().span_warn(sp, msg)
89+
}
8690
}
8791
pub fn span_warn_with_code(&self, sp: Span, msg: &str, code: &str) {
88-
self.diagnostic().span_warn_with_code(sp, msg, code)
92+
if self.can_print_warnings {
93+
self.diagnostic().span_warn_with_code(sp, msg, code)
94+
}
8995
}
9096
pub fn warn(&self, msg: &str) {
91-
self.diagnostic().handler().warn(msg)
97+
if self.can_print_warnings {
98+
self.diagnostic().handler().warn(msg)
99+
}
92100
}
93101
pub fn opt_span_warn(&self, opt_sp: Option<Span>, msg: &str) {
94102
match opt_sp {
@@ -247,6 +255,13 @@ pub fn build_session_(sopts: config::Options,
247255
}
248256
);
249257

258+
let can_print_warnings = sopts.lint_opts
259+
.iter()
260+
.filter(|&&(ref key, _)| key.as_slice() == "warnings")
261+
.map(|&(_, ref level)| *level != lint::Allow)
262+
.last()
263+
.unwrap_or(true);
264+
250265
let sess = Session {
251266
target: target_cfg,
252267
opts: sopts,
@@ -265,6 +280,7 @@ pub fn build_session_(sopts: config::Options,
265280
crate_metadata: RefCell::new(Vec::new()),
266281
features: RefCell::new(feature_gate::Features::new()),
267282
recursion_limit: Cell::new(64),
283+
can_print_warnings: can_print_warnings
268284
};
269285

270286
sess.lint_store.borrow_mut().register_builtin(Some(&sess));

0 commit comments

Comments
 (0)