Skip to content
This repository has been archived by the owner on Apr 5, 2024. It is now read-only.

Handle let _ = x in coercing closures to FnPtr #23

Open
arora-aman opened this issue Nov 9, 2020 · 2 comments
Open

Handle let _ = x in coercing closures to FnPtr #23

arora-aman opened this issue Nov 9, 2020 · 2 comments
Labels
enhancement New feature or request

Comments

@arora-aman
Copy link
Member

arora-aman commented Nov 9, 2020

Consider the following closure:

let x;

let c = || {
    let _ = x;
};

let f: fn() = c; 

When capture_disjoint_fields is enabled, this closure doesn't capture x, implying c can be coerced to an FnPtr.

However, the code that checks if coercion can happen depends on upvars_mentioned which are computed before the capture analysis and would result in an error.

@arora-aman
Copy link
Member Author

arora-aman commented Nov 9, 2020

Documenting a solution @nikomatsakis has previously proposed:

  • When the coercion code runs in Typeck we set an Obligation for the closure to have no captures/ can be coerced to an FnPtr.
  • After capture analysis, in trait selection, we ensure that the obligation can be met.

@arora-aman
Copy link
Member Author

After #24

@arora-aman arora-aman added the enhancement New feature or request label Feb 16, 2021
@nikomatsakis nikomatsakis added this to the Polish complete milestone Feb 17, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants