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

unsafe keyword: trait examples and unsafe_op_in_unsafe_fn update #102475

Merged
merged 2 commits into from
Oct 7, 2022

Conversation

RalfJung
Copy link
Member

Having a safe fn in an unsafe trait vs an unsafe fn in a safe trait are pretty different situations, but the distinction is subtle and can confuse even seasoned Rust developers. So let's have explicit examples of both. I also removed the existing unsafe trait example since it was rather strange.

Also the unsafe_op_in_unsafe_fn lint can help disentangle the two sides of unsafe, so update the docs to account for that.

@rustbot rustbot added the T-libs Relevant to the library team, which will review and decide on the PR/issue. label Sep 29, 2022
@rustbot
Copy link
Collaborator

rustbot commented Sep 29, 2022

Hey! It looks like you've submitted a new PR for the library teams!

If this PR contains changes to any rust-lang/rust public library APIs then please comment with @rustbot label +T-libs-api -T-libs to tag it appropriately. If this PR contains changes to any unstable APIs please edit the PR description to add a link to the relevant API Change Proposal or create one if you haven't already. If you're unsure where your change falls no worries, just leave it as is and the reviewer will take a look and make a decision to forward on if necessary.

Examples of T-libs-api changes:

  • Stabilizing library features
  • Introducing insta-stable changes such as new implementations of existing stable traits on existing stable types
  • Introducing new or changing existing unstable library APIs (excluding permanently unstable features / features without a tracking issue)
  • Changing public documentation in ways that create new stability guarantees
  • Changing observable runtime behavior of library APIs

@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 Sep 29, 2022
@Noratrieb
Copy link
Member

I love the three different examples with the Indexable trait, thanks!

@RalfJung
Copy link
Member Author

RalfJung commented Oct 5, 2022

The reference PR rust-lang/reference#1278 that points to these new examples has landed. Would be good to also get this in so that there's no dangling references in the reference. :)

@RalfJung
Copy link
Member Author

RalfJung commented Oct 7, 2022

@rust-lang/libs-api @ehuss this is a keyword docs change, not sure whom to hand these to?

@dtolnay
Copy link
Member

dtolnay commented Oct 7, 2022

T-libs if it's documenting already well-established behavior or practice / not introducing some kind of new commitment.

library/std/src/keyword_docs.rs Outdated Show resolved Hide resolved
library/std/src/keyword_docs.rs Outdated Show resolved Hide resolved
library/std/src/keyword_docs.rs Outdated Show resolved Hide resolved
@RalfJung
Copy link
Member Author

RalfJung commented Oct 7, 2022

T-libs if it's documenting already well-established behavior or practice / not introducing some kind of new commitment.

Ah okay, yes that would be it.

@dtolnay dtolnay assigned dtolnay and unassigned joshtriplett Oct 7, 2022
@dtolnay
Copy link
Member

dtolnay commented Oct 7, 2022

@bors r+

@bors
Copy link
Contributor

bors commented Oct 7, 2022

📌 Commit c30dcff has been approved by dtolnay

It is now in the queue for this repository.

@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 Oct 7, 2022
bors added a commit to rust-lang-ci/rust that referenced this pull request Oct 7, 2022
Rollup of 6 pull requests

Successful merges:

 - rust-lang#102300 (Use a macro to not have to copy-paste `ConstFnMutClosure::new(&mut fold, NeverShortCircuit::wrap_mut_2_imp)).0` everywhere)
 - rust-lang#102475 (unsafe keyword: trait examples and unsafe_op_in_unsafe_fn update)
 - rust-lang#102760 (Avoid repeated re-initialization of the BufReader buffer)
 - rust-lang#102764 (Check `WhereClauseReferencesSelf` after all other object safety checks)
 - rust-lang#102779 (Fix `type_of` ICE)
 - rust-lang#102780 (run Miri CI when std::sys changes)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit e461e94 into rust-lang:master Oct 7, 2022
@rustbot rustbot added this to the 1.66.0 milestone Oct 7, 2022
@RalfJung RalfJung deleted the unsafe branch October 8, 2022 08:38
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. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants