mirror of
https://github.com/rust-lang/rust.git
synced 2025-06-05 11:48:30 +00:00
Don't treat stashed warnings as errors
This commit is contained in:
parent
86c6ebee8f
commit
e9e46c95ce
@ -625,19 +625,13 @@ impl Handler {
|
|||||||
/// Stash a given diagnostic with the given `Span` and `StashKey` as the key for later stealing.
|
/// Stash a given diagnostic with the given `Span` and `StashKey` as the key for later stealing.
|
||||||
pub fn stash_diagnostic(&self, span: Span, key: StashKey, diag: Diagnostic) {
|
pub fn stash_diagnostic(&self, span: Span, key: StashKey, diag: Diagnostic) {
|
||||||
let mut inner = self.inner.borrow_mut();
|
let mut inner = self.inner.borrow_mut();
|
||||||
// FIXME(Centril, #69537): Consider reintroducing panic on overwriting a stashed diagnostic
|
inner.stash((span, key), diag);
|
||||||
// if/when we have a more robust macro-friendly replacement for `(span, key)` as a key.
|
|
||||||
// See the PR for a discussion.
|
|
||||||
inner.stashed_diagnostics.insert((span, key), diag);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Steal a previously stashed diagnostic with the given `Span` and `StashKey` as the key.
|
/// Steal a previously stashed diagnostic with the given `Span` and `StashKey` as the key.
|
||||||
pub fn steal_diagnostic(&self, span: Span, key: StashKey) -> Option<DiagnosticBuilder<'_, ()>> {
|
pub fn steal_diagnostic(&self, span: Span, key: StashKey) -> Option<DiagnosticBuilder<'_, ()>> {
|
||||||
self.inner
|
let mut inner = self.inner.borrow_mut();
|
||||||
.borrow_mut()
|
inner.steal((span, key)).map(|diag| DiagnosticBuilder::new_diagnostic(self, diag))
|
||||||
.stashed_diagnostics
|
|
||||||
.remove(&(span, key))
|
|
||||||
.map(|diag| DiagnosticBuilder::new_diagnostic(self, diag))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Emit all stashed diagnostics.
|
/// Emit all stashed diagnostics.
|
||||||
@ -1105,13 +1099,31 @@ impl HandlerInner {
|
|||||||
|
|
||||||
/// Emit all stashed diagnostics.
|
/// Emit all stashed diagnostics.
|
||||||
fn emit_stashed_diagnostics(&mut self) -> Option<ErrorGuaranteed> {
|
fn emit_stashed_diagnostics(&mut self) -> Option<ErrorGuaranteed> {
|
||||||
|
let has_errors = self.has_errors();
|
||||||
let diags = self.stashed_diagnostics.drain(..).map(|x| x.1).collect::<Vec<_>>();
|
let diags = self.stashed_diagnostics.drain(..).map(|x| x.1).collect::<Vec<_>>();
|
||||||
let mut reported = None;
|
let mut reported = None;
|
||||||
for mut diag in diags {
|
for mut diag in diags {
|
||||||
|
// Decrement the count tracking the stash; emitting will increment it.
|
||||||
if diag.is_error() {
|
if diag.is_error() {
|
||||||
reported = Some(ErrorGuaranteed(()));
|
if matches!(diag.level, Level::Error { lint: true }) {
|
||||||
|
self.lint_err_count -= 1;
|
||||||
|
} else {
|
||||||
|
self.err_count -= 1;
|
||||||
}
|
}
|
||||||
self.emit_diagnostic(&mut diag);
|
} else {
|
||||||
|
if diag.is_force_warn() {
|
||||||
|
self.warn_count -= 1;
|
||||||
|
} else {
|
||||||
|
// Unless they're forced, don't flush stashed warnings when
|
||||||
|
// there are errors, to avoid causing warning overload. The
|
||||||
|
// stash would've been stolen already if it were important.
|
||||||
|
if has_errors {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let reported_this = self.emit_diagnostic(&mut diag);
|
||||||
|
reported = reported.or(reported_this);
|
||||||
}
|
}
|
||||||
reported
|
reported
|
||||||
}
|
}
|
||||||
@ -1301,9 +1313,47 @@ impl HandlerInner {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn stash(&mut self, key: (Span, StashKey), diagnostic: Diagnostic) {
|
||||||
|
// Track the diagnostic for counts, but don't panic-if-treat-err-as-bug
|
||||||
|
// yet; that happens when we actually emit the diagnostic.
|
||||||
|
if diagnostic.is_error() {
|
||||||
|
if matches!(diagnostic.level, Level::Error { lint: true }) {
|
||||||
|
self.lint_err_count += 1;
|
||||||
|
} else {
|
||||||
|
self.err_count += 1;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Warnings are only automatically flushed if they're forced.
|
||||||
|
if diagnostic.is_force_warn() {
|
||||||
|
self.warn_count += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// FIXME(Centril, #69537): Consider reintroducing panic on overwriting a stashed diagnostic
|
||||||
|
// if/when we have a more robust macro-friendly replacement for `(span, key)` as a key.
|
||||||
|
// See the PR for a discussion.
|
||||||
|
self.stashed_diagnostics.insert(key, diagnostic);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn steal(&mut self, key: (Span, StashKey)) -> Option<Diagnostic> {
|
||||||
|
let diagnostic = self.stashed_diagnostics.remove(&key)?;
|
||||||
|
if diagnostic.is_error() {
|
||||||
|
if matches!(diagnostic.level, Level::Error { lint: true }) {
|
||||||
|
self.lint_err_count -= 1;
|
||||||
|
} else {
|
||||||
|
self.err_count -= 1;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if diagnostic.is_force_warn() {
|
||||||
|
self.warn_count -= 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Some(diagnostic)
|
||||||
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn err_count(&self) -> usize {
|
fn err_count(&self) -> usize {
|
||||||
self.err_count + self.stashed_diagnostics.len()
|
self.err_count
|
||||||
}
|
}
|
||||||
|
|
||||||
fn has_errors(&self) -> bool {
|
fn has_errors(&self) -> bool {
|
||||||
|
Loading…
Reference in New Issue
Block a user