rust-lang / rust-mode

Emacs configuration for Rust
Apache License 2.0
1.1k stars 176 forks source link

Eliminate "Containing expression ends prematurely" error #500

Closed micl2e2 closed 11 months ago

micl2e2 commented 11 months ago

While #498 handles dbg! insertion for "empty line" cases, the original rust-insert-dbg remains unchanged. Though it can handle most cases where there is a valid s-expression ahead of current position, it cannot handle if there isn't, such as:

if let Ok(val) = a {}
____________________^ cursor is here 

, where it results in "Containing expression ends prematurely" error, and an incorrect insertion:

if let Ok(val) = a {(}

This patch attempts to fix this issue. And the result would be:

if let Ok(val) = a {dbg!()}
psibi commented 11 months ago

Thank you!