Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No drop flag check for DST structs #16758

Closed
nrc opened this issue Aug 26, 2014 · 8 comments
Closed

No drop flag check for DST structs #16758

nrc opened this issue Aug 26, 2014 · 8 comments
Labels
A-DSTs Area: Dynamically-sized types (DSTs) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@nrc
Copy link
Member

nrc commented Aug 26, 2014

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

@steveklabnik
Copy link
Member

@nrc is this still relevant today?

@nrc
Copy link
Member Author

nrc commented Feb 3, 2016

Yes, afaik. cc @pnkfelix

@tailhook
Copy link

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?

durka added a commit to durka/rust that referenced this issue Apr 2, 2016
bors added a commit that referenced this issue Apr 3, 2016
add missing spaces in #16758 warning

I should probably add a test.
@pnkfelix
Copy link
Member

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

@chriscoomber
Copy link

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?

@jonas-schievink
Copy link
Contributor

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

@Osspial
Copy link

Osspial commented Nov 4, 2016

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

@arielb1 arielb1 added I-nominated T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. and removed I-nominated labels Nov 4, 2016
@arielb1
Copy link
Contributor

arielb1 commented Nov 4, 2016

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

@arielb1 arielb1 closed this as completed Nov 4, 2016
matthiaskrgr pushed a commit to matthiaskrgr/rust that referenced this issue Mar 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-DSTs Area: Dynamically-sized types (DSTs) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

8 participants