Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
attributes: fix
#[instrument(err)]
in case of early returns (#1006)
## Motivation For the non-async case, early returns could escape the block so that the error handling was skipped. I was wondering for quite some time now what was going on here 😆 ## Solution Just put the block into the all-mighty "try-catch-closure" construct. Annotating the return type of the closure improves the error message in case of a mismatch between the function's return type and body. Example code: ``` fn with_err() -> Result<(), String> { Ok(5) } ``` Without return type annotation: ``` error[E0308]: mismatched types --> src/main.rs:2:37 | 2 | fn with_err() -> Result<(), String> { | _____________________________________^ 3 | | Ok(5) 4 | | } | |_^ expected `()`, found integer ``` With return type annotation: ``` error[E0308]: mismatched types --> src/main.rs:3:8 | 3 | Ok(5) | ^ expected `()`, found integer ```
- Loading branch information