Skip to content

Reflection TypeKind::FnPtr#152173

Open
9SonSteroids wants to merge 1 commit intorust-lang:mainfrom
9SonSteroids:fn_ptr_type_info
Open

Reflection TypeKind::FnPtr#152173
9SonSteroids wants to merge 1 commit intorust-lang:mainfrom
9SonSteroids:fn_ptr_type_info

Conversation

@9SonSteroids
Copy link

@9SonSteroids 9SonSteroids commented Feb 5, 2026

This is for #146922.

Const-eval currently lacks full support for function pointer (fn) types. We should implement handling of FnPtr TypeKind, covering safe and unsafe functions, Rust and custom ABIs, input and output types, higher-ranked lifetimes, and variadic functions.

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. 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. labels Feb 5, 2026
@9SonSteroids 9SonSteroids marked this pull request as ready for review February 5, 2026 15:23
@rustbot
Copy link
Collaborator

rustbot commented Feb 5, 2026

Some changes occurred to the CTFE machinery

cc @RalfJung, @oli-obk, @lcnr

The reflection data structures are tied exactly to the implementation
in the compiler. Make sure to also adjust rustc_const_eval/src/const_eval/type_info.rs

cc @oli-obk

@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 Feb 5, 2026
@rustbot
Copy link
Collaborator

rustbot commented Feb 5, 2026

r? @nnethercote

rustbot has assigned @nnethercote.
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

@9SonSteroids 9SonSteroids marked this pull request as draft February 5, 2026 15:29
@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 Feb 5, 2026
- Implement handling of FnPtr TypeKind in const-eval, including:
  - Unsafety flag (safe vs unsafe fn)
  - ABI variants (Rust, Named(C), Named(custom))
  - Input and output types
  - Variadic function pointers
- Add const-eval tests covering:
  - Basic Rust fn() pointers
  - Unsafe fn() pointers
  - Extern C and custom ABI pointers
  - Functions with multiple inputs and output types
  - Variadic functions
- Use const TypeId checks to verify correctness of inputs, outputs, and payloads
@9SonSteroids 9SonSteroids marked this pull request as ready for review February 5, 2026 17:09
@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 Feb 5, 2026
@SpriteOvO SpriteOvO added the F-type_info #![feature(type_info)] label Feb 5, 2026
@rust-log-analyzer
Copy link
Collaborator

The job tidy failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)
##[group]Runner Image Provisioner
Hosted Compute Agent
Version: 20260123.484
Commit: 6bd6555ca37d84114959e1c76d2c01448ff61c5d
Build Date: 2026-01-23T19:41:17Z
Worker ID: {86bf5dda-318a-45df-95db-9cadfb37e88a}
Azure Region: westcentralus
##[endgroup]
##[group]Operating System
Ubuntu
24.04.3
LTS
---
checking C++ file formatting
spellchecking files
building external tool typos from package typos-cli@1.38.1
finished building tool typos
error: `varidic` should be `variadic`
    ╭▸ library/coretests/tests/mem/fn_ptr.rs:156:9
    │
156 │ fn test_varidic() {
    ╰╴        ━━━━━━━
rerun tidy with `--extra-checks=spellcheck --bless` to fix typos
tidy [extra_checks]: checks with external tool 'typos' failed
tidy [extra_checks]: FAIL
tidy: The following check failed: extra_checks
Command `/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-tools-bin/rust-tidy --root-path=/checkout --cargo-path=/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo --output-dir=/checkout/obj/build --concurrency=4 --npm-path=/node/bin/yarn --extra-checks=py,cpp,js,spellcheck` failed with exit code 1
Created at: src/bootstrap/src/core/build_steps/tool.rs:1612:23
Executed at: src/bootstrap/src/core/build_steps/test.rs:1365:29

Command has failed. Rerun with -v to see more details.
Bootstrap failed while executing `test src/tools/tidy tidyselftest --extra-checks=py,cpp,js,spellcheck`
Build completed unsuccessfully in 0:02:39
  local time: Thu Feb  5 18:48:25 UTC 2026
  network time: Thu, 05 Feb 2026 18:48:25 GMT
##[error]Process completed with exit code 1.

/// Compile-time type information about generic lifetimes.
#[derive(Debug)]
#[unstable(feature = "type_info", issue = "146922")]
pub struct Lifetime {
Copy link
Contributor

Choose a reason for hiding this comment

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

This doesn't appear to be used anymore

self.write_fn_ptr_type_info(
fn_ptr_place,
binder.skip_binder().output(),
signature.safety.is_unsafe(),
Copy link
Contributor

Choose a reason for hiding this comment

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

You should exhaustively destructure signature so that future changes to the struct get picked up here.


// FIXME: Merge with #151142
// A general method to write an array to a static slice place.
fn project_write_array(
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
fn project_write_array(
fn allocate_fill_and_write_slice_ptr(

Or sth equally forcing ppl to read docs on what it does

@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 Feb 5, 2026
@rustbot
Copy link
Collaborator

rustbot commented Feb 5, 2026

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

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

Labels

F-type_info #![feature(type_info)] S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. 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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants