mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-23 07:14:28 +00:00
Do not print any warnings if '-A warnings' is specified on the command line
This commit is contained in:
parent
5804a30686
commit
9d01db1966
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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));
|
||||
|
Loading…
Reference in New Issue
Block a user