diff options
author | David Malcolm <dmalcolm@redhat.com> | 2022-07-21 18:35:35 -0400 |
---|---|---|
committer | Arthur Cohen <arthur.cohen@embecosm.com> | 2022-08-29 10:39:36 +0200 |
commit | bc2fe97fad18ba518279b7058512606bc99cc2ca (patch) | |
tree | cd802e34bf2e896ec27ff69fc05cdec4037c4af2 /gcc/rust/rust-gcc-diagnostics.cc | |
parent | 05f1f87274a4ed13c0ab84de77d4253776b46637 (diff) | |
download | gcc-bc2fe97fad18ba518279b7058512606bc99cc2ca.zip gcc-bc2fe97fad18ba518279b7058512606bc99cc2ca.tar.gz gcc-bc2fe97fad18ba518279b7058512606bc99cc2ca.tar.bz2 |
Experiment with adding an error code to an error
Diffstat (limited to 'gcc/rust/rust-gcc-diagnostics.cc')
-rw-r--r-- | gcc/rust/rust-gcc-diagnostics.cc | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/gcc/rust/rust-gcc-diagnostics.cc b/gcc/rust/rust-gcc-diagnostics.cc index db07372..70b3cf2 100644 --- a/gcc/rust/rust-gcc-diagnostics.cc +++ b/gcc/rust/rust-gcc-diagnostics.cc @@ -22,6 +22,7 @@ #include "rust-diagnostics.h" #include "options.h" +#include "diagnostic-metadata.h" void rust_be_internal_error_at (const Location location, const std::string &errmsg) @@ -70,6 +71,39 @@ rust_be_error_at (const RichLocation &location, const std::string &errmsg) error_at (&gcc_loc, "%s", errmsg.c_str ()); } +class rust_error_code_rule : public diagnostic_metadata::rule +{ +public: + rust_error_code_rule (const ErrorCode code) : m_code (code) {} + + char *make_description () const final override + { + return xstrdup (m_code.m_str); + } + + char *make_url () const final override + { + return concat ("https://doc.rust-lang.org/error-index.html#", + m_code.m_str, + NULL); + } + +private: + const ErrorCode m_code; +}; + +void +rust_be_error_at (const RichLocation &location, const ErrorCode code, + const std::string &errmsg) +{ + /* TODO: 'error_at' would like a non-'const' 'rich_location *'. */ + rich_location &gcc_loc = const_cast<rich_location &> (location.get ()); + diagnostic_metadata m; + rust_error_code_rule rule (code); + m.add_rule (rule); + error_meta (&gcc_loc, m, "%s", errmsg.c_str ()); +} + void rust_be_get_quotechars (const char **open_qu, const char **close_qu) { |