Skip to content

Commit abc56a0

Browse files
committed
Make '-A warnings' apply to all warnings, including feature gate warnings
1 parent 5a6fb8e commit abc56a0

File tree

15 files changed

+106
-13
lines changed

15 files changed

+106
-13
lines changed

src/librustc/session/mod.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -305,9 +305,19 @@ pub fn build_session(sopts: config::Options,
305305
local_crate_source_file: Option<Path>,
306306
registry: diagnostics::registry::Registry)
307307
-> Session {
308+
// FIXME: This is not general enough to make the warning lint completely override
309+
// normal diagnostic warnings, since the warning lint can also be denied and changed
310+
// later via the source code.
311+
let can_print_warnings = sopts.lint_opts
312+
.iter()
313+
.filter(|&&(ref key, _)| *key == "warnings")
314+
.map(|&(_, ref level)| *level != lint::Allow)
315+
.last()
316+
.unwrap_or(true);
317+
308318
let codemap = codemap::CodeMap::new();
309319
let diagnostic_handler =
310-
diagnostic::default_handler(sopts.color, Some(registry));
320+
diagnostic::default_handler(sopts.color, Some(registry), can_print_warnings);
311321
let span_diagnostic_handler =
312322
diagnostic::mk_span_handler(diagnostic_handler, codemap);
313323

src/librustc_back/target/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ impl Target {
223223
// this is 1. ugly, 2. error prone.
224224

225225

226-
let handler = diagnostic::default_handler(diagnostic::Auto, None);
226+
let handler = diagnostic::default_handler(diagnostic::Auto, None, true);
227227

228228
let get_req_field = |&: name: &str| {
229229
match obj.find(name)

src/librustc_trans/back/write.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -911,7 +911,7 @@ fn run_work_multithreaded(sess: &Session,
911911
futures.push(rx);
912912

913913
thread::Builder::new().name(format!("codegen-{}", i)).spawn(move |:| {
914-
let diag_handler = mk_handler(box diag_emitter);
914+
let diag_handler = mk_handler(true, box diag_emitter);
915915

916916
// Must construct cgcx inside the proc because it has non-Send
917917
// fields.

src/librustdoc/core.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ pub fn run_core(search_paths: SearchPaths, cfgs: Vec<String>, externs: Externs,
108108
};
109109

110110
let codemap = codemap::CodeMap::new();
111-
let diagnostic_handler = diagnostic::default_handler(diagnostic::Auto, None);
111+
let diagnostic_handler = diagnostic::default_handler(diagnostic::Auto, None, true);
112112
let span_diagnostic_handler =
113113
diagnostic::mk_span_handler(diagnostic_handler, codemap);
114114

src/librustdoc/test.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ pub fn run(input: &str,
5858
};
5959

6060
let codemap = CodeMap::new();
61-
let diagnostic_handler = diagnostic::default_handler(diagnostic::Auto, None);
61+
let diagnostic_handler = diagnostic::default_handler(diagnostic::Auto, None, true);
6262
let span_diagnostic_handler =
6363
diagnostic::mk_span_handler(diagnostic_handler, codemap);
6464

@@ -164,7 +164,7 @@ fn runtest(test: &str, cratename: &str, libs: SearchPaths,
164164

165165
// Compile the code
166166
let codemap = CodeMap::new();
167-
let diagnostic_handler = diagnostic::mk_handler(box emitter);
167+
let diagnostic_handler = diagnostic::mk_handler(true, box emitter);
168168
let span_diagnostic_handler =
169169
diagnostic::mk_span_handler(diagnostic_handler, codemap);
170170

src/libsyntax/diagnostic.rs

+9-3
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ impl SpanHandler {
143143
pub struct Handler {
144144
err_count: Cell<usize>,
145145
emit: RefCell<Box<Emitter + Send>>,
146+
pub can_emit_warnings: bool
146147
}
147148

148149
impl Handler {
@@ -195,17 +196,20 @@ impl Handler {
195196
cmsp: Option<(&codemap::CodeMap, Span)>,
196197
msg: &str,
197198
lvl: Level) {
199+
if lvl == Warning && !self.can_emit_warnings { return }
198200
self.emit.borrow_mut().emit(cmsp, msg, None, lvl);
199201
}
200202
pub fn emit_with_code(&self,
201203
cmsp: Option<(&codemap::CodeMap, Span)>,
202204
msg: &str,
203205
code: &str,
204206
lvl: Level) {
207+
if lvl == Warning && !self.can_emit_warnings { return }
205208
self.emit.borrow_mut().emit(cmsp, msg, Some(code), lvl);
206209
}
207210
pub fn custom_emit(&self, cm: &codemap::CodeMap,
208211
sp: RenderSpan, msg: &str, lvl: Level) {
212+
if lvl == Warning && !self.can_emit_warnings { return }
209213
self.emit.borrow_mut().custom_emit(cm, sp, msg, lvl);
210214
}
211215
}
@@ -218,14 +222,16 @@ pub fn mk_span_handler(handler: Handler, cm: codemap::CodeMap) -> SpanHandler {
218222
}
219223

220224
pub fn default_handler(color_config: ColorConfig,
221-
registry: Option<diagnostics::registry::Registry>) -> Handler {
222-
mk_handler(box EmitterWriter::stderr(color_config, registry))
225+
registry: Option<diagnostics::registry::Registry>,
226+
can_emit_warnings: bool) -> Handler {
227+
mk_handler(can_emit_warnings, box EmitterWriter::stderr(color_config, registry))
223228
}
224229

225-
pub fn mk_handler(e: Box<Emitter + Send>) -> Handler {
230+
pub fn mk_handler(can_emit_warnings: bool, e: Box<Emitter + Send>) -> Handler {
226231
Handler {
227232
err_count: Cell::new(0),
228233
emit: RefCell::new(e),
234+
can_emit_warnings: can_emit_warnings
229235
}
230236
}
231237

src/libsyntax/feature_gate.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -191,9 +191,11 @@ pub fn emit_feature_err(diag: &SpanHandler, feature: &str, span: Span, explain:
191191

192192
pub fn emit_feature_warn(diag: &SpanHandler, feature: &str, span: Span, explain: &str) {
193193
diag.span_warn(span, explain);
194-
diag.span_help(span, &format!("add #![feature({})] to the \
195-
crate attributes to silence this warning",
196-
feature)[]);
194+
if diag.handler.can_emit_warnings {
195+
diag.span_help(span, &format!("add #![feature({})] to the \
196+
crate attributes to silence this warning",
197+
feature)[]);
198+
}
197199
}
198200

199201
struct MacroVisitor<'a> {

src/libsyntax/parse/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ pub struct ParseSess {
4545

4646
pub fn new_parse_sess() -> ParseSess {
4747
ParseSess {
48-
span_diagnostic: mk_span_handler(default_handler(Auto, None), CodeMap::new()),
48+
span_diagnostic: mk_span_handler(default_handler(Auto, None, true), CodeMap::new()),
4949
included_mod_stack: RefCell::new(Vec::new()),
5050
node_id: Cell::new(1),
5151
}

src/test/run-make/allow-non-lint-warnings-cmdline/1

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
-include ../tools.mk
2+
3+
# Test that -A warnings makes the 'empty trait list for derive' warning go away
4+
OUT=$(shell $(RUSTC) foo.rs -A warnings 2>&1 | grep "warning" )
5+
6+
all: foo
7+
test -z '$(OUT)'
8+
9+
# This is just to make sure the above command actually succeeds
10+
foo:
11+
$(RUSTC) foo.rs -A warnings
12+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#[derive()]
12+
#[derive(Copy)]
13+
pub struct Foo;
14+
15+
pub fn main() { }

src/test/run-make/allow-warnings-cmdline-stability/1

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
-include ../tools.mk
2+
3+
# Test that -A warnings makes the 'empty trait list for derive' warning go away
4+
DEP=$(shell $(RUSTC) bar.rs)
5+
OUT=$(shell $(RUSTC) foo.rs -A warnings 2>&1 | grep "warning" )
6+
7+
all: foo bar
8+
test -z '$(OUT)'
9+
10+
# These are just to ensure that the above commands actually work
11+
bar:
12+
$(RUSTC) bar.rs
13+
14+
foo: bar
15+
$(RUSTC) foo.rs -A warnings
16+
17+
18+
19+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#![crate_type = "lib"]
12+
#![feature(staged_api)]
13+
#![staged_api]
14+
#![unstable(feature = "test_feature")]
15+
16+
pub fn baz() { }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
extern crate bar;
12+
13+
pub fn main() { bar::baz() }

0 commit comments

Comments
 (0)