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

rustdoc: mark unsafe fns in module page with superscript icons #37250

Merged
merged 1 commit into from
Nov 9, 2016

Conversation

liigo
Copy link
Contributor

@liigo liigo commented Oct 18, 2016

Note: I'v changed the mark style. Now use superscript ⚠(U+26A0) (the old one is '[Unsafe]' literal).
Basically per https://botbot.me/mozilla/rust-docs/2016-10-19/?msg=75112017&page=1

New: mark with superscript icon

unsafe-fn-icon

Old: mark with literal '[Unsafe]'

unsafe-fn

@rust-highfive
Copy link
Collaborator

r? @steveklabnik

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

@steveklabnik
Copy link
Member

/cc @rust-lang/tools @rust-lang/docs

@sophiajt
Copy link
Contributor

Hmm, I'd assume it's okay for standard library functions to be unsafe, otherwise they wouldn't be able to get very far.

Now, for functions in extern crates, that might be a handy thing to know.

@alexcrichton
Copy link
Member

I personally feel like this is calling out unsafe functions too much. They're typically very well motivated to be part of a public API and don't necessarily need to have external pressure from rustdoc to remove them.

@GuillaumeGomez
Copy link
Member

I dont like this change. The function is described as unsafe anyway so I don't see the need to add even more on that.

@nrc
Copy link
Member

nrc commented Oct 18, 2016

