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

docs: Use String in Rc::into_raw examples #61421

Merged
merged 1 commit into from
Jun 14, 2019
Merged

docs: Use String in Rc::into_raw examples #61421

merged 1 commit into from
Jun 14, 2019

Conversation

vorner
Copy link
Contributor

@vorner vorner commented Jun 1, 2019

It is unclear if accessing an integer after drop_in_place has been
called on it is undefined behaviour or not, as demonstrated by the
discussion in
#60766 (review).

Avoid these uncertainties by using String which frees memory in its
drop_in_place to make sure this is undefined behaviour. The message in
the docs should be to watch out and not access the data after that, not
discussing when one maybe could get away with it O:-).

@rust-highfive
Copy link
Collaborator

r? @joshtriplett

(rust_highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 1, 2019
@Centril
Copy link
Contributor

Centril commented Jun 10, 2019

r? @RalfJung

@RalfJung
Copy link
Member

Despite what the title says, this is just for the Weak::*_raw functions, right? What about the similar functions on Rc itself?

@vorner
Copy link
Contributor Author

vorner commented Jun 10, 2019

Ups, yes, the title is wrong.

I don't think the original examples had this problem of claiming something is UB and maybe not being UB in the first place, so I've changed only the examples I've added in the linked merge request. Do you think it makes sense to go through the other examples too and unify it (for no other reason than just the consistency)?

@RalfJung
Copy link
Member

Do you think it makes sense to go through the other examples too and unify it (for no other reason than just the consistency)?

Yes I think that would make sense. But if you don't want to do that that's fine too; this PR is okay as-is (if you fix the title).

@vorner
Copy link
Contributor Author

vorner commented Jun 10, 2019

I'll have a look and go through the other examples, that's fine (it'll probably take few days before I get around to it, though).

@vorner
Copy link
Contributor Author

vorner commented Jun 12, 2019

OK, fixup with more example updates (I'll squash after full review, separating incremental changes for now).

I've done it only with the *_raw methods, not on the fn new and similar ‒ the .to_owned() and such feels a bit distracting in the examples. Is that OK?

@RalfJung
Copy link
Member

I've done it only with the *_raw methods, not on the fn new and similar ‒ the .to_owned() and such feels a bit distracting in the examples. Is that OK?

Yes, that sounds great.

I thought somewhere in these changed examples we'd also get the "but not anymore this, accessing the memory now would be UB", but I guess that can only happen with Weak?

@vorner
Copy link
Contributor Author

vorner commented Jun 13, 2019

I thought somewhere in these changed examples we'd also get the "but not anymore this, accessing the memory now would be UB", but I guess that can only happen with Weak?

There's this one example that has a dangling pointer at the end (because the Arc was already freed), but that is dangling with an int inside it too. This specific UB can happen only with Weak, yes.

Should I rebase? I've looked at the failing CI, but my feeling is this is problem in the build itself?

@RalfJung
Copy link
Member

Ignore Azure CI, that is just being tested currently.

@RalfJung
Copy link
Member

This specific UB can happen only with Weak, yes.

Fair. All right then, let's land this.

@bors r+

@bors
Copy link
Contributor

bors commented Jun 13, 2019

📌 Commit e5af0e5 has been approved by RalfJung

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 13, 2019
@bors
Copy link
Contributor

bors commented Jun 13, 2019

⌛ Testing commit e5af0e5 with merge ab0c4b9...

bors added a commit that referenced this pull request Jun 13, 2019
docs: Use String in Rc::into_raw examples

It is unclear if accessing an integer after `drop_in_place` has been
called on it is undefined behaviour or not, as demonstrated by the
discussion in
#60766 (review).

Avoid these uncertainties by using String which frees memory in its
`drop_in_place` to make sure this is undefined behaviour. The message in
the docs should be to watch out and not access the data after that, not
discussing when one maybe could get away with it O:-).
It is unclear if accessing an integer after `drop_in_place` has been
called on it is undefined behaviour or not, as demonstrated by the
discussion in
#60766 (review).

Avoid these uncertainties by using String which frees memory in its
`drop_in_place` to make sure this is undefined behaviour. The message in
the docs should be to watch out and not access the data after that, not
discussing when one maybe could get away with it O:-).
@vorner
Copy link
Contributor Author

vorner commented Jun 13, 2019

Um, wait? I was talking about rebasing because of the fixup commit that needs to be squashed before the merge (I've pushed the rebase now). Or does bors handle that automatically? It would be stupid if the fixup commit ended up in master :-(.

@RalfJung
Copy link
Member

Sorry, I didn't notice the fixup commit.

@bors retry

@pietroalbini
Copy link
Member

@bors r-

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Jun 14, 2019
@RalfJung
Copy link
Member

@pietroalbini why that?

@pietroalbini
Copy link
Member

Based on @vorner's comment this wasn't supposed to land until the fixup was removed, but @bors retry doesn't do that.

...I now see the commit was already pushed auto-unapproving it...

@RalfJung
Copy link
Member

Oh that's what happened. I did the retry to cancel the build that was already ongoing. I forgot about auto-unapproval. (Is that state change visible anywhere from within the issue?)

@bors r+

@bors
Copy link
Contributor

bors commented Jun 14, 2019

📌 Commit 79e5839 has been approved by RalfJung

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jun 14, 2019
@bors
Copy link
Contributor

bors commented Jun 14, 2019

⌛ Testing commit 79e5839 with merge fc550d4...

bors added a commit that referenced this pull request Jun 14, 2019
docs: Use String in Rc::into_raw examples

It is unclear if accessing an integer after `drop_in_place` has been
called on it is undefined behaviour or not, as demonstrated by the
discussion in
#60766 (review).

Avoid these uncertainties by using String which frees memory in its
`drop_in_place` to make sure this is undefined behaviour. The message in
the docs should be to watch out and not access the data after that, not
discussing when one maybe could get away with it O:-).
@bors
Copy link
Contributor

bors commented Jun 14, 2019

☀️ Test successful - checks-travis, status-appveyor
Approved by: RalfJung
Pushing fc550d4 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Jun 14, 2019
@bors bors merged commit 79e5839 into rust-lang:master Jun 14, 2019
@vorner vorner deleted the string-in-rc-into-raw-docs branch June 14, 2019 18:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants