Skip to content

Commit 1a439d2

Browse files
committed
Simplify the error Registry methods a little
1 parent 6318d24 commit 1a439d2

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

src/librustc_errors/registry.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ pub struct Registry {
1010

1111
impl Registry {
1212
pub fn new(long_descriptions: &[(&'static str, Option<&'static str>)]) -> Registry {
13-
Registry { long_descriptions: long_descriptions.iter().cloned().collect() }
13+
Registry { long_descriptions: long_descriptions.iter().copied().collect() }
1414
}
1515

1616
/// This will panic if an invalid error code is passed in
1717
pub fn find_description(&self, code: &str) -> Option<&'static str> {
18-
self.try_find_description(code).unwrap()
18+
self.long_descriptions[code]
1919
}
2020
/// Returns `InvalidErrorCode` if the code requested does not exist in the
2121
/// registry. Otherwise, returns an `Option` where `None` means the error
@@ -24,9 +24,6 @@ impl Registry {
2424
&self,
2525
code: &str,
2626
) -> Result<Option<&'static str>, InvalidErrorCode> {
27-
if !self.long_descriptions.contains_key(code) {
28-
return Err(InvalidErrorCode);
29-
}
30-
Ok(*self.long_descriptions.get(code).unwrap())
27+
self.long_descriptions.get(code).copied().ok_or(InvalidErrorCode)
3128
}
3229
}

0 commit comments

Comments
 (0)