Skip to content

Commit

Permalink
Do not print any warnings if '-A warnings' is specified on the comman…
Browse files Browse the repository at this point in the history
…d line
  • Loading branch information
Jakub Bukaj committed Nov 26, 2014
1 parent 5804a30 commit 9d01db1
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 3 deletions.
34 changes: 34 additions & 0 deletions src/librustc/session/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
22 changes: 19 additions & 3 deletions src/librustc/session/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
Expand All @@ -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));
Expand Down

5 comments on commit 9d01db1

@bors
Copy link
Contributor

@bors bors commented on 9d01db1 Nov 26, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors
Copy link
Contributor

@bors bors commented on 9d01db1 Nov 26, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging jakub-/rust/issue-19100 = 9d01db1 into auto

@bors
Copy link
Contributor

@bors bors commented on 9d01db1 Nov 26, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

jakub-/rust/issue-19100 = 9d01db1 merged ok, testing candidate = fac5a07

@bors
Copy link
Contributor

@bors bors commented on 9d01db1 Nov 27, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors
Copy link
Contributor

@bors bors commented on 9d01db1 Nov 27, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = fac5a07

Please sign in to comment.