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

Generate a documentation page for core::mem::transmute. #57848

Merged
merged 2 commits into from
Feb 7, 2019

Conversation

jrvanwhy
Copy link
Contributor

In #[no_std] environments, std::mem::transmute is unavailable. Searching for "core transmute" online only pulls up core::intrinsics::transmute, which is behind the (unstable) core_intrinsics feature flag. Users wishing to use transmute in #[no_std] environments typically should use core::mem::transmute instead, as it is stable. This documentation makes core::mem::transmute discoverable.

…ransmute.

In #[no_std] environments, std::mem::transmute is unavailable. Searching for transmute in libcore only pulls up core::intrinsics::transmute, which is behind the (unstable) core_intrinsics feature flag. Users wishing to use transmute in #[no_std] environments typically should use core::mem::transmute instead, as it is stable. This documentation makes core::mem::transmute discoverable.
@rust-highfive
Copy link
Collaborator

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @shepmaster (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

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

tesuji commented Jan 23, 2019

I'm not a contributor. My thought is that when you search transmute in Rust doc, you would see all posible output.

search

@shepmaster
Copy link
Member

when you search transmute in Rust doc,

And (unfortunately in this case), the intrinsics:: one appears before the one we'd want people to use (mem::).

I think this is fine, but I'd wonder how it would look for std::intrinsics::transmute — does it suggest using core::mem?

@shepmaster
Copy link
Member

Now, does this new fancy thing work yet...

r? @rust-lang/docs

@shepmaster
Copy link
Member

No, it does not.

r? @QuietMisdreavus

@jrvanwhy
Copy link
Contributor Author

when you search transmute in Rust doc,

And (unfortunately in this case), the intrinsics:: one appears before the one we'd want people to use (mem::).

Actually, the one we want (core::mem::transmute) does not appear in the list at all. core::mem::transmute_copy does appear, as does std::mem::transmute. I suspect there's some mechanism trying to shepherd users towards std rather than core for items that exist in both, but that can be troublesome for #![no_std] users.

I think this is fine, but I'd wonder how it would look for std::intrinsics::transmute — does it suggest using core::mem?

Unfortunately, the recommendation does show up in std::intrinsics::transmute's docs. It also appears in std::mem::transmute's docs. I'm not sure if it's possible to disable that -- if we can't prevent it, then this needs to be reworded.

@shepmaster
Copy link
Member

Hm. It's because core::mem::transmute is just a re-export:

rust/src/libcore/mem.rs

Lines 17 to 18 in 19f8958

#[stable(feature = "rust1", since = "1.0.0")]
pub use intrinsics::transmute;

@GuillaumeGomez
Copy link
Member

You can (will be able to) filter your search (currently not in stable, only in nightly and beta...) so you won't have the search issue anymore. However, I approve the precision add!

@@ -729,6 +729,10 @@ extern "rust-intrinsic" {
/// cause [undefined behavior][ub] with this function. `transmute` should be
/// the absolute last resort.
///
/// `transmute` is re-exported by [core::mem](../mem/index.html) as
/// `core::mem::transmute`, which may be used without the `core_intrinsics`
/// feature flag.
Copy link
Member

@scottmcm scottmcm Jan 24, 2019

Choose a reason for hiding this comment

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

These docs are going to show up for all four of {core|std}::{mem|intrinsics}::transmute, right? It might be worth pointing at both mem locations, in that case.

@QuietMisdreavus
Copy link
Member

A better solution than adding the extra blurb in the docs is to apply #[doc(inline)] to the pub use intrinsics::transmute statement instead. This will make a new page for core::mem::transmute appear, which will also add it to the search index.

@scottmcm
Copy link
Member

scottmcm commented Jan 24, 2019

Ooh, nice, @QuietMisdreavus! That sounds great, and would let us make the docs for the intrinsic just be "don't use this; use it from core instead". Oops, I misunderstood.

@QuietMisdreavus
Copy link
Member

and would let us make the docs for the intrinsic just be "don't use this; use it from core instead"

Actually, the doc for the intrinsic is going to be the same in all four places it's available, because it's just re-exported around. There's no way to fix that, since rustdoc doesn't let you add different docs to a re-export.

@jrvanwhy
Copy link
Contributor Author

A better solution than adding the extra blurb in the docs is to apply #[doc(inline)] to the pub use intrinsics::transmute statement instead. This will make a new page for core::mem::transmute appear, which will also add it to the search index.

Thank you! I'll give that a try -- it sounds like a much better solution.

…::mem::transmute, create documentation pages for them.

This renders them discoverable via search. I removed the mention of the exports in the transmute documentation, but can re-add it if desired.
@jrvanwhy jrvanwhy changed the title Mention that core::intrinsics::transmute is available at core::mem::transmute. Generate documentation pages for std::mem::transmute and core::mem::transmute. Jan 25, 2019
@jrvanwhy jrvanwhy changed the title Generate documentation pages for std::mem::transmute and core::mem::transmute. Generate a documentation page for core::mem::transmute. Jan 25, 2019
@jrvanwhy
Copy link
Contributor Author

I added the doc page for core::mem::transmute. For my own use cases, this change would've been plenty, so I removed the additional paragraph from the doc comment. I can replace the comment if others feel that transmute is sufficiently unique to deserve a "recommended exports of" comment.

@QuietMisdreavus
Copy link
Member

Sorry for letting this sit for so long! Let's get this merged!

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Feb 7, 2019

📌 Commit 1c8c94a has been approved by QuietMisdreavus

@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 Feb 7, 2019
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request Feb 7, 2019
…ietMisdreavus

Generate a documentation page for core::mem::transmute.

In `#[no_std]` environments, `std::mem::transmute` is unavailable. Searching for "core transmute" online only pulls up `core::intrinsics::transmute`, which is behind the (unstable) `core_intrinsics` feature flag. Users wishing to use transmute in `#[no_std]` environments typically should use `core::mem::transmute` instead, as it is stable. This documentation makes `core::mem::transmute` discoverable.
bors added a commit that referenced this pull request Feb 7, 2019
Rollup of 11 pull requests

Successful merges:

 - #57504 (Re-enable history api on file:// protocol)
 - #57848 (Generate a documentation page for core::mem::transmute.)
 - #57884 (Update minifier version)
 - #57954 (rustdoc: remove blank unstable spans)
 - #58028 (Fix image link in the settings menu)
 - #58033 (rustdoc: wrap stability tags in colored spans)
 - #58086 ([rustdoc] Improve file list display)
 - #58143 (Sort elements in the sidebar)
 - #58146 (Prevent automatic collapse of methods impl blocks)
 - #58150 (Don't apply impl block collapse rules to trait impls)
 - #58185 (Remove images' url to make it work even without internet connection)

Failed merges:

r? @ghost
@bors bors merged commit 1c8c94a into rust-lang:master Feb 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.

8 participants