I've been looking into solving rust-analyzer#8378.
I think the solution would look like modifying https://github.com/rust-analyzer/rust-analyzer/blob/a8f1e41f0f15fee02a73850db559752a9124d014/crates/hir_def/src/body/lower.rs#L697 to fallback to the last not cfged out statement, if and only if that statement is an expression statement without a semicolon. However, I can't inerate backwards through AstChildren, because that is not implemented (in rowan), although the impl should be cheap. I could just allocate a temporary vector, but I don't feel like that's the best solution.
Wasn't too bad, if people think this design makes sense.