1
Fork 0

Add SessionDiagnostic derive macro.

Co-authored-by: Oliver Scherer <github35764891676564198441@oli-obk.de>
This commit is contained in:
jumbatm 2020-08-27 20:00:21 +10:00 committed by jumbatm
parent 6f1bbf5ee0
commit 93eaf15646
9 changed files with 1106 additions and 10 deletions

View file

@ -237,6 +237,14 @@ enum DiagnosticBuilderMethod {
// Add more variants as needed to support one-time diagnostics.
}
/// Trait implemented by error types. This should not be implemented manually. Instead, use
/// `#[derive(SessionDiagnostic)]` -- see [rustc_macros::SessionDiagnostic].
pub trait SessionDiagnostic<'a> {
/// Write out as a diagnostic out of `sess`.
#[must_use]
fn into_diagnostic(self, sess: &'a Session) -> DiagnosticBuilder<'a>;
}
/// Diagnostic message ID, used by `Session.one_time_diagnostics` to avoid
/// emitting the same message more than once.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
@ -392,6 +400,9 @@ impl Session {
pub fn err(&self, msg: &str) {
self.diagnostic().err(msg)
}
pub fn emit_err<'a>(&'a self, err: impl SessionDiagnostic<'a>) {
err.into_diagnostic(self).emit()
}
pub fn err_count(&self) -> usize {
self.diagnostic().err_count()
}