rustc_errors/registry.rs
1use rustc_data_structures::fx::FxHashMap;
2
3use crate::ErrCode;
4
5#[derive(Debug)]
6pub struct InvalidErrorCode;
7
8#[derive(Clone)]
9pub struct Registry {
10 long_descriptions: FxHashMap<ErrCode, &'static str>,
11}
12
13impl Registry {
14 pub fn new(long_descriptions: &[(ErrCode, &'static str)]) -> Registry {
15 Registry { long_descriptions: long_descriptions.iter().copied().collect() }
16 }
17
18 /// Returns `InvalidErrorCode` if the code requested does not exist in the
19 /// registry.
20 pub fn try_find_description(&self, code: ErrCode) -> Result<&'static str, InvalidErrorCode> {
21 self.long_descriptions.get(&code).copied().ok_or(InvalidErrorCode)
22 }
23}