gccrs: error codes: Add rust_error_codes.def, refactor ErrorCode enum

gcc/rust/ChangeLog:

	* rust-diagnostics.cc: Rework `make_description` and `make_url` functions.
	* rust-diagnostics.h: Specify ErrorCode's underlying type,
	remove error_codes_strings table.
	* rust_error_codes.def: New file.
This commit is contained in:
Arthur Cohen 2023-07-28 14:33:34 +02:00
parent 886d56d0c5
commit fa13cfd08a
3 changed files with 556 additions and 1039 deletions

View file

@ -197,15 +197,40 @@ class rust_error_code_rule : public diagnostic_metadata::rule
public:
rust_error_code_rule (const ErrorCode code) : m_code (code) {}
void format_error_code (char *buffer) const
{
static_assert (
std::is_same<std::underlying_type<ErrorCode>::type, unsigned int>::value,
"invalid format specifier for ErrorCode's underlying type");
snprintf (buffer, 6, "E%04u",
(std::underlying_type<ErrorCode>::type) m_code);
}
char *make_description () const final override
{
return xstrdup (error_code_strings.at (m_code));
// 'E' + 4 characters + \0
char *buffer = new char[6];
// is that needed. does C++ suck that much that you
// can't zero initialize a new[]'d char array
memset (buffer, 0, 6);
format_error_code (buffer);
// we can use the `u` format specifier because the `ErrorCode` enum class
// "inherits" from `unsigned int` - add a static assertion to make sure
// that's the case before we do the formatting
return buffer;
}
char *make_url () const final override
{
return concat ("https://doc.rust-lang.org/error-index.html#",
error_code_strings.at (m_code), NULL);
char buffer[6] = {0};
format_error_code (buffer);
return concat ("https://doc.rust-lang.org/error-index.html#", buffer, NULL);
}
private:

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,506 @@
ERROR(0001), // this error code is no longer emitted by the compiler
ERROR(0002), // this error code is no longer emitted by the compiler
ERROR(0004),
ERROR(0005),
ERROR(0007), // this error code is no longer emitted by the compiler
ERROR(0009), // this error code is no longer emitted by the compiler
ERROR(0010),
ERROR(0013),
ERROR(0014), // this error code is no longer emitted by the compiler
ERROR(0015),
ERROR(0023),
ERROR(0025),
ERROR(0026),
ERROR(0027),
ERROR(0029),
ERROR(0030),
ERROR(0033),
ERROR(0034),
ERROR(0038),
ERROR(0040),
ERROR(0044),
ERROR(0045),
ERROR(0046),
ERROR(0049),
ERROR(0050),
ERROR(0053),
ERROR(0054),
ERROR(0055),
ERROR(0057),
ERROR(0059),
ERROR(0060),
ERROR(0061),
ERROR(0062),
ERROR(0063),
ERROR(0067),
ERROR(0069),
ERROR(0070),
ERROR(0071),
ERROR(0072),
ERROR(0073), // this error code is no longer emitted by the compiler
ERROR(0074), // this error code is no longer emitted by the compiler
ERROR(0075),
ERROR(0076),
ERROR(0077),
ERROR(0080),
ERROR(0081),
ERROR(0084),
ERROR(0087), // this error code is no longer emitted by the compiler
ERROR(0088), // this error code is no longer emitted by the compiler
ERROR(0089), // this error code is no longer emitted by the compiler
ERROR(0090), // this error code is no longer emitted by the compiler
ERROR(0091),
ERROR(0092),
ERROR(0093),
ERROR(0094),
ERROR(0106),
ERROR(0107),
ERROR(0109),
ERROR(0110), // this error code is no longer emitted by the compiler
ERROR(0116),
ERROR(0117),
ERROR(0118),
ERROR(0119),
ERROR(0120),
ERROR(0121),
ERROR(0124),
ERROR(0128),
ERROR(0130),
ERROR(0131),
ERROR(0132),
ERROR(0133),
ERROR(0136), // this error code is no longer emitted by the compiler
ERROR(0137), // this error code is no longer emitted by the compiler
ERROR(0138),
ERROR(0139), // this error code is no longer emitted by the compiler
ERROR(0152),
ERROR(0154), // this error code is no longer emitted by the compiler
ERROR(0158),
ERROR(0161),
ERROR(0162), // this error code is no longer emitted by the compiler
ERROR(0164),
ERROR(0165), // this error code is no longer emitted by the compiler
ERROR(0170),
ERROR(0178),
ERROR(0183),
ERROR(0184),
ERROR(0185),
ERROR(0186),
ERROR(0191),
ERROR(0192), // this error code is no longer emitted by the compiler
ERROR(0193), // this error code is no longer emitted by the compiler
ERROR(0195),
ERROR(0197),
ERROR(0198),
ERROR(0199),
ERROR(0200),
ERROR(0201),
ERROR(0203),
ERROR(0204),
ERROR(0205), // this error code is no longer emitted by the compiler
ERROR(0206),
ERROR(0207),
ERROR(0208), // this error code is no longer emitted by the compiler
ERROR(0210),
ERROR(0211), // this error code is no longer emitted by the compiler
ERROR(0212),
ERROR(0214),
ERROR(0220),
ERROR(0221),
ERROR(0222),
ERROR(0223),
ERROR(0224),
ERROR(0225),
ERROR(0226),
ERROR(0227),
ERROR(0228),
ERROR(0229),
ERROR(0230),
ERROR(0231),
ERROR(0232),
ERROR(0243), // this error code is no longer emitted by the compiler
ERROR(0244), // this error code is no longer emitted by the compiler
ERROR(0251), // this error code is no longer emitted by the compiler
ERROR(0252),
ERROR(0253),
ERROR(0254),
ERROR(0255),
ERROR(0256), // this error code is no longer emitted by the compiler
ERROR(0259),
ERROR(0260),
ERROR(0261),
ERROR(0262),
ERROR(0263), // this error code is no longer emitted by the compiler
ERROR(0264),
ERROR(0267),
ERROR(0268),
ERROR(0271),
ERROR(0275),
ERROR(0276),
ERROR(0277),
ERROR(0281), // this error code is no longer emitted by the compiler
ERROR(0282),
ERROR(0283),
ERROR(0284),
ERROR(0297), // this error code is no longer emitted by the compiler
ERROR(0301), // this error code is no longer emitted by the compiler
ERROR(0302), // this error code is no longer emitted by the compiler
ERROR(0303), // this error code is no longer emitted by the compiler
ERROR(0307),
ERROR(0308),
ERROR(0309),
ERROR(0310),
ERROR(0311),
ERROR(0312), // this error code is no longer emitted by the compiler
ERROR(0316),
ERROR(0317),
ERROR(0320),
ERROR(0321),
ERROR(0322),
ERROR(0323),
ERROR(0324),
ERROR(0325),
ERROR(0326),
ERROR(0328),
ERROR(0329), // this error code is no longer emitted by the compiler
ERROR(0364),
ERROR(0365),
ERROR(0366),
ERROR(0367),
ERROR(0368),
ERROR(0369),
ERROR(0370),
ERROR(0371),
ERROR(0373),
ERROR(0374),
ERROR(0375),
ERROR(0376),
ERROR(0377),
ERROR(0378),
ERROR(0379),
ERROR(0380),
ERROR(0381),
ERROR(0382),
ERROR(0383), // this error code is no longer emitted by the compiler
ERROR(0384),
ERROR(0386), // this error code is no longer emitted by the compiler
ERROR(0387), // this error code is no longer emitted by the compiler
ERROR(0388), // this error code is no longer emitted by the compiler
ERROR(0389), // this error code is no longer emitted by the compiler
ERROR(0390),
ERROR(0391),
ERROR(0392),
ERROR(0393),
ERROR(0398), // this error code is no longer emitted by the compiler
ERROR(0399),
ERROR(0401),
ERROR(0403),
ERROR(0404),
ERROR(0405),
ERROR(0407),
ERROR(0408),
ERROR(0409),
ERROR(0411),
ERROR(0412),
ERROR(0415),
ERROR(0416),
ERROR(0422),
ERROR(0423),
ERROR(0424),
ERROR(0425),
ERROR(0426),
ERROR(0428),
ERROR(0429),
ERROR(0430),
ERROR(0431),
ERROR(0432),
ERROR(0433),
ERROR(0434),
ERROR(0435),
ERROR(0436),
ERROR(0437),
ERROR(0438),
ERROR(0439), // this error code is no longer emitted by the compiler
ERROR(0445),
ERROR(0446),
ERROR(0447), // this error code is no longer emitted by the compiler
ERROR(0448), // this error code is no longer emitted by the compiler
ERROR(0449),
ERROR(0451),
ERROR(0452),
ERROR(0453),
ERROR(0454),
ERROR(0455),
ERROR(0457),
ERROR(0458),
ERROR(0459),
ERROR(0460),
ERROR(0461),
ERROR(0462),
ERROR(0463),
ERROR(0464),
ERROR(0466),
ERROR(0468),
ERROR(0469),
ERROR(0472),
ERROR(0476),
ERROR(0477), // this error code is no longer emitted by the compiler
ERROR(0478),
ERROR(0482), // this error code is no longer emitted by the compiler
ERROR(0491),
ERROR(0492),
ERROR(0493),
ERROR(0495), // this error code is no longer emitted by the compiler
ERROR(0496),
ERROR(0497), // this error code is no longer emitted by the compiler
ERROR(0498),
ERROR(0499),
ERROR(0500),
ERROR(0501),
ERROR(0502),
ERROR(0503),
ERROR(0504), // this error code is no longer emitted by the compiler
ERROR(0505),
ERROR(0506),
ERROR(0507),
ERROR(0508),
ERROR(0509),
ERROR(0510),
ERROR(0511),
ERROR(0512),
ERROR(0514),
ERROR(0515),
ERROR(0516),
ERROR(0517),
ERROR(0518),
ERROR(0519),
ERROR(0520),
ERROR(0521),
ERROR(0522),
ERROR(0523), // this error code is no longer emitted by the compiler
ERROR(0524),
ERROR(0525),
ERROR(0527),
ERROR(0528),
ERROR(0529),
ERROR(0530),
ERROR(0531),
ERROR(0532),
ERROR(0533),
ERROR(0534),
ERROR(0535),
ERROR(0536),
ERROR(0537),
ERROR(0538),
ERROR(0539),
ERROR(0541),
ERROR(0542),
ERROR(0543),
ERROR(0544),
ERROR(0545),
ERROR(0546),
ERROR(0547),
ERROR(0549),
ERROR(0550),
ERROR(0551),
ERROR(0552),
ERROR(0554),
ERROR(0556),
ERROR(0557),
ERROR(0559),
ERROR(0560),
ERROR(0561),
ERROR(0562),
ERROR(0565),
ERROR(0566),
ERROR(0567),
ERROR(0568),
ERROR(0569),
ERROR(0570),
ERROR(0571),
ERROR(0572),
ERROR(0573),
ERROR(0574),
ERROR(0575),
ERROR(0576),
ERROR(0577),
ERROR(0578),
ERROR(0579),
ERROR(0580),
ERROR(0581),
ERROR(0582),
ERROR(0583),
ERROR(0584),
ERROR(0585),
ERROR(0586),
ERROR(0587),
ERROR(0588),
ERROR(0589),
ERROR(0590),
ERROR(0591),
ERROR(0592),
ERROR(0593),
ERROR(0594),
ERROR(0595), // this error code is no longer emitted by the compiler
ERROR(0596),
ERROR(0597),
ERROR(0599),
ERROR(0600),
ERROR(0601),
ERROR(0602),
ERROR(0603),
ERROR(0604),
ERROR(0605),
ERROR(0606),
ERROR(0607),
ERROR(0608),
ERROR(0609),
ERROR(0610),
ERROR(0614),
ERROR(0615),
ERROR(0616),
ERROR(0617),
ERROR(0618),
ERROR(0619), // this error code is no longer emitted by the compiler
ERROR(0620),
ERROR(0621),
ERROR(0622),
ERROR(0623),
ERROR(0624),
ERROR(0625),
ERROR(0626),
ERROR(0627),
ERROR(0628),
ERROR(0631),
ERROR(0632), // this error code is no longer emitted by the compiler
ERROR(0633), // this error code is no longer emitted by the compiler
ERROR(0634),
ERROR(0635),
ERROR(0636),
ERROR(0637),
ERROR(0638),
ERROR(0639),
ERROR(0640),
ERROR(0641),
ERROR(0642),
ERROR(0643),
ERROR(0644),
ERROR(0646),
ERROR(0647),
ERROR(0648),
ERROR(0657),
ERROR(0658),
ERROR(0659),
ERROR(0660), // this error code is no longer emitted by the compiler
ERROR(0661), // this error code is no longer emitted by the compiler
ERROR(0662), // this error code is no longer emitted by the compiler
ERROR(0663), // this error code is no longer emitted by the compiler
ERROR(0664), // this error code is no longer emitted by the compiler
ERROR(0665), // this error code is no longer emitted by the compiler
ERROR(0666),
ERROR(0667),
ERROR(0668), // this error code is no longer emitted by the compiler
ERROR(0669), // this error code is no longer emitted by the compiler
ERROR(0670),
ERROR(0671), // this error code is no longer emitted by the compiler
ERROR(0687), // this error code is no longer emitted by the compiler
ERROR(0688), // this error code is no longer emitted by the compiler
ERROR(0689),
ERROR(0690),
ERROR(0691),
ERROR(0692),
ERROR(0693),
ERROR(0695),
ERROR(0696),
ERROR(0697),
ERROR(0698),
ERROR(0699),
ERROR(0700),
ERROR(0701),
ERROR(0703),
ERROR(0704),
ERROR(0705),
ERROR(0706),
ERROR(0708),
ERROR(0710),
ERROR(0711),
ERROR(0712),
ERROR(0713),
ERROR(0714),
ERROR(0715),
ERROR(0716),
ERROR(0717),
ERROR(0718),
ERROR(0719),
ERROR(0720),
ERROR(0722),
ERROR(0724),
ERROR(0725),
ERROR(0726),
ERROR(0727),
ERROR(0728),
ERROR(0729),
ERROR(0730),
ERROR(0731),
ERROR(0732),
ERROR(0733),
ERROR(0734),
ERROR(0735),
ERROR(0736),
ERROR(0737),
ERROR(0739),
ERROR(0740),
ERROR(0741),
ERROR(0742),
ERROR(0743),
ERROR(0744),
ERROR(0745),
ERROR(0746),
ERROR(0747),
ERROR(0748),
ERROR(0749),
ERROR(0750),
ERROR(0751),
ERROR(0752),
ERROR(0753),
ERROR(0754),
ERROR(0755),
ERROR(0756),
ERROR(0757),
ERROR(0758),
ERROR(0759), // this error code is no longer emitted by the compiler
ERROR(0760), // this error code is no longer emitted by the compiler
ERROR(0761),
ERROR(0762),
ERROR(0763),
ERROR(0764),
ERROR(0765),
ERROR(0766),
ERROR(0767),
ERROR(0768),
ERROR(0769),
ERROR(0770),
ERROR(0771),
ERROR(0772), // this error code is no longer emitted by the compiler
ERROR(0773),
ERROR(0774),
ERROR(0775),
ERROR(0776),
ERROR(0777),
ERROR(0778),
ERROR(0779),
ERROR(0780),
ERROR(0781),
ERROR(0782),
ERROR(0783),
ERROR(0784),
ERROR(0785),
ERROR(0786),
ERROR(0787),
ERROR(0788),
ERROR(0789),
ERROR(0790),
ERROR(0791),
ERROR(0792),
ERROR(0793),
ERROR(0794)