Auto merge of #86572 - rylev:force-warnings-always, r=nikomatsakis

Force warnings even when can_emit_warnings == false

Fixes an issue mentioned in #85512 with --cap-lints overriding --force-warnings.

Fixes https://github.com/rust-lang/rust/issues/86751

r? `@ehuss`
This commit is contained in:
bors
2021-07-06 16:50:33 +00:00
10 changed files with 116 additions and 12 deletions

View File

@@ -520,12 +520,28 @@ impl Handler {
}
/// Construct a builder at the `Warning` level at the given `span` and with the `msg`.
///
/// The builder will be canceled if warnings cannot be emitted.
pub fn struct_span_warn(&self, span: impl Into<MultiSpan>, msg: &str) -> DiagnosticBuilder<'_> {
let mut result = self.struct_warn(msg);
result.set_span(span);
result
}
/// Construct a builder at the `Warning` level at the given `span` and with the `msg`.
///
/// This will "force" the warning meaning it will not be canceled even
/// if warnings cannot be emitted.
pub fn struct_span_force_warn(
&self,
span: impl Into<MultiSpan>,
msg: &str,
) -> DiagnosticBuilder<'_> {
let mut result = self.struct_force_warn(msg);
result.set_span(span);
result
}
/// Construct a builder at the `Allow` level at the given `span` and with the `msg`.
pub fn struct_span_allow(
&self,
@@ -551,6 +567,8 @@ impl Handler {
}
/// Construct a builder at the `Warning` level with the `msg`.
///
/// The builder will be canceled if warnings cannot be emitted.
pub fn struct_warn(&self, msg: &str) -> DiagnosticBuilder<'_> {
let mut result = DiagnosticBuilder::new(self, Level::Warning, msg);
if !self.flags.can_emit_warnings {
@@ -559,6 +577,14 @@ impl Handler {
result
}
/// Construct a builder at the `Warning` level with the `msg`.
///
/// This will "force" a warning meaning it will not be canceled even
/// if warnings cannot be emitted.
pub fn struct_force_warn(&self, msg: &str) -> DiagnosticBuilder<'_> {
DiagnosticBuilder::new(self, Level::Warning, msg)
}
/// Construct a builder at the `Allow` level with the `msg`.
pub fn struct_allow(&self, msg: &str) -> DiagnosticBuilder<'_> {
DiagnosticBuilder::new(self, Level::Allow, msg)
@@ -801,7 +827,10 @@ impl HandlerInner {
self.future_breakage_diagnostics.push(diagnostic.clone());
}
if diagnostic.level == Warning && !self.flags.can_emit_warnings {
if diagnostic.level == Warning
&& !self.flags.can_emit_warnings
&& !diagnostic.is_force_warn()
{
if diagnostic.has_future_breakage() {
(*TRACK_DIAGNOSTICS)(diagnostic);
}
@@ -873,7 +902,7 @@ impl HandlerInner {
match (errors.len(), warnings.len()) {
(0, 0) => return,
(0, _) => self.emit_diagnostic(&Diagnostic::new(Level::Warning, &warnings)),
(0, _) => self.emitter.emit_diagnostic(&Diagnostic::new(Level::Warning, &warnings)),
(_, 0) => {
let _ = self.fatal(&errors);
}