Skip to content

Commit

Permalink
Resolve manual_let_else clippy lints in experimental-enum-variants-fr…
Browse files Browse the repository at this point in the history
…om-header

    warning: this could be rewritten as `let...else`
       --> macro/src/load.rs:107:13
        |
    107 | /             let name = match &decl.name {
    108 | |                 Some(name) => name,
    109 | |                 // Can ignore enums inside an anonymous namespace.
    110 | |                 None => return,
    111 | |             };
        | |______________^ help: consider writing: `let Some(name) = &decl.name else { return };`
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#manual_let_else
        = note: `-W clippy::manual-let-else` implied by `-W clippy::pedantic`
        = help: to override `-W clippy::pedantic` add `#[allow(clippy::manual_let_else)]`

    warning: this could be rewritten as `let...else`
       --> macro/src/load.rs:116:13
        |
    116 | /             let name = match &decl.name {
    117 | |                 Some(name) => name,
    118 | |                 None => return,
    119 | |             };
        | |______________^ help: consider writing: `let Some(name) = &decl.name else { return };`
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#manual_let_else

    warning: this could be rewritten as `let...else`
       --> macro/src/load.rs:130:21
        |
    130 | /                     let fixed_underlying_type = match &decl.fixed_underlying_type {
    131 | |                         Some(fixed_underlying_type) => fixed_underlying_type,
    132 | |                         None => {
    133 | |                             let span = &enm.variants_from_header_attr;
    ...   |
    143 | |                     };
        | |______________________^
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#manual_let_else
    help: consider writing
        |
    130 ~                     let Some(fixed_underlying_type) = &decl.fixed_underlying_type else {
    131 +                             let span = &enm.variants_from_header_attr;
    132 +                             let name = &enm.name.cxx;
    133 +                             let qual_name = CxxName(&enm.name);
    134 +                             let msg = format!(
    135 +                                 "implicit implementation-defined repr for enum {} is not supported yet; consider changing its C++ definition to `enum {}: int {{...}}",
    136 +                                 qual_name, name,
    137 +                             );
    138 +                             cx.error(span, msg);
    139 +                             return;
    140 +                         };
        |

    warning: this could be rewritten as `let...else`
       --> macro/src/load.rs:172:17
        |
    172 | /                 let cxx_name = match ForeignName::parse(&decl.name, span) {
    173 | |                     Ok(foreign_name) => foreign_name,
    174 | |                     Err(_) => {
    175 | |                         let span = &enm.variants_from_header_attr;
    ...   |
    179 | |                 };
        | |__________________^
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#manual_let_else
    help: consider writing
        |
    172 ~                 let Ok(cxx_name) = ForeignName::parse(&decl.name, span) else {
    173 +                         let span = &enm.variants_from_header_attr;
    174 +                         let msg = format!("unsupported C++ variant name: {}", decl.name);
    175 +                         return cx.error(span, msg);
    176 +                     };
        |
  • Loading branch information
dtolnay committed Dec 27, 2024
1 parent d54e446 commit fb82424
Showing 1 changed file with 18 additions and 26 deletions.
44 changes: 18 additions & 26 deletions macro/src/load.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,18 +104,16 @@ fn traverse<'a>(
) {
match &node.kind {
Clang::NamespaceDecl(decl) => {
let name = match &decl.name {
Some(name) => name,
let Some(name) = &decl.name else {
// Can ignore enums inside an anonymous namespace.
None => return,
return;
};
namespace.push(name);
idx = None;
}
Clang::EnumDecl(decl) => {
let name = match &decl.name {
Some(name) => name,
None => return,
let Some(name) = &decl.name else {
return;
};
idx = None;
for (i, enm) in variants_from_header.iter_mut().enumerate() {
Expand All @@ -127,19 +125,16 @@ fn traverse<'a>(
cx.error(span, msg);
return;
}
let fixed_underlying_type = match &decl.fixed_underlying_type {
Some(fixed_underlying_type) => fixed_underlying_type,
None => {
let span = &enm.variants_from_header_attr;
let name = &enm.name.cxx;
let qual_name = CxxName(&enm.name);
let msg = format!(
"implicit implementation-defined repr for enum {} is not supported yet; consider changing its C++ definition to `enum {}: int {{...}}",
qual_name, name,
);
cx.error(span, msg);
return;
}
let Some(fixed_underlying_type) = &decl.fixed_underlying_type else {
let span = &enm.variants_from_header_attr;
let name = &enm.name.cxx;
let qual_name = CxxName(&enm.name);
let msg = format!(
"implicit implementation-defined repr for enum {} is not supported yet; consider changing its C++ definition to `enum {}: int {{...}}",
qual_name, name,
);
cx.error(span, msg);
return;
};
let repr = translate_qual_type(
cx,
Expand Down Expand Up @@ -169,13 +164,10 @@ fn traverse<'a>(
.get_ident()
.unwrap()
.span();
let cxx_name = match ForeignName::parse(&decl.name, span) {
Ok(foreign_name) => foreign_name,
Err(_) => {
let span = &enm.variants_from_header_attr;
let msg = format!("unsupported C++ variant name: {}", decl.name);
return cx.error(span, msg);
}
let Ok(cxx_name) = ForeignName::parse(&decl.name, span) else {
let span = &enm.variants_from_header_attr;
let msg = format!("unsupported C++ variant name: {}", decl.name);
return cx.error(span, msg);
};
let rust_name: Ident = match syn::parse_str(&decl.name) {
Ok(ident) => ident,
Expand Down

0 comments on commit fb82424

Please sign in to comment.