Make '-A warnings' apply to all warnings, including feature gate warnings
This commit is contained in:
parent
5a6fb8eb98
commit
abc56a011a
15 changed files with 106 additions and 13 deletions
|
@ -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);
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
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> {
|
||||
|
|
|
@ -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),
|
||||
}
|
||||
|
|
0
src/test/run-make/allow-non-lint-warnings-cmdline/1
Normal file
0
src/test/run-make/allow-non-lint-warnings-cmdline/1
Normal file
12
src/test/run-make/allow-non-lint-warnings-cmdline/Makefile
Normal file
12
src/test/run-make/allow-non-lint-warnings-cmdline/Makefile
Normal file
|
@ -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
|
||||
|
15
src/test/run-make/allow-non-lint-warnings-cmdline/foo.rs
Normal file
15
src/test/run-make/allow-non-lint-warnings-cmdline/foo.rs
Normal file
|
@ -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() { }
|
0
src/test/run-make/allow-warnings-cmdline-stability/1
Normal file
0
src/test/run-make/allow-warnings-cmdline-stability/1
Normal file
19
src/test/run-make/allow-warnings-cmdline-stability/Makefile
Normal file
19
src/test/run-make/allow-warnings-cmdline-stability/Makefile
Normal file
|
@ -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
|
||||
|
||||
|
||||
|
||||
|
16
src/test/run-make/allow-warnings-cmdline-stability/bar.rs
Normal file
16
src/test/run-make/allow-warnings-cmdline-stability/bar.rs
Normal file
|
@ -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() { }
|
13
src/test/run-make/allow-warnings-cmdline-stability/foo.rs
Normal file
13
src/test/run-make/allow-warnings-cmdline-stability/foo.rs
Normal file
|
@ -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() }
|
Loading…
Add table
Add a link
Reference in a new issue