Skip to content

Fix Vec::map_in_place not doing what is written in the comment #18908

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

Closed
wants to merge 1 commit into from

Conversation

tbu-
Copy link
Contributor

@tbu- tbu- commented Nov 12, 2014

No description provided.

@rust-highfive
Copy link
Contributor

warning Warning warning

  • These commits modify unsafe code. Please review it carefully!

@alexcrichton
Copy link
Member

Can a test be added for this as well?

@tbu-
Copy link
Contributor Author

tbu- commented Nov 13, 2014

@alexcrichton I'm not sure how to do this for the zero-sized types.

When I add a destructor to a zero-sized it gets a drop flag and isn't zero-sized anymore.

@Gankra
Copy link
Contributor

Gankra commented Nov 13, 2014

So basically this is dead code until we remove the drop flag? You could still add a test that should "still" work once the drop flag is gone.

@alexcrichton
Copy link
Member

Would #[unsafe_no_drop_flag] work here?

@bstrie
Copy link
Contributor

bstrie commented Nov 20, 2014

Is there a timeframe for removing drop flags?

@tbu-
Copy link
Contributor Author

tbu- commented Nov 21, 2014

@alexcrichton I tried this, but my conclusion is that you can't test for it right now.

  1. Suppose you make a normal struct with no members, and implement Drop for it -> not zero-sized anymore.
  2. Suppose you add #[unsafe_no_drop_flag] to the struct with no members. Then mem::forget doesn't stop the destructor from running (I think by design of #[unsafe_no_drop_flag]), so it actually yields incorrect behavior in Vec::map_in_place.

For this to work, we must have stack-based drop flags.

@pnkfelix
Copy link
Member

cc me.

@alexcrichton
Copy link
Member

Hm ok, looks ok to me then!

@Gankra
Copy link
Contributor

Gankra commented Nov 21, 2014

I still think it would be reasonable to add a test that is effectively "dead code" now, but will stop being dead when the drop-flags become stack based. That is, code that makes sure destructors aren't called here on zero-sized types. This is trivially true now because such an object doesn't actually exist, but they will, and we might as well write the test now while we remember.

bors added a commit that referenced this pull request Nov 21, 2014
@tbu-
Copy link
Contributor Author

tbu- commented Nov 21, 2014

@gankro How would you want to do that? If you can tell me a way, I'll implement it.

@bors bors closed this Nov 21, 2014
@Gankra
Copy link
Contributor

Gankra commented Nov 21, 2014

@tbu- I imagine something like:

  • define two zero-sized types A, B
  • define two statics a_deaths, b_deaths
  • make the destructors of A and B increment those respectively
  • make a Vec<A>, assert a_deaths and b_deaths are 0
  • map_inplace to Vec<B>, assert a_deaths has increased to the right value, and b_deaths hasn't
  • drop Vec<B>, assert b_deaths has increased

This should trivially be true before and after this PR, and non-trivially true when we get stack-flags

@tbu- tbu- mentioned this pull request Nov 28, 2014
tbu- added a commit to tbu-/rust that referenced this pull request Nov 28, 2014
lnicola pushed a commit to lnicola/rust that referenced this pull request Jan 20, 2025
Fix: Detect missing errors for } braces before else in let...else statements
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants