Skip to content

Initial implementation of FnPtr trait#156176

Open
carbotaniuman wants to merge 1 commit into
rust-lang:mainfrom
carbotaniuman:fn-ptr-trait-impl
Open

Initial implementation of FnPtr trait#156176
carbotaniuman wants to merge 1 commit into
rust-lang:mainfrom
carbotaniuman:fn-ptr-trait-impl

Conversation

@carbotaniuman

@carbotaniuman carbotaniuman commented May 5, 2026

Copy link
Copy Markdown
Contributor

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

rustbot commented May 5, 2026

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

@rustbot rustbot 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

rustbot commented May 5, 2026

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

rustbot commented May 7, 2026

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

rustbot commented May 8, 2026

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.

Comment thread compiler/rustc_middle/src/ty/instance.rs Outdated
Comment thread compiler/rustc_ty_utils/src/instance.rs Outdated
}

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

@nia-e nia-e May 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
Contributor Author

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

Comment thread library/core/src/ops/function.rs Outdated
Comment thread library/core/src/ptr/mod.rs Outdated
@rustbot rustbot 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

rustbot commented May 12, 2026

Copy link
Copy Markdown
Collaborator

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

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.
@carbotaniuman

Copy link
Copy Markdown
Contributor Author

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels May 14, 2026
@rust-bors

rust-bors Bot commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

☔ The latest upstream changes (presumably #157600) made this pull request unmergeable. Please resolve the merge conflicts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants