@@ -197,15 +197,40 @@ class rust_error_code_rule : public diagnostic_metadata::rule
197
197
public:
198
198
rust_error_code_rule (const ErrorCode code) : m_code (code) {}
199
199
200
+ void format_error_code (char *buffer) const
201
+ {
202
+ static_assert (
203
+ std::is_same<std::underlying_type<ErrorCode>::type, unsigned int >::value,
204
+ " invalid format specifier for ErrorCode's underlying type" );
205
+
206
+ snprintf (buffer, 6 , " E%04u" ,
207
+ (std::underlying_type<ErrorCode>::type) m_code);
208
+ }
209
+
200
210
char *make_description () const final override
201
211
{
202
- return xstrdup (error_code_strings.at (m_code));
212
+ // 'E' + 4 characters + \0
213
+ char *buffer = new char [6 ];
214
+
215
+ // is that needed. does C++ suck that much that you
216
+ // can't zero initialize a new[]'d char array
217
+ memset (buffer, 0 , 6 );
218
+
219
+ format_error_code (buffer);
220
+
221
+ // we can use the `u` format specifier because the `ErrorCode` enum class
222
+ // "inherits" from `unsigned int` - add a static assertion to make sure
223
+ // that's the case before we do the formatting
224
+
225
+ return buffer;
203
226
}
204
227
205
228
char *make_url () const final override
206
229
{
207
- return concat (" https://doc.rust-lang.org/error-index.html#" ,
208
- error_code_strings.at (m_code), NULL );
230
+ char buffer[6 ] = {0 };
231
+ format_error_code (buffer);
232
+
233
+ return concat (" https://doc.rust-lang.org/error-index.html#" , buffer, NULL );
209
234
}
210
235
211
236
private:
0 commit comments