I assume the intention here is not unsafe-shaming, but informing users they will need an unsafe context to call from? That is useful info, but I think having it in the detail (rather than in this summary view) is fine (it is, I think less important to know at a glance than the function's type signature).

@GuillaumeGomez
Copy link
Member

My point was that such an information shouldn't be in a description. I'm open to suggestions to make spotting unsafe functions easier but I don't like this approach.

@liigo
Copy link
Contributor Author

liigo commented Oct 19, 2016

I prefer safe functions to unsafe functions. I prefer safe way to unsafe way to do something. While searching for a way, I often explore corresponding module's page to find safe functions first, then unsafe ones for second best. Module pages already list functions' name and docs summary, adding an unsafety flag makes people easy to focus on both safe-only and unsafe-only functions, avoid wasting time click on undesired detail pages.


@nrc : I assume the intention here is not unsafe-shaming, but informing users they will need an unsafe context to call from?

Yes, of course.

@alexcrichton : They're typically very well motivated to be part of a public API and don't necessarily need to have external pressure from rustdoc to remove them.

Not leave a flag to remove them (but why you thought of this?). Just give users more information about unsafety before they open the detail page.

@GuillaumeGomez : The function is described as unsafe anyway so I don't see the need to add even more on that.

You must open its detail page to know it's unsafe or not. If people want to find a safe way to do something, they'd like not wasting time to click unsafe functions.

@frewsxcv
Copy link
Member

Will bring this up at the docs meeting tomorrow.

@frewsxcv
Copy link
Member

Brought this up at the meeting yesterday:

https://botbot.me/mozilla/rust-docs/2016-10-19/?msg=75112017&page=1

We didn't reach any decisions on this, but I think some people said they'd think about it.


My own opinion: I notice that (as per in the screenshot above) the "[Unsafe]" matches the visual styles of "[Deprecated]" and "[Unstable]". I think it's worth making a distinction between these items:

In the case of "[Deprecated]" and "[Unstable]", I think it makes sense to mention these because we really want to discourage the user from using these functions as the functions are phased out or subject to change.

In the case of "[Unsafe]", there are some very valid use cases (many for performance reasons) for using unsafe functions. I think we do enough at the compilation level for making the user aware of unsafe functions (though we could do more at the doc-comment level describing why it's unsafe).

I don't personally think it's necessary to treat both of these scenarios on the same level

@liigo
Copy link
Contributor Author

liigo commented Oct 21, 2016

I don't personally think it's necessary to treat both of these scenarios on the same level

On the same level because both are tags (or attributes) of a function. Tags itself are documentation. Not just stability and unsafety, we may add visibility here in the future too. (If rustdoc shows private items, visibility should be tagged.) I doubt there is exclusive scenario only for stability, but not for unsafety and visibility.

@liigo liigo changed the title rustdoc: flag unsafe fns in module's function list [WIP] rustdoc: flag unsafe fns in module's function list Oct 21, 2016
@liigo liigo force-pushed the rustdoc-unsafe-fns branch 2 times, most recently from 2046337 to 8e7fa5d Compare October 24, 2016 01:10
@liigo liigo changed the title [WIP] rustdoc: flag unsafe fns in module's function list rustdoc: mark unsafe fns in module page with superscript icons Oct 24, 2016
@liigo
Copy link
Contributor Author

liigo commented Oct 24, 2016

Note: I'v changed the mark style. Now we use superscript ⚠(U+26A0) (the old one is '[Unsafe]' literal), basically per https://botbot.me/mozilla/rust-docs/2016-10-19/?msg=75112017&page=1
cc @frewsxcv

unsafe-fn-icon

@GuillaumeGomez
Copy link
Member

Oh nice! I like this one.

@matthew-piziak
Copy link
Contributor

That's quite elegant @liigo. 👍

@GuillaumeGomez
Copy link
Member

cc @steveklabnik

@steveklabnik
Copy link
Member

Seems like some more people like this. /cc @rust-lang/tools what do you think?

@frewsxcv
Copy link
Member

I personally like the latest proposal more than the original one. I think I'm overall neutral on it though. I have some reservations about the use of a caution sign to represent 'unsafe', but I also can't think of a better symbol at the moment. I also am not a fan of 'alt' attributes in HTML as I feel they are unintuitive to trigger and don't work on mobile. That said, I unfortunately don't really have any concrete advice, but am interested to hear what others think.

@alexcrichton
Copy link
Member

I agree with @frewsxcv in that I'm fairly neutral about this. I do like it better than [unsafe] as it's smaller and a not quite as in-your-face.

@liigo
Copy link
Contributor Author

liigo commented Oct 31, 2016

Unsafe function is unsafe, it's the truth. The unsafe keyword itself is a caution sign, which programmers pay more attention to. The new docs with caution signs just represent the code. Don't hesitate to tell it's unsafe, it is.

@jbcden
Copy link

jbcden commented Nov 2, 2016

I like this version too!

@steveklabnik
Copy link
Member

It seems like people are neutral to mildly-positive about this change. I would merge, but since it's only a few days until we cut the next beta, I'd like to wait until just after, so we can get a full six weeks of feedback on nightly first.

@steveklabnik
Copy link
Member

Beta has been branched. Let's see how the wider community feels.

@bors: r+

@bors
Copy link
Contributor

bors commented Nov 8, 2016

📌 Commit 47515ad has been approved by steveklabnik

eddyb added a commit to eddyb/rust that referenced this pull request Nov 9, 2016
…abnik

rustdoc: mark unsafe fns in module page with superscript icons

Note: I'v changed the mark style. Now use superscript ⚠(U+26A0) (the old one is '[Unsafe]' literal).
Basically per https://botbot.me/mozilla/rust-docs/2016-10-19/?msg=75112017&page=1

![unsafe-fn-icon](https://cloud.githubusercontent.com/assets/346530/19633650/7f6e1eea-99e6-11e6-8d09-31aec83e46a5.png)

![unsafe-fn](https://cloud.githubusercontent.com/assets/346530/19472050/39daded2-9558-11e6-9148-3cb12afd1c9a.png)
bors added a commit that referenced this pull request Nov 9, 2016
Rollup of 15 pull requests

- Successful merges: #36868, #37134, #37229, #37250, #37370, #37428, #37432, #37472, #37524, #37614, #37622, #37627, #37636, #37644, #37654
- Failed merges: #37463, #37542, #37645
@bors bors merged commit 47515ad into rust-lang:master Nov 9, 2016
@Manishearth
Copy link
Member

This should really be done on method names too.

@liigo
Copy link
Contributor Author

liigo commented Jan 6, 2017

@Manishearth Unsafe methods are already marked with unsafe keyword.

unsafe-methods

@Manishearth
Copy link
Member

Yes, but it would be nice to be clearer about it.

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.