rust-rocksdb-zaidoon1/tests/fail/memory_usage_builder_outlive_db.stderr
Evan Jones 4b9ba976d6 MemoryUsageBuilder: Prevent outliving the DBs/caches (#1061)
This type must not outlive the DBs and caches that are added to it,
otherwise the caller will access invalid memory and likely crash.
Use PhantomData to ensure it does not outlive its arguments. This is
technically a breaking API change, but anything that used this code
in this way was likely broken anyway.

Co-authored-by: Oleksandr Anyshchenko <aanischenko@gmail.com>
2026-01-06 22:13:21 -05:00

11 lines
483 B
Text

error[E0597]: `db` does not live long enough
--> tests/fail/memory_usage_builder_outlive_db.rs:7:24
|
6 | let db = DB::open_default("foo").unwrap();
| -- binding `db` declared here
7 | builder.add_db(&db);
| ^^^ borrowed value does not live long enough
8 | }
| - `db` dropped here while still borrowed
9 | let _memory_usage = builder.build().unwrap();
| ------- borrow later used here