pub use emitter::ColorConfig;
+use rustc_lint_defs::LintExpectationId;
use Level::*;
use emitter::{is_case_difference, Emitter, EmitterWriter};
deduplicated_warn_count: usize,
future_breakage_diagnostics: Vec<Diagnostic>,
+
+ /// Lint [`Diagnostic`]s can be expected as described in [RFC-2383]. An
+ /// expected diagnostic will have the level `Expect` which additionally
+ /// carries the [`LintExpectationId`] of the expectation that can be
+ /// marked as fulfilled. This is a collection of all [`LintExpectationId`]s
+ /// that have been marked as fulfilled this way.
+ ///
+ /// [RFC-2383]: https://rust-lang.github.io/rfcs/2383-lint-reasons.html
+ fulfilled_expectations: FxHashSet<LintExpectationId>,
}
/// A key denoting where from a diagnostic was stashed.
emitted_diagnostics: Default::default(),
stashed_diagnostics: Default::default(),
future_breakage_diagnostics: Vec::new(),
+ fulfilled_expectations: Default::default(),
}),
}
}
DiagnosticBuilder::new(self, Level::Allow, msg)
}
+ /// Construct a builder at the `Expect` level with the `msg`.
+ pub fn struct_expect(&self, msg: &str, id: LintExpectationId) -> DiagnosticBuilder<'_, ()> {
+ DiagnosticBuilder::new(self, Level::Expect(id), msg)
+ }
+
/// Construct a builder at the `Error` level at the given `span` and with the `msg`.
pub fn struct_span_err(
&self,
pub fn emit_unused_externs(&self, lint_level: &str, unused_externs: &[&str]) {
self.inner.borrow_mut().emit_unused_externs(lint_level, unused_externs)
}
+
+ /// This methods steals all [`LintExpectationId`]s that are stored inside
+ /// [`HandlerInner`] and indicate that the linked expectation has been fulfilled.
+ pub fn steal_fulfilled_expectation_ids(&self) -> FxHashSet<LintExpectationId> {
+ std::mem::take(&mut self.inner.borrow_mut().fulfilled_expectations)
+ }
}
impl HandlerInner {
(*TRACK_DIAGNOSTICS)(diagnostic);
- if diagnostic.level == Allow {
+ if let Level::Expect(expectation_id) = diagnostic.level {
+ self.fulfilled_expectations.insert(expectation_id);
+ return;
+ } else if diagnostic.level == Allow {
return;
}
Help,
FailureNote,
Allow,
+ Expect(LintExpectationId),
}
impl fmt::Display for Level {
spec.set_fg(Some(Color::Cyan)).set_intense(true);
}
FailureNote => {}
- Allow => unreachable!(),
+ Allow | Expect(_) => unreachable!(),
}
spec
}
Help => "help",
FailureNote => "failure-note",
Allow => panic!("Shouldn't call on allowed error"),
+ Expect(_) => panic!("Shouldn't call on expected error"),
}
}