+use crate::{Applicability, Handler, Level, StashKey};
use crate::{Diagnostic, DiagnosticId, DiagnosticStyledString};
-use crate::{Applicability, Level, Handler, StashKey};
+use log::debug;
+use rustc_span::{MultiSpan, Span};
use std::fmt::{self, Debug};
use std::ops::{Deref, DerefMut};
use std::thread::panicking;
-use syntax_pos::{MultiSpan, Span};
-use log::debug;
/// Used for emitting structured error messages and other diagnostic information.
///
///
/// See `emit` and `delay_as_bug` for details.
pub fn emit_unless(&mut self, delay: bool) {
- if delay {
- self.delay_as_bug()
- } else {
- self.emit()
- }
+ if delay { self.delay_as_bug() } else { self.emit() }
}
/// Stashes diagnostic for possible later improvement in a different,
/// Converts the builder to a `Diagnostic` for later emission,
/// unless handler has disabled such buffering.
pub fn into_diagnostic(mut self) -> Option<(Diagnostic, &'a Handler)> {
- if self.0.handler.flags.dont_buffer_diagnostics ||
- self.0.handler.flags.treat_err_as_bug.is_some()
+ if self.0.handler.flags.dont_buffer_diagnostics
+ || self.0.handler.flags.treat_err_as_bug.is_some()
{
self.emit();
return None;
applicability: Applicability,
) -> &mut Self {
if !self.0.allow_suggestions {
- return self
+ return self;
}
- self.0.diagnostic.multipart_suggestion(
- msg,
- suggestion,
- applicability,
- );
+ self.0.diagnostic.multipart_suggestion(msg, suggestion, applicability);
self
}
applicability: Applicability,
) -> &mut Self {
if !self.0.allow_suggestions {
- return self
+ return self;
}
- self.0.diagnostic.tool_only_multipart_suggestion(
- msg,
- suggestion,
- applicability,
- );
+ self.0.diagnostic.tool_only_multipart_suggestion(msg, suggestion, applicability);
self
}
applicability: Applicability,
) -> &mut Self {
if !self.0.allow_suggestions {
- return self
+ return self;
}
- self.0.diagnostic.span_suggestion(
- sp,
- msg,
- suggestion,
- applicability,
- );
+ self.0.diagnostic.span_suggestion(sp, msg, suggestion, applicability);
self
}
applicability: Applicability,
) -> &mut Self {
if !self.0.allow_suggestions {
- return self
+ return self;
}
- self.0.diagnostic.span_suggestions(
- sp,
- msg,
- suggestions,
- applicability,
- );
+ self.0.diagnostic.span_suggestions(sp, msg, suggestions, applicability);
self
}
applicability: Applicability,
) -> &mut Self {
if !self.0.allow_suggestions {
- return self
+ return self;
}
- self.0.diagnostic.span_suggestion_short(
- sp,
- msg,
- suggestion,
- applicability,
- );
+ self.0.diagnostic.span_suggestion_short(sp, msg, suggestion, applicability);
self
}
applicability: Applicability,
) -> &mut Self {
if !self.0.allow_suggestions {
- return self
+ return self;
}
- self.0.diagnostic.span_suggestion_hidden(
- sp,
- msg,
- suggestion,
- applicability,
- );
+ self.0.diagnostic.span_suggestion_hidden(sp, msg, suggestion, applicability);
self
}
applicability: Applicability,
) -> &mut Self {
if !self.0.allow_suggestions {
- return self
+ return self;
}
- self.0.diagnostic.tool_only_span_suggestion(
- sp,
- msg,
- suggestion,
- applicability,
- );
+ self.0.diagnostic.tool_only_span_suggestion(sp, msg, suggestion, applicability);
self
}
/// Convenience function for internal use, clients should use one of the
/// struct_* methods on Handler.
- crate fn new_with_code(handler: &'a Handler,
- level: Level,
- code: Option<DiagnosticId>,
- message: &str)
- -> DiagnosticBuilder<'a> {
+ crate fn new_with_code(
+ handler: &'a Handler,
+ level: Level,
+ code: Option<DiagnosticId>,
+ message: &str,
+ ) -> DiagnosticBuilder<'a> {
let diagnostic = Diagnostic::new_with_code(level, code, message);
DiagnosticBuilder::new_diagnostic(handler, diagnostic)
}
/// Creates a new `DiagnosticBuilder` with an already constructed
/// diagnostic.
- crate fn new_diagnostic(handler: &'a Handler, diagnostic: Diagnostic)
- -> DiagnosticBuilder<'a> {
+ crate fn new_diagnostic(handler: &'a Handler, diagnostic: Diagnostic) -> DiagnosticBuilder<'a> {
DiagnosticBuilder(Box::new(DiagnosticBuilderInner {
handler,
diagnostic,
}
}
}
+
+#[macro_export]
+macro_rules! struct_span_err {
+ ($session:expr, $span:expr, $code:ident, $($message:tt)*) => ({
+ $session.struct_span_err_with_code(
+ $span,
+ &format!($($message)*),
+ $crate::error_code!($code),
+ )
+ })
+}
+
+#[macro_export]
+macro_rules! error_code {
+ ($code:ident) => {{ $crate::DiagnosticId::Error(stringify!($code).to_owned()) }};
+}