E0091#
Warning name: unused_errdefer
An errdefer statement cannot run because the rest of its body cannot raise an
error. Unlike defer, errdefer performs its cleanup only when control leaves
the body by raising an error.
Erroneous example#
///|
pub fn run() -> Unit {
errdefer println("cleanup")
println("operation completed")
}
The statements after errdefer complete normally, so its cleanup is unused.
Suggestion#
Remove the statement if no cleanup is needed. Use defer for cleanup that must
always run, or keep errdefer before an operation that can raise an error when
the cleanup is needed only on failure.
///|
fn operation_that_may_fail() -> Unit raise {
fail("operation failed")
}
///|
pub fn run() -> Unit raise {
errdefer println("cleanup")
operation_that_may_fail()
}