Skip to content

Commit

Permalink
Fix clippy warnings on "match like matches macro"
Browse files Browse the repository at this point in the history
Now that our MSRV was increased, clippy has lots of "new" things it
wants use to use.

Example warning:

error: match expression looks like `matches!` macro
  --> generator/src/generator/mod.rs:84:5
   |
84 | /     match name {
85 | |         "bigreq" | "ge" | "xc_misc" | "xproto" => false,
86 | |         _ => true,
87 | |     }
   | |_____^ help: try this: `!matches!(name, "bigreq" | "ge" | "xc_misc" | "xproto")`
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#match_like_matches_macro

Signed-off-by: Uli Schlachter <psychon@znc.in>
  • Loading branch information
psychon committed Jan 30, 2022
1 parent 218856c commit aab6428
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 63 deletions.
5 changes: 1 addition & 4 deletions generator/src/generator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,7 @@ pub(crate) fn generate(module: &xcbgen::defs::Module) -> HashMap<PathBuf, String
}

fn ext_has_feature(name: &str) -> bool {
match name {
"bigreq" | "ge" | "xc_misc" | "xproto" => false,
_ => true,
}
!matches!(name, "bigreq" | "ge" | "xc_misc" | "xproto")
}

/// Add a Rust-header to the output saying that this file is generated.
Expand Down
34 changes: 16 additions & 18 deletions generator/src/generator/namespace/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -781,20 +781,18 @@ impl<'ns, 'c> NamespaceGenerator<'ns, 'c> {

// An enum is ok for bitmask if all its values are <bit>
// or have value zero (but not if all values are zero)
let ok_for_bitmask = enum_def
let ok_for_bitmask = enum_def.items.iter().all(|enum_item| {
matches!(
enum_item.value,
xcbdefs::EnumValue::Value(0) | xcbdefs::EnumValue::Bit(_)
)
}) && enum_def
.items
.iter()
.all(|enum_item| match enum_item.value {
xcbdefs::EnumValue::Value(0) | xcbdefs::EnumValue::Bit(_) => true,
_ => false,
})
&& enum_def
.items
.iter()
.any(|enum_item| match enum_item.value {
xcbdefs::EnumValue::Value(_) => false,
xcbdefs::EnumValue::Bit(_) => true,
});
.any(|enum_item| match enum_item.value {
xcbdefs::EnumValue::Value(_) => false,
xcbdefs::EnumValue::Bit(_) => true,
});

outln!(out, "impl std::fmt::Debug for {} {{", rust_name);
out.indented(|out| {
Expand Down Expand Up @@ -971,13 +969,13 @@ impl<'ns, 'c> NamespaceGenerator<'ns, 'c> {
}
type_ => type_.clone(),
};
match original_type {
matches!(
original_type,
xcbdefs::TypeRef::BuiltIn(xcbdefs::BuiltInType::Card8)
| xcbdefs::TypeRef::BuiltIn(xcbdefs::BuiltInType::Byte)
| xcbdefs::TypeRef::BuiltIn(xcbdefs::BuiltInType::Char)
| xcbdefs::TypeRef::BuiltIn(xcbdefs::BuiltInType::Void) => true,
_ => false,
}
| xcbdefs::TypeRef::BuiltIn(xcbdefs::BuiltInType::Byte)
| xcbdefs::TypeRef::BuiltIn(xcbdefs::BuiltInType::Char)
| xcbdefs::TypeRef::BuiltIn(xcbdefs::BuiltInType::Void)
)
}
}

Expand Down
6 changes: 1 addition & 5 deletions generator/src/generator/namespace/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -317,11 +317,7 @@ fn emit_value_post_parse(type_: &xcbdefs::FieldValueType, var_name: &str, out: &
}

fn needs_post_parse(type_: &xcbdefs::FieldValueType) -> bool {
if let xcbdefs::FieldValueSet::Enum(_) = type_.value_set {
true
} else {
false
}
matches!(type_.value_set, xcbdefs::FieldValueSet::Enum(_))
}

