aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/rust-diagnostics.cc
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/rust/rust-diagnostics.cc')
-rw-r--r--gcc/rust/rust-diagnostics.cc43
1 files changed, 39 insertions, 4 deletions
diff --git a/gcc/rust/rust-diagnostics.cc b/gcc/rust/rust-diagnostics.cc
index c0f02c2..4e5c2ec 100644
--- a/gcc/rust/rust-diagnostics.cc
+++ b/gcc/rust/rust-diagnostics.cc
@@ -231,14 +231,49 @@ rust_debug_loc (const Location location, const char *fmt, ...)
}
namespace Rust {
-Error::Error (const Location location, const char *fmt, ...) : locus (location)
+
+/**
+ * This function takes ownership of `args` and calls `va_end` on it
+ */
+static Error
+va_constructor (Error::Kind kind, Location locus, const char *fmt, va_list args)
+ RUST_ATTRIBUTE_GCC_DIAG (3, 0);
+
+static Error
+va_constructor (Error::Kind kind, Location locus, const char *fmt, va_list args)
+{
+ std::string message = expand_message (fmt, args);
+ message.shrink_to_fit ();
+ va_end (args);
+
+ return Error (kind, locus, message);
+}
+
+Error::Error (const Location location, const char *fmt, ...)
+ : kind (Kind::Err), locus (location)
{
va_list ap;
+ va_start (ap, fmt);
+ *this = va_constructor (Kind::Err, location, fmt, ap);
+}
+
+Error
+Error::Hint (const Location location, const char *fmt, ...)
+{
+ va_list ap;
va_start (ap, fmt);
- message = expand_message (fmt, ap);
- va_end (ap);
- message.shrink_to_fit ();
+ return va_constructor (Kind::Hint, location, fmt, ap);
+}
+
+Error
+Error::Fatal (const Location location, const char *fmt, ...)
+{
+ va_list ap;
+ va_start (ap, fmt);
+
+ return va_constructor (Kind::FatalErr, location, fmt, ap);
}
+
} // namespace Rust