]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_errors/src/registry.rs
Merge commit 'd9ddce8a223cb9916389c039777b6966ea448dc8' into clippyup
[rust.git] / compiler / rustc_errors / src / registry.rs
1 use rustc_data_structures::fx::FxHashMap;
2
3 #[derive(Debug)]
4 pub struct InvalidErrorCode;
5
6 #[derive(Clone)]
7 pub struct Registry {
8     long_descriptions: FxHashMap<&'static str, Option<&'static str>>,
9 }
10
11 impl Registry {
12     pub fn new(long_descriptions: &[(&'static str, Option<&'static str>)]) -> Registry {
13         Registry { long_descriptions: long_descriptions.iter().copied().collect() }
14     }
15
16     /// Returns `InvalidErrorCode` if the code requested does not exist in the
17     /// registry. Otherwise, returns an `Option` where `None` means the error
18     /// code is valid but has no extended information.
19     pub fn try_find_description(
20         &self,
21         code: &str,
22     ) -> Result<Option<&'static str>, InvalidErrorCode> {
23         self.long_descriptions.get(code).copied().ok_or(InvalidErrorCode)
24     }
25 }