Redundant Option Checks, Unwrap Safety (#1892)

Redundant Option Checks, unwrap Safety, unnecessary Lifetimes, Rust often infers lifetimes automatically

---------

Co-authored-by: Quied <dexflame3@gmail.com>
This commit is contained in:
shray sharma 2024-11-09 22:27:33 +01:00 committed by GitHub
parent 4f21731fec
commit d90f6b5864
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 14 additions and 13 deletions

View File

@ -28,8 +28,15 @@ pub fn parse_styles(opt: &cli::Opt) -> HashMap<String, Style> {
make_misc_styles(opt, &mut styles); make_misc_styles(opt, &mut styles);
let mut resolved_styles = resolve_style_references(styles, opt); let mut resolved_styles = resolve_style_references(styles, opt);
resolved_styles.get_mut("minus-emph-style").unwrap().is_emph = true; resolved_styles
resolved_styles.get_mut("plus-emph-style").unwrap().is_emph = true; .get_mut("minus-emph-style")
.unwrap_or_else(|| panic!("minus-emph-style not found in resolved styles"))
.is_emph = true;
resolved_styles
.get_mut("plus-emph-style")
.unwrap_or_else(|| panic!("plus-emph-style not found in resolved styles"))
.is_emph = true;
resolved_styles resolved_styles
} }
@ -114,7 +121,7 @@ fn parse_as_reference_to_git_config(style_string: &str, opt: &cli::Opt) -> Style
} }
} }
fn make_hunk_styles<'a>(opt: &'a cli::Opt, styles: &'a mut HashMap<&str, StyleReference>) { fn make_hunk_styles(opt: &cli::Opt, styles: &mut HashMap<&str, StyleReference>) {
let color_mode = opt.computed.color_mode; let color_mode = opt.computed.color_mode;
let true_color = opt.computed.true_color; let true_color = opt.computed.true_color;
let minus_style = style_from_str( let minus_style = style_from_str(

View File

@ -307,17 +307,11 @@ impl fmt::Debug for AnsiTermStyleEqualityKey {
} }
fn ansi_term_color_equality(a: Option<ansi_term::Color>, b: Option<ansi_term::Color>) -> bool { fn ansi_term_color_equality(a: Option<ansi_term::Color>, b: Option<ansi_term::Color>) -> bool {
match (a, b) { match a.zip(b) {
(None, None) => true, Some((a, b)) => {
(None, Some(_)) => false, a == b || ansi_term_16_color_equality(a, b) || ansi_term_16_color_equality(b, a)
(Some(_), None) => false,
(Some(a), Some(b)) => {
if a == b {
true
} else {
ansi_term_16_color_equality(a, b) || ansi_term_16_color_equality(b, a)
}
} }
None => a.is_none() && b.is_none(),
} }
} }