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

Drive-by mention unsafe fn closure coercion #802

Merged
merged 2 commits into from
Jul 29, 2020

Conversation

alercah
Copy link
Contributor

@alercah alercah commented Apr 16, 2020

No description provided.

@ehuss
Copy link
Contributor

ehuss commented Apr 17, 2020

I'm a bit uncertain about why it would call out unsafe specifically here. unsafe fn isn't a distinct pointer type from fn is it? I wouldn't expect to call out all the function "front matter" like "extern" here, either.

@alercah
Copy link
Contributor Author

alercah commented Apr 18, 2020

Yes, they are. Interestingly, though, unsafe closures can be assigned to regular function pointers: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=de1dee0081843286d774d1d21c27091c

(I'm not sure this is wrong, but it's interesting.)

I forgot about extern, but closures can't be converted to extern functions (other than usual Rust ones).

@ldm0
Copy link
Contributor

ldm0 commented May 15, 2020

A drive-by developer here.

@alercah There is no "unsafe closure" actually. For the let u = || unsafe {};, u is just a closure with an unsafe block.

But I think this PR maybe useful. Since the rustc currently support coercing non-capturing closure to safe and unsafe function pointer. Coercing non-capturing closure to extern function pointer may be implemented in the future(rust-lang/rust#44291) but now it won't pass compilation. I guess the reference need to point out either the compile-passing unsafe fn or the non-compile-passing extern fn.

@nikomatsakis nikomatsakis self-assigned this May 27, 2020
@nikomatsakis
Copy link
Contributor

I do not think of unsafe fn as a distinct type from fn -- rather I think of "function pointers" as types that have a range of options, something like this (ignoring for<...>):

  • extern "ABI" unsafe? fn(A0..An) -> R

@alercah
Copy link
Contributor Author

alercah commented May 27, 2020

What about impls?

@nikomatsakis
Copy link
Contributor

@alercah I don't really understand your question, can you elaborate?

@alercah
Copy link
Contributor Author

alercah commented Jun 10, 2020 via email

@nikomatsakis
Copy link
Contributor

I see. Well, I guess it depends on what one means by "a separate type". I see "function pointer types" as a family of types, I suppose, parameterized by various things:

  • their ABI
  • their safety
  • their argument and return types

much as a type like Vec is parameterized by its element type T.

If we were going for completeness, I don't think that "fn or unsafe fn" is sufficient, since it doesn't account for ABI etc, so perhaps we should just write "(e.g., fn())" instead.

@nikomatsakis
Copy link
Contributor

@alercah

so perhaps we should just write "(e.g., fn())" instead.

what do you think about this? :)

@alercah
Copy link
Contributor Author

alercah commented Jul 28, 2020

Ah, I see. That makes sense to me!

src/types/closure.md Outdated Show resolved Hide resolved
Copy link
Contributor

@nikomatsakis nikomatsakis left a comment

Choose a reason for hiding this comment

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

in suggestion form

@nikomatsakis
Copy link
Contributor

@ehuss how do I merge, just click the green button? :)

@ehuss
Copy link
Contributor

ehuss commented Jul 29, 2020

Yes, after marking "approved" just click the merge button. 😃

@nikomatsakis nikomatsakis merged commit 5642af8 into rust-lang:master Jul 29, 2020
Manishearth added a commit to Manishearth/rust that referenced this pull request Aug 5, 2020
Update books

## reference

7 commits in b329ce37424874ad4db94f829a55807c6e21d2cb..c9b2736a059469043177e1e4ed41a55d7c63ac28
2020-07-20 08:54:08 -0700 to 2020-08-03 03:34:03 -0700
- Fix documented build output path. (rust-lang/reference#870)
- Update token usage table. (rust-lang/reference#868)
- Allow trait inner attributes (rust-lang/reference#864)
- patterns.md - add word "underscore" to _ paragraph (rust-lang/reference#865)
- Drive-by mention unsafe fn closure coercion (rust-lang/reference#802)
- grammar: Change "For awhile" to "For a while" (rust-lang/reference#857)
- Added Unpin to list of Auto Traits (rust-lang/reference#854)

## book

7 commits in a914f2c7e5cdb771fa465de142381a51c53b580e..363293c1c5ce9e84ea3935a5e29ce8624801208a
2020-07-21 09:20:05 -0500 to 2020-08-03 15:56:30 -0500
- replace commas with m-dashes to improve readability of chapter 4.1 (rust-lang/book#2419)
- Update TOML link to official website (rust-lang/book#2411)
- Add github repo link (rust-lang/book#2265)
- Remove the version number entirely so we can stop updating it
- Add link to the `Vec&lt;T&gt;` API documentation (rust-lang/book#2249)
- link to stdlib atomic docs (rust-lang/book#2361)
- mdbook version used is now 0.4.x (rust-lang/book#2410)

## rust-by-example

1 commits in 229c6945a26a53a751ffa4f9cb418388c00029d3..2e9271981adc32613365810f3428334c07095215
2020-07-06 10:13:15 -0300 to 2020-07-27 13:39:16 -0500
- Replaced "princess" with "royal" (rust-lang/rust-by-example#1363)

## embedded-book

1 commits in 94d9ea8460bcbbbfef1877b47cb930260b5849a7..b5256448a2a4c1bec68b93c0847066f92f2ff5a9
2020-07-05 14:17:40 +0000 to 2020-07-24 23:09:29 +0000
- Update c-with-rust.md  (rust-embedded/book#256)
JohnTitor added a commit to JohnTitor/rust that referenced this pull request Aug 5, 2020
Update books

## reference

7 commits in b329ce37424874ad4db94f829a55807c6e21d2cb..c9b2736a059469043177e1e4ed41a55d7c63ac28
2020-07-20 08:54:08 -0700 to 2020-08-03 03:34:03 -0700
- Fix documented build output path. (rust-lang/reference#870)
- Update token usage table. (rust-lang/reference#868)
- Allow trait inner attributes (rust-lang/reference#864)
- patterns.md - add word "underscore" to _ paragraph (rust-lang/reference#865)
- Drive-by mention unsafe fn closure coercion (rust-lang/reference#802)
- grammar: Change "For awhile" to "For a while" (rust-lang/reference#857)
- Added Unpin to list of Auto Traits (rust-lang/reference#854)

## book

7 commits in a914f2c7e5cdb771fa465de142381a51c53b580e..363293c1c5ce9e84ea3935a5e29ce8624801208a
2020-07-21 09:20:05 -0500 to 2020-08-03 15:56:30 -0500
- replace commas with m-dashes to improve readability of chapter 4.1 (rust-lang/book#2419)
- Update TOML link to official website (rust-lang/book#2411)
- Add github repo link (rust-lang/book#2265)
- Remove the version number entirely so we can stop updating it
- Add link to the `Vec&lt;T&gt;` API documentation (rust-lang/book#2249)
- link to stdlib atomic docs (rust-lang/book#2361)
- mdbook version used is now 0.4.x (rust-lang/book#2410)

## rust-by-example

1 commits in 229c6945a26a53a751ffa4f9cb418388c00029d3..2e9271981adc32613365810f3428334c07095215
2020-07-06 10:13:15 -0300 to 2020-07-27 13:39:16 -0500
- Replaced "princess" with "royal" (rust-lang/rust-by-example#1363)

## embedded-book

1 commits in 94d9ea8460bcbbbfef1877b47cb930260b5849a7..b5256448a2a4c1bec68b93c0847066f92f2ff5a9
2020-07-05 14:17:40 +0000 to 2020-07-24 23:09:29 +0000
- Update c-with-rust.md  (rust-embedded/book#256)
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.

4 participants