Extend [if, while, else] let with additional expressions

To be honest, my code doesn't look very good and even unsuccessful. Especially if, for example, instead of Some we get None and we add OR. This will be really weird.

However, does it make sense to add the ability to continue specifying additional conditions in the line with the check for if let, while let and other if else lines with the let declaration?

Something like this.

let x: &Option<i32> = &Some(3);
if let Some(y) && y > 4 && y != 10 || ...  = x {
    // y was converted to `ref y` and its type is &i32
}

RFC 2497: if- and while-let chains (available as #[feature(let_chains)] on nightly) was originally going to be stabilized in Rust 1.64 but had to be reverted. Then it was supposed to be stabilized for Rust 2024, but stabilization is apparently still ongoing, so missed the deadline? However, if I understand correctly, the required underlying changes in semantics were included in 2024, so the feature itself can be stabilized in any future version.

3 Likes

Oh, thanks for sharing this RFC! Glad to see this feature accepted and in the works!

I don't think it was ever to be supposed to be stabilized in 1.85.0 which brought the 2024 edition. However stabilization is actively being worked on:

2 Likes