pub(super) fn can_use_simple_list_parsing(
Expand Down
24 changes: 9 additions & 15 deletions generator/src/generator/namespace/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -449,13 +449,9 @@ fn emit_request_struct(
out.indented(|out| {
let fields = request_def.fields.borrow();

let has_expr_fields = fields.iter().any(|field| {
if let xcbdefs::FieldDef::Expr(_) = field {
true
} else {
false
}
});
let has_expr_fields = fields
.iter()
.any(|field| matches!(field, xcbdefs::FieldDef::Expr(_)));
// Calculate `VirtualLen` field values because they
// may be used by <exprfield>s.
if has_expr_fields {
Expand Down Expand Up @@ -1356,10 +1352,7 @@ fn gather_request_fields(
.use_enum_type_in_field(&normal_field.type_)
.is_none()
{
match normal_field.type_.value_set {
xcbdefs::FieldValueSet::None => false,
_ => true,
}
!matches!(normal_field.type_.value_set, xcbdefs::FieldValueSet::None)
} else {
false
};
Expand Down Expand Up @@ -1460,10 +1453,11 @@ fn gather_request_fields(
.reply
.as_ref()
.map(|reply_def| {
reply_def.fields.borrow().iter().any(|field| match field {
xcbdefs::FieldDef::Fd(_) => true,
xcbdefs::FieldDef::FdList(_) => true,
_ => false,
reply_def.fields.borrow().iter().any(|field| {
matches!(
field,
xcbdefs::FieldDef::Fd(_) | xcbdefs::FieldDef::FdList(_)
)
})
})
.unwrap_or(false);
Expand Down
5 changes: 1 addition & 4 deletions generator/src/generator/namespace/resource_wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,10 +234,7 @@ fn generate_creator(
.use_enum_type_in_field(&normal_field.type_)
.is_none()
{
match normal_field.type_.value_set {
xcbdefs::FieldValueSet::None => false,
_ => true,
}
!matches!(normal_field.type_.value_set, xcbdefs::FieldValueSet::None)
} else {
false
};
Expand Down
8 changes: 5 additions & 3 deletions generator/src/generator/namespace/struct_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,11 @@ pub(super) fn emit_struct_type(
}
outln!(out, "}}");

let has_fds = fields.iter().any(|field| match field {
xcbdefs::FieldDef::Fd(_) | xcbdefs::FieldDef::FdList(_) => true,
_ => false,
let has_fds = fields.iter().any(|field| {
matches!(
field,
xcbdefs::FieldDef::Fd(_) | xcbdefs::FieldDef::FdList(_)
)
});

if generate_try_parse {
Expand Down
12 changes: 6 additions & 6 deletions generator/src/generator/namespace/switch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -996,12 +996,12 @@ fn case_has_single_visible_field(
fn needs_match_by_value(field: &xcbdefs::FieldDef) -> bool {
match field {
xcbdefs::FieldDef::Normal(normal_field) => {
match normal_field.type_.type_.get_resolved().get_original_type() {
xcbdefs::TypeRef::BuiltIn(_) => true,
xcbdefs::TypeRef::Xid(_) => true,
xcbdefs::TypeRef::XidUnion(_) => true,
_ => false,
}
matches!(
normal_field.type_.type_.get_resolved().get_original_type(),
xcbdefs::TypeRef::BuiltIn(_)
| xcbdefs::TypeRef::Xid(_)
| xcbdefs::TypeRef::XidUnion(_)
)
}
_ => false,
}
Expand Down
5 changes: 1 addition & 4 deletions src/cursor/find_cursor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,7 @@ fn parse_inherits_impl(input: &mut impl BufRead) -> Result<Vec<String>, IOError>
to_parse = &to_parse[1..];

fn should_skip(c: u8) -> bool {
match c {
b' ' | b'\t' | b'\n' | b';' | b',' => true,
_ => false,
}
matches!(c, b' ' | b'\t' | b'\n' | b';' | b',')
}

// Iterate over the pieces
Expand Down
5 changes: 1 addition & 4 deletions src/resource_manager/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@ use super::{Binding, Component, Entry};

/// Check if a character (well, u8) is an octal digit
fn is_octal_digit(c: u8) -> bool {
match c {
b'0' | b'1' | b'2' | b'3' | b'4' | b'5' | b'6' | b'7' => true,
_ => false,
}
matches!(c, b'0' | b'1' | b'2' | b'3' | b'4' | b'5' | b'6' | b'7')
}

/// Find the longest prefix of the given data where the given callback returns true
Expand Down

0 comments on commit aab6428

Please sign in to comment.