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

Add more docs - mostly warnings - to std::mem::transmute #34609

Merged
merged 15 commits into from
Jul 27, 2016
Merged

Add more docs - mostly warnings - to std::mem::transmute #34609

merged 15 commits into from
Jul 27, 2016

Conversation

strega-nil
Copy link
Contributor

No description provided.

@rust-highfive
Copy link
Collaborator

r? @aturon

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

@strega-nil
Copy link
Contributor Author

r? @steveklabnik

@rust-highfive rust-highfive assigned steveklabnik and unassigned aturon Jul 2, 2016
@strega-nil
Copy link
Contributor Author

Perhaps I should also add an example for casting to usize.

@arielb1
Copy link
Contributor

arielb1 commented Jul 2, 2016

transmute can also be used to transform a Vec<Option<&T>> to a Vec<&T>.

@strega-nil
Copy link
Contributor Author

@arielb1 Ah, good for the alternatives section!

@@ -278,17 +278,157 @@ extern "rust-intrinsic" {
/// Moves a value out of scope without running drop glue.
pub fn forget<T>(_: T) -> ();

/// Unsafely transforms a value of one type into a value of another type.
/// Reinterprets the bits of a value of one type as another type. Both types
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The first paragraph needs to be a single sentence as it's used as a short summary on the module page and search results.

@ollie27
Copy link
Member

ollie27 commented Jul 3, 2016

A lot of these examples aren't compiling, check the travis output and try them locally. I suggest you put each example in it's own code block so they run individually and some examples like the libc one need to be marked ignore as that won't even compile.

@strega-nil
Copy link
Contributor Author

@ollie27 Yeah, I've obviously never written documentation like this before xP

@strega-nil
Copy link
Contributor Author

strega-nil commented Jul 4, 2016

@ollie27 Okay, I can't actually try it locally due to LLDB failures. I'm... not willing to continue to try this. If someone else wants to pick this up, they can, but goddamnit, I've spent a fucking day trying to get rustc to compile. This is ridiculous.

Edit: Alright, it's working now. The rustc new-dev experience is... not great :P

@ollie27
Copy link
Member

ollie27 commented Jul 5, 2016

You shouldn't need to compile rustc to try these. If you have a working rustdoc you can copy this doc block into it's own file and run rustdoc --test on that. You can also use https://play.rust-lang.org/.

@steveklabnik
Copy link
Member

I suggest you put each example in it's own code block so they run individually and some examples like the libc one need to be marked ignore as that won't even compile.

Yes please to both of these!

/// are as follows:
///
/// Turning a pointer into a `usize`:
/// ```
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you put a blank line between the triple backticks and the descriptions? This applies throughout the file.

/// `transmute` is semantically equivalent to a bitwise move of one type
/// into another. It copies the bits from the destination type into the
/// source type, then forgets the original. If you know C or C++, it's like
/// `memcpy` under the hood.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We usually don't refer to other languages in the docs. I would just say

then forgets the original, like memcpy.

@steveklabnik
Copy link
Member

@ubsan thanks for all the work on this, it's improved greatly 😄

I have some extremely small nits and then this is good to go, I think.

@steveklabnik
Copy link
Member

@bors: r+ rollup

@bors
Copy link
Contributor

bors commented Jul 21, 2016

📌 Commit 24f8589 has been approved by steveklabnik

@bors
Copy link
Contributor

bors commented Jul 21, 2016

⌛ Testing commit 24f8589 with merge 3850b22...

@bors
Copy link
Contributor

bors commented Jul 21, 2016

💔 Test failed - auto-win-gnu-32-opt

@alexcrichton
Copy link
Member

@bors: retry

On Thu, Jul 21, 2016 at 1:04 PM, bors notifications@github.com wrote:

💔 Test failed - auto-win-gnu-32-opt
https://buildbot.rust-lang.org/builders/auto-win-gnu-32-opt/builds/5024


You are receiving this because you are on a team that was mentioned.
Reply to this email directly, view it on GitHub
#34609 (comment), or mute
the thread
https://github.com/notifications/unsubscribe-auth/AAD95G2-XT29Gv4h4UxzWq6n25TnPZ3Pks5qX9DSgaJpZM4JDnTq
.

@steveklabnik
Copy link
Member

@bors: retry

@alexcrichton
Copy link
Member

@bors: retry (maybe third time's the charm)

steveklabnik added a commit to steveklabnik/rust that referenced this pull request Jul 25, 2016
Add more docs - mostly warnings - to std::mem::transmute
bors added a commit that referenced this pull request Jul 25, 2016
Rollup of 13 pull requests

- Successful merges: #34461, #34609, #34732, #34850, #34894, #34935, #34974, #34990, #34995, #35001, #35009, #35010, #35028
- Failed merges:
@bors
Copy link
Contributor

bors commented Jul 26, 2016

⌛ Testing commit 24f8589 with merge 2094bc3...

@bors
Copy link
Contributor

bors commented Jul 26, 2016

💔 Test failed - auto-win-msvc-64-opt

@alexcrichton
Copy link
Member

@bors: retry

On Tue, Jul 26, 2016 at 4:03 AM, bors notifications@github.com wrote:

💔 Test failed - auto-win-msvc-64-opt
https://buildbot.rust-lang.org/builders/auto-win-msvc-64-opt/builds/5083


You are receiving this because you are on a team that was mentioned.
Reply to this email directly, view it on GitHub
#34609 (comment), or mute
the thread
https://github.com/notifications/unsubscribe-auth/AAD95JTonEuCnHepaRi5964EO9N3lIeQks5qZelygaJpZM4JDnTq
.

steveklabnik added a commit to steveklabnik/rust that referenced this pull request Jul 26, 2016
Add more docs - mostly warnings - to std::mem::transmute
bors added a commit that referenced this pull request Jul 27, 2016
@bors bors merged commit 24f8589 into rust-lang:master Jul 27, 2016
@strega-nil strega-nil deleted the transmute_docs branch September 11, 2018 05:38
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.