aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/rust-diagnostics.cc
diff options
context:
space:
mode:
authorArthur Cohen <arthur.cohen@embecosm.com>2023-02-15 16:56:07 +0100
committerArthur Cohen <arthur.cohen@embecosm.com>2023-04-06 10:47:24 +0200
commit2785d591116a135215f473534b20f5da6075b265 (patch)
tree2efc2bab8b0f2ac49c354679a19305348249af3d /gcc/rust/rust-diagnostics.cc
parentfa7675df86ad2f22d0d349708da5cd363ed03f0f (diff)
downloadgcc-2785d591116a135215f473534b20f5da6075b265.zip
gcc-2785d591116a135215f473534b20f5da6075b265.tar.gz
gcc-2785d591116a135215f473534b20f5da6075b265.tar.bz2
gccrs: diagnostic: Refactor Error class
The class now allows for more variants including a `Hint` one which then gets emitted by calling `rust_inform`. This allows us to display hints/tips/notes in backtracking contexts such as the parser. gcc/rust/ChangeLog: * rust-diagnostics.h (struct Error): Add new Kind enum and various new static constructors to allow for hints as well. * rust-diagnostics.cc (Error::Error): Use new `kind` field properly. * checks/errors/privacy/rust-visibility-resolver.cc (VisibilityResolver::resolve_module_path): Use new Error API. * expand/rust-macro-builtins.cc (MacroBuiltin::include_handler): Likewise. * expand/rust-macro-expand.cc (parse_many): Likewise. (transcribe_type): Likewise. * parse/rust-parse-impl.h (Parser::parse_crate): Likewise. * rust-session-manager.cc (Session::handle_crate_name): Likewise. * ast/rust-ast.cc (Module::load_items): Likewise.
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