Skip to content

Commit d02ceac

Browse files
committed
--cap-lints allow switches off can_emit_warnings
This boolean field on the error `Handler` is toggled to silence warnings when `-A warnings` is passed. (This is actually a separate mechanism from the global lint level—whether there's some redundancy to be factored away here is an important question, but not one we concern ourselves with in this commit.) But the same rationale applies for `--cap-lints allow`. In particular, this makes the "soft" feature-gate warning introduced in 8492ad2 (which is not a lint, but just calls `struct_span_warn`) not pollute the builds of dependent crates. Thanks to @kennytm for pointing out the potential of `can_emit_warnings` for this purpose. Resolves #44213.
1 parent fd4bef5 commit d02ceac

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

src/librustc/session/mod.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -660,12 +660,16 @@ pub fn build_session_with_codemap(sopts: config::Options,
660660
// FIXME: This is not general enough to make the warning lint completely override
661661
// normal diagnostic warnings, since the warning lint can also be denied and changed
662662
// later via the source code.
663-
let can_print_warnings = sopts.lint_opts
663+
let warnings_allow = sopts.lint_opts
664664
.iter()
665665
.filter(|&&(ref key, _)| *key == "warnings")
666-
.map(|&(_, ref level)| *level != lint::Allow)
666+
.map(|&(_, ref level)| *level == lint::Allow)
667667
.last()
668-
.unwrap_or(true);
668+
.unwrap_or(false);
669+
let cap_lints_allow = sopts.lint_cap.map_or(false, |cap| cap == lint::Allow);
670+
671+
let can_print_warnings = !(warnings_allow || cap_lints_allow);
672+
669673
let treat_err_as_bug = sopts.debugging_opts.treat_err_as_bug;
670674

671675
let emitter: Box<Emitter> = match (sopts.error_format, emitter_dest) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright 2017 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+
// compile-flags: --cap-lints allow
12+
13+
// This tests that the fn_must_use feature-gate warning respects the lint
14+
// cap. (See discussion in Issue #44213.)
15+
16+
#![feature(rustc_attrs)]
17+
18+
#[must_use] // (no feature-gate warning because of the lint cap!)
19+
fn need_to_use_it() -> bool { true }
20+
21+
#[rustc_error]
22+
fn main() {} //~ ERROR compilation successful

0 commit comments

Comments
 (0)