Nested Struct Bindings Syntax Issue

What is the correct syntax for nesting struct bindings? If I have this code:

enum E2 {
    A,
    B,
}

enum E1 {
    X,
    Y { s: E2 },
}

fn func(opt: E1) {
    if let E1::Y { s } = opt {
        if let E2::A = s {}
    }
}

clippy tells me:

warning: this `if let` can be collapsed into the outer `if let`
  --> src/lib.rs:13:9
   |
13 |         if let E2::A = s {}
   |         ^^^^^^^^^^^^^^^^^^^
   |
   = note: `#[warn(clippy::collapsible_match)]` on by default
help: the outer pattern can be modified to include the inner pattern
  --> src/lib.rs:12:20
   |
12 |     if let E1::Y { s } = opt {
   |                    ^ replace this binding
13 |         if let E2::A = s {}
   |                ^^^^^ with this pattern
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#collapsible_match

So I listened to clippy and got uncompilable code:

fn func(opt: E1) {
    if let E1::Y { E2::A } = opt {
    }
}

What is the correct syntax here? The example on the clippy link didn't really help me.

fn func(opt: E1) {
    if let E1::Y { s: E2::A } = opt {
        println!("Hi!");
    }
}

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.