Skip to content

Commit

Permalink
Make '-A warnings' apply to all warnings, including feature gate warn…
Browse files Browse the repository at this point in the history
…ings
  • Loading branch information
brson committed Jan 27, 2015
1 parent 5a6fb8e commit abc56a0
Show file tree
Hide file tree
Showing 15 changed files with 106 additions and 13 deletions.
12 changes: 11 additions & 1 deletion src/librustc/session/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion src/librustc_back/target/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_trans/back/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
4 changes: 2 additions & 2 deletions src/librustdoc/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down
12 changes: 9 additions & 3 deletions src/libsyntax/diagnostic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -195,17 +196,20 @@ 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,
cmsp: Option<(&codemap::CodeMap, Span)>,
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);
}
}
Expand All @@ -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
}
}

Expand Down
8 changes: 5 additions & 3 deletions src/libsyntax/feature_gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
diag.span_help(span, &format!("add #![feature({})] to the \
crate attributes to silence this warning",
feature)[]);
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> {
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/parse/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
Expand Down
Empty file.
12 changes: 12 additions & 0 deletions src/test/run-make/allow-non-lint-warnings-cmdline/Makefile
Original file line number Diff line number Diff line change
@@ -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 changes: 15 additions & 0 deletions src/test/run-make/allow-non-lint-warnings-cmdline/foo.rs
Original file line number Diff line number Diff line change
@@ -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() { }
Empty file.
19 changes: 19 additions & 0 deletions src/test/run-make/allow-warnings-cmdline-stability/Makefile
Original file line number Diff line number Diff line change
@@ -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 changes: 16 additions & 0 deletions src/test/run-make/allow-warnings-cmdline-stability/bar.rs
Original file line number Diff line number Diff line change
@@ -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 changes: 13 additions & 0 deletions src/test/run-make/allow-warnings-cmdline-stability/foo.rs
Original file line number Diff line number Diff line change
@@ -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() }

0 comments on commit abc56a0

Please sign in to comment.