Skip to content

Consider feature for #[may_dangle] on Drop impl to allow usage in cases where normal Vec works #322

Description

@laundmo

Normal Vec uses the unstable #[may_dangle] on its Drop impl, avoiding issues with lifetimes when a ArryaVec is used as a struct field and stores references to other fields of the struct. Smallvec has a feature flag to opt in to doing the same.

Playground with the problem: https://play.rust-lang.org/?version=stable&mode=debug&edition=2024&gist=1ae3af28bff1fe47748f747755f47326
change ArrayVec to Vec to see that it works.

references/docs:
https://doc.rust-lang.org/nomicon/dropck.html#an-escape-hatch
https://std-dev-guide.rust-lang.org/tricky/may-dangle.html

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions