Skip to content

Commit a2ed355

Browse files
committed
Fix new clippy unnecessary_unwrap warning
error: called `unwrap` on `bytes_name` after checking its variant with `is_some` --> generator/src/generator/namespace/mod.rs:573:49 | 572 | if bytes_name.is_some() && field_size == union_size { | -------------------- the check is happening here 573 | outln!(out, "Self({})", bytes_name.unwrap()); | ^^^^^^^^^^^^^^^^^^^ | = help: try using `match` = help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.92.0/index.html#unnecessary_unwrap = note: `-D clippy::unnecessary-unwrap` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::unnecessary_unwrap)]` Signed-off-by: Uli Schlachter <psychon@znc.in>
1 parent b9847ff commit a2ed355

File tree

1 file changed

+19
-16
lines changed
  • generator/src/generator/namespace

1 file changed

+19
-16
lines changed

generator/src/generator/namespace/mod.rs

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -569,25 +569,28 @@ impl<'ns, 'c> NamespaceGenerator<'ns, 'c> {
569569
out,
570570
);
571571
let field_size = field.size().unwrap();
572-
if bytes_name.is_some() && field_size == union_size {
573-
outln!(out, "Self({})", bytes_name.unwrap());
574-
} else {
575-
outln!(out, "let value = [");
576-
for result_byte in result_bytes.iter() {
577-
outln!(out.indent(), "{},", result_byte);
572+
match bytes_name {
573+
Some(bytes_name) if field_size == union_size => {
574+
outln!(out, "Self({})", bytes_name);
578575
}
579-
// This is needed to handle cases such as Behavior.type or
580-
// Action.type from the XKB extension.
581-
//
582-
// FIXME: For those cases it might be better to omit the
583-
// serialize implementation.
584-
if field_size != union_size {
585-
for _ in 0..(union_size - field_size) {
586-
outln!(out.indent(), "0,");
576+
_ => {
577+
outln!(out, "let value = [");
578+
for result_byte in result_bytes.iter() {
579+
outln!(out.indent(), "{},", result_byte);
580+
}
581+
// This is needed to handle cases such as Behavior.type or
582+
// Action.type from the XKB extension.
583+
//
584+
// FIXME: For those cases it might be better to omit the
585+
// serialize implementation.
586+
if field_size != union_size {
587+
for _ in 0..(union_size - field_size) {
588+
outln!(out.indent(), "0,");
589+
}
587590
}
591+
outln!(out, "];");
592+
outln!(out, "Self(value)");
588593
}
589-
outln!(out, "];");
590-
outln!(out, "Self(value)");
591594
}
592595
});
593596
outln!(out, "}}");

0 commit comments

Comments
 (0)