diff options
| author | Gary Guo <gary@garyguo.net> | 2026-09-22 22:58:11 +0100 |
|---|---|---|
| committer | Gary Guo <gary@garyguo.net> | 2026-10-11 11:06:46 +0100 |
| commit | 29213c00ccaa55e8ba01cfc79a93e000b0fcacc4 (patch) | |
| tree | 6d3827af2e40386a9c61205d4ea2683ccb002623 /tools/perf/scripts/python/stackcollapse.py | |
| parent | 73511e489bb0cb41d65a99b6f9df4f73a2f4827a (diff) | |
rust: pin-init: internal: pin_data: teach drop check about generics that cannot dangle
Lifetimes not needed by drop glue are considered by Rust's drop check to be
considered `#[may_dangle]`. In case for a self-referential struct, we may
have fields which need lifetime of borrowed fields in their drop glue, so
compiler's automatic check is insufficient.
Code like this:
#[pin_data]
struct SelfRef<'a> {
borrow: PrintOnDrop<&'owner str>,
owner: &'a str,
}
may access `owner` during the drop, however Rust will determine that since
`'a` only is used in `owner`, the `'a` lifetime may dangle during drop.
This is undesirable for pin-init self references, because `&'a str` could
be coerced to `&'owner str` and this could further coerce if there're
implied outlives, e.g. `&'earlier_field &'owner ()` would allow `&'owner
str` to further coerce to `&'earlier_field`.
Thus, if any self-referential field require field lifetime access in `Drop`
impl, we would need to ensure that the all generic parameters visible by
self-referential fields would strictly outlive the struct. And this can be
done by a simple `Drop` impl that does nothing. Without a dropck eye patch,
presence of `Drop` impl, albeit empty, tells the drop check that the strict
outlive relation is needed.
Acked-by: Benno Lossin <lossin@kernel.org>
Link: https://patch.msgid.link/20261008-dev-selfref-v2-5-e280b3c8fba5@garyguo.net/
Signed-off-by: Gary Guo <gary@garyguo.net>
Diffstat (limited to 'tools/perf/scripts/python/stackcollapse.py')
0 files changed, 0 insertions, 0 deletions
