Skip to content

No drop flag check for DST structs #16758

Closed

Description

@nrc

Since drop flags come after all named fields and the last field in a DST struct is unsized, finding the drop flag is a bit tricky. Therefore, it is currently not checked. A possible fix is to find the alignment by taking the size of the struct from its vtable and subtracting the size of the drop flag. However, since the plan is to remove the drop flag anyway (#5016), I have just left a FIXME and issue a warning when we skip the check.

cc @pnkfelix

Activity

  1. steveklabnik commented on Feb 2, 2016

    @steveklabnik
    Contributor

    @nrc is this still relevant today?

  2. nrc commented on Feb 3, 2016

    @nrc
    MemberAuthor

    Yes, afaik. cc @pnkfelix

  3. tailhook commented on Mar 29, 2016

    @tailhook

    Does this mean if i get:

    warning: Ignoring drop flag in destructor for std::sync::mutex::Mutex<Something>because the struct is unsized. See issue#16758
    

    Then I will get a memory leak?

  4. added a commit that references this issue on Apr 2, 2016
  5. added a commit that references this issue on Apr 3, 2016
  6. pnkfelix commented on Apr 28, 2016

    @pnkfelix
    Contributor

    some relevant recent discussion from #rust-internals IRC channel: https://botbot.me/mozilla/rust-internals/2016-04-28/?msg=65078367&page=3

  7. chriscoomber commented on Aug 22, 2016

    @chriscoomber

    Just hit this when coercing a Box<RwLock< (struct) >> to a Box<RwLock< (trait) >>.

    (Aside: it is of course illegal to coerce a RwLock< (struct) > to a RwLock< (trait) > - I don't really understand why the outer box makes this legal.)

    Here's a small example that produces this warning:

    use std::sync::RwLock;
    use std::boxed::Box;
    
    trait Trait {}
    struct Thing;
    impl Trait for Thing {}
    
    fn main() {
      let _: Box<RwLock<Trait>> = Box::new(RwLock::new(Thing));
    }

    Will I get a memory leak with this code?

  8. jonas-schievink commented on Aug 22, 2016

    @jonas-schievink
    Contributor

    This should no longer be relevant after #35764 lands since it will remove in-struct drop flags

  9. Osspial commented on Nov 4, 2016

    @Osspial

    Should this warning be removed now? Non-zeroing drops have landed, so there isn't a flag to check.

  10. added
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    and removed on Nov 4, 2016
  11. arielb1 commented on Nov 4, 2016

    @arielb1
    Contributor

    Sure enough. There is no such a thing as a drop flag in the MIR (1.13+) universe.

  12. added a commit that references this issue on Mar 10, 2024
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

    A-DSTsArea: Dynamically-sized types (DSTs)T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions