Skip to content

Initial implementation of FnPtr trait - #156176

Merged
rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
carbotaniuman:fn-ptr-trait-impl
Aug 19, 2026
Merged

Initial implementation of FnPtr trait#156176
rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
carbotaniuman:fn-ptr-trait-impl

Conversation

@carbotaniuman

@carbotaniumancarbotaniuman commented May 5, 2026

Copy link
Copy Markdown
Contributor

View all comments

This commit is an initial implementation of the FnPtr trait as described in the fn_static tracking issue, which consists of moving the internally unstable core::marker::FnPtr to core::ops::FnPtr, as well as changing the API. Because NonNull is used in the new as_ptr signature, it was also turned into a proper lang item.

Part of fn_static: #148768

@rustbot

Copy link
Copy Markdown
Collaborator

The Clippy subtree was changed

cc @rust-lang/clippy

rust-analyzer is developed in its own repository. If possible, consider making this change to rust-lang/rust-analyzer instead.

cc @rust-lang/rust-analyzer

Some changes occurred to MIR optimizations

cc @rust-lang/wg-mir-opt

@rustbotrustbot added O-unix Operating system: Unix-like S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-clippy Relevant to the Clippy team. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue. T-rust-analyzer Relevant to the rust-analyzer team, which will review and decide on the PR/issue. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver) labels May 5, 2026
@rustbot

Copy link
Copy Markdown
Collaborator

r? @nia-e

rustbot has assigned @nia-e.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: @scottmcm, libs
  • @scottmcm, libs expanded to 8 candidates
  • Random selection from Mark-Simulacrum, jhpratt, nia-e, scottmcm

@rust-log-analyzer

This comment has been minimized.

@nia-e

nia-e commented May 7, 2026

Copy link
Copy Markdown
Member

Thanks for the PR! I'll take a proper look asap, but in the meantime could you add some tests for the feature & take a look at the build errors?

@rust-log-analyzer

This comment has been minimized.

@rustbot

Copy link
Copy Markdown
Collaborator

This PR changes rustc_public

cc @oli-obk, @celinval, @ouz-a, @makai410

Some changes occurred to the CTFE / Miri interpreter

cc @rust-lang/miri

Some changes occurred to the CTFE machinery

cc @RalfJung, @oli-obk, @lcnr

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rustbot

This comment has been minimized.

Comment threadcompiler/rustc_middle/src/ty/instance.rs Outdated
Comment threadcompiler/rustc_ty_utils/src/instance.rs Outdated
Comment threadlibrary/core/src/ops/function.rs Outdated
}

/// A type representing a pointer to a function pointer.
// FIXME: Make this a proper extern type.

@nia-enia-eMay 12, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What's holding us back from making this an extern type now?

View changes since the review

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

If I try I get:

error: foreign type has missing stability attribute
--> library/core/src/ops/function.rs:318:5
|
318 | pub type Code;
| ^^^^^^^^^^^^^

And if I try to put a stability marker on it I get this:

extern "C" {
error: `#[unstable]` attribute cannot be used on foreign types
--> library/core/src/ops/function.rs:318:5
|
318 | #[unstable(feature = "fn_static", issue = "148768")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: `#[unstable]` can be applied to associated consts, associated types, constants, crates, data types, enum variants, extern crates, foreign statics, functions, impl blocks, macro defs, modules, statics, struct fields, trait aliases, traits, type aliases, type parameters, and use statements

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

we should change our attribute handling to support stabiity attributes on foreign types. please either implement this or open a github issue for this

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Don't have the time to implement this right now, but made an issue #158200.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this has been fixed I think, so we can now use extern types here if we need to 🤔

Comment threadlibrary/core/src/ops/function.rs Outdated
Comment threadlibrary/core/src/ptr/mod.rs Outdated
@rustbotrustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 12, 2026
@rustbot

Copy link
Copy Markdown
Collaborator

Reminder, once the PR becomes ready for a review, use @rustbot ready.

jhpratt added a commit to jhpratt/rust that referenced this pull request Aug 16, 2026
…=jackh726
Initial implementation of `FnPtr` trait
This commit is an initial implementation of the `FnPtr` trait as described in the `fn_static` tracking issue, which consists of moving the internally unstable `core::marker::FnPtr` to `core::ops::FnPtr`, as well as changing the API. Because `NonNull` is used in the new `as_ptr` signature, it was also turned into a proper lang item.
Part of `fn_static`: rust-lang#148768
@jhprattjhpratt mentioned this pull request Aug 16, 2026
@jhpratt

Copy link
Copy Markdown
Member

@bors r- #161155 (comment)

@rust-borsrust-borsBot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Aug 16, 2026
@rust-bors

rust-borsBot commented Aug 16, 2026

Copy link
Copy Markdown
Contributor

This pull request was unapproved.

This PR was contained in a rollup (#161155), which was unapproved.

View changes since this unapproval

@rust-bors

This comment has been minimized.

@rustbot

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@rust-log-analyzer

This comment has been minimized.

This commit is an initial implementation of the `FnPtr` trait as
described in the `fn_static` tracking issue, which consists of moving
the internally unstable `core::marker::FnPtr` to `core::ops::FnPtr`, as
well as changing the API. Because `NonNull` is used in the new `as_ptr`
signature, it was also turned into a proper lang item.
@jackh726

Copy link
Copy Markdown
Member

@bors r+

@rust-bors

rust-borsBot commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 5898a39 has been approved by jackh726

It is now in the queue for this repository.

@rust-borsrust-borsBot 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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Aug 18, 2026
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Aug 18, 2026
…=jackh726
Initial implementation of `FnPtr` trait
This commit is an initial implementation of the `FnPtr` trait as described in the `fn_static` tracking issue, which consists of moving the internally unstable `core::marker::FnPtr` to `core::ops::FnPtr`, as well as changing the API. Because `NonNull` is used in the new `as_ptr` signature, it was also turned into a proper lang item.
Part of `fn_static`: rust-lang#148768
rust-borsBot pushed a commit that referenced this pull request Aug 18, 2026
…uwer
Rollup of 8 pull requests
Successful merges:
- #154210 (fix: fix the capture behavior of `if let` in closures)
- #156176 (Initial implementation of `FnPtr` trait)
- #160767 (Unify E0117 foreign-trait label for ADT/primitive types with existing Slice/Array/Tuple handling)
- #160489 (Adding diagnostic item markers for multiple fs functions and structs)
- #161220 (bootstrap: Allow `./x fix --allow-dirty`)
- #161291 (Rename `ProjectionPredicate` and `TraitPredicate`)
- #161296 (Enable overflow checks in `rustc_thread_pool`)
- #161304 (Rename test so it matches the issue)
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Aug 18, 2026
…=jackh726
Initial implementation of `FnPtr` trait
This commit is an initial implementation of the `FnPtr` trait as described in the `fn_static` tracking issue, which consists of moving the internally unstable `core::marker::FnPtr` to `core::ops::FnPtr`, as well as changing the API. Because `NonNull` is used in the new `as_ptr` signature, it was also turned into a proper lang item.
Part of `fn_static`: rust-lang#148768
jhpratt added a commit to jhpratt/rust that referenced this pull request Aug 19, 2026
…=jackh726
Initial implementation of `FnPtr` trait
This commit is an initial implementation of the `FnPtr` trait as described in the `fn_static` tracking issue, which consists of moving the internally unstable `core::marker::FnPtr` to `core::ops::FnPtr`, as well as changing the API. Because `NonNull` is used in the new `as_ptr` signature, it was also turned into a proper lang item.
Part of `fn_static`: rust-lang#148768
This was referenced Aug 19, 2026
rust-borsBot pushed a commit that referenced this pull request Aug 19, 2026
Rollup of 18 pull requests
Successful merges:
- #154210 (fix: fix the capture behavior of `if let` in closures)
- #156176 (Initial implementation of `FnPtr` trait)
- #160767 (Unify E0117 foreign-trait label for ADT/primitive types with existing Slice/Array/Tuple handling)
- #161297 (std: use UNIX's `Instant` and `SystemTime` on Hermit)
- #160489 (Adding diagnostic item markers for multiple fs functions and structs)
- #160643 (Require windowed (and exception) for Xtensa ABI)
- #161088 (suppress projection errors already covered by a trait error)
- #161114 (Remove fields from TypeKind: Struct, Enum, Union and Tuple)
- #161115 (Assorted allocator nitpicks)
- #161220 (bootstrap: Allow `./x fix --allow-dirty`)
- #161296 (Enable overflow checks in `rustc_thread_pool`)
- #161298 (remove rustc_error_messages dependency)
- #161304 (Rename test so it matches the issue)
- #161309 (`allow(non_camel_case_types)` in `minicore.rs`)
- #161315 (Relax codgen test variable regex)
- #161318 (Doc: clarify how `Read::bytes` handling Interrupted errors)
- #161321 (Update books)
- #161335 ([compiletest] Use the correct rustc lib directory for query_rustc_output)
@rust-bors
rust-borsBot merged commit 30bd758 into rust-lang:mainAug 19, 2026
13 checks passed
@rustbotrustbot added this to the 1.100.0 milestone Aug 19, 2026
rust-borsBot pushed a commit that referenced this pull request Aug 19, 2026
Rollup merge of #156176 - carbotaniuman:fn-ptr-trait-impl, r=jackh726
Initial implementation of `FnPtr` trait
This commit is an initial implementation of the `FnPtr` trait as described in the `fn_static` tracking issue, which consists of moving the internally unstable `core::marker::FnPtr` to `core::ops::FnPtr`, as well as changing the API. Because `NonNull` is used in the new `as_ptr` signature, it was also turned into a proper lang item.
Part of `fn_static`: #148768
RalfJung pushed a commit to RalfJung/miri that referenced this pull request Aug 19, 2026
Rollup of 18 pull requests
Successful merges:
- rust-lang/rust#154210 (fix: fix the capture behavior of `if let` in closures)
- rust-lang/rust#156176 (Initial implementation of `FnPtr` trait)
- rust-lang/rust#160767 (Unify E0117 foreign-trait label for ADT/primitive types with existing Slice/Array/Tuple handling)
- rust-lang/rust#161297 (std: use UNIX's `Instant` and `SystemTime` on Hermit)
- rust-lang/rust#160489 (Adding diagnostic item markers for multiple fs functions and structs)
- rust-lang/rust#160643 (Require windowed (and exception) for Xtensa ABI)
- rust-lang/rust#161088 (suppress projection errors already covered by a trait error)
- rust-lang/rust#161114 (Remove fields from TypeKind: Struct, Enum, Union and Tuple)
- rust-lang/rust#161115 (Assorted allocator nitpicks)
- rust-lang/rust#161220 (bootstrap: Allow `./x fix --allow-dirty`)
- rust-lang/rust#161296 (Enable overflow checks in `rustc_thread_pool`)
- rust-lang/rust#161298 (remove rustc_error_messages dependency)
- rust-lang/rust#161304 (Rename test so it matches the issue)
- rust-lang/rust#161309 (`allow(non_camel_case_types)` in `minicore.rs`)
- rust-lang/rust#161315 (Relax codgen test variable regex)
- rust-lang/rust#161318 (Doc: clarify how `Read::bytes` handling Interrupted errors)
- rust-lang/rust#161321 (Update books)
- rust-lang/rust#161335 ([compiletest] Use the correct rustc lib directory for query_rustc_output)
pullBot pushed a commit to asukaminato0721/rust-analyzer that referenced this pull request Aug 20, 2026
Rollup of 18 pull requests
Successful merges:
- rust-lang/rust#154210 (fix: fix the capture behavior of `if let` in closures)
- rust-lang/rust#156176 (Initial implementation of `FnPtr` trait)
- rust-lang/rust#160767 (Unify E0117 foreign-trait label for ADT/primitive types with existing Slice/Array/Tuple handling)
- rust-lang/rust#161297 (std: use UNIX's `Instant` and `SystemTime` on Hermit)
- rust-lang/rust#160489 (Adding diagnostic item markers for multiple fs functions and structs)
- rust-lang/rust#160643 (Require windowed (and exception) for Xtensa ABI)
- rust-lang/rust#161088 (suppress projection errors already covered by a trait error)
- rust-lang/rust#161114 (Remove fields from TypeKind: Struct, Enum, Union and Tuple)
- rust-lang/rust#161115 (Assorted allocator nitpicks)
- rust-lang/rust#161220 (bootstrap: Allow `./x fix --allow-dirty`)
- rust-lang/rust#161296 (Enable overflow checks in `rustc_thread_pool`)
- rust-lang/rust#161298 (remove rustc_error_messages dependency)
- rust-lang/rust#161304 (Rename test so it matches the issue)
- rust-lang/rust#161309 (`allow(non_camel_case_types)` in `minicore.rs`)
- rust-lang/rust#161315 (Relax codgen test variable regex)
- rust-lang/rust#161318 (Doc: clarify how `Read::bytes` handling Interrupted errors)
- rust-lang/rust#161321 (Update books)
- rust-lang/rust#161335 ([compiletest] Use the correct rustc lib directory for query_rustc_output)
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-attributesArea: Attributes (`#[…]`, `#![…]`)O-unixOperating system: Unix-likeS-waiting-on-borsStatus: Waiting on bors to run and complete tests. Bors will change the label on completion.T-clippyRelevant to the Clippy team.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.T-libsRelevant to the library team, which will review and decide on the PR/issue.T-rust-analyzerRelevant to the rust-analyzer team, which will review and decide on the PR/issue.T-typesRelevant to the types team, which will review and decide on the PR/issue.WG-trait-system-refactorThe Rustc Trait System Refactor Initiative (-Znext-solver)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants

@carbotaniuman@rustbot@rust-log-analyzer@nia-e@jackh726@jhpratt@lcnr