本頁尚未翻譯,以下為英文原文。
#E0092: Drop::drop called directly
drop runs on its own when a using block ends, and calling it again would release the resource twice. Expose a method such as close() for an early release.
nabi
struct Conn { id: i32; }
impl Drop for Conn { fn drop(ref self) {} }
let c = Conn { id: 1 };
c.drop();
error[E0092]: `Drop::drop` cannot be called directly; it runs when a `using` block exits - expose a method such as `close()` to release early --> main.nabi:5:1 | 5 | c.drop(); | ^^^^^^^^
Let using release the value:
nabi
struct Conn { id: i32; }
impl Drop for Conn { fn drop(ref self) { println(f"closed {self.id}"); } }
using c = (Conn { id: 1 }) {
println(f"using {c.id}");
}
using 1
closed 1
Related: E0066 using on a value without Drop, E0133 resource used after it was moved or closed
Found a mistake? Edit this page on GitHub. Last updated