Skip to content

Tracking Issue for RFC 3216: "Allow using for<'a> syntax when declaring closures" #97362

Description

@pnkfelix

View all comments

This is a tracking issue for the RFC "Allow using for<'a> syntax when declaring closures" (rust-lang/rfcs#3216).
The feature gate for the issue is #![feature(closure_lifetime_binder)].

About tracking issues

Tracking issues are used to record the overall progress of implementation.
They are also used as hubs connecting to other relevant issues, e.g., bugs or open design questions.
A tracking issue is however not meant for large scale discussion, questions, or bug reports about a feature.
Instead, open a dedicated issue for the specific matter and add the relevant feature gate label.

Steps

Unresolved Questions

How does the explicit lifetime binder deal interact with elided lifetimes. The addition of higher-kinded inference variables (rust-lang/types-team#131) may change the preferred design here.

Implementation history

Activity

  1. added
    T-langRelevant to the language team
    C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFC
    on May 24, 2022
  2. WaffleLapkin commented on May 31, 2022

    @WaffleLapkin
    Member

    I'd like to work on implementing this 👀

    @rustbot claim

  3. added 2 commits that reference this issue on Jul 14, 2022
  4. fmease commented on Jul 21, 2022

    @fmease
  5. added
    S-tracking-needs-summaryStatus: It's hard to tell what's been done and what hasn't! Someone should do some investigation.
    on Aug 10, 2022
  6. fakedrake commented on Aug 15, 2022

    @fakedrake
  7. WaffleLapkin commented on Aug 15, 2022

    @WaffleLapkin
  8. fakedrake commented on Aug 15, 2022

    @fakedrake
  9. WaffleLapkin commented on Aug 15, 2022

    @WaffleLapkin
  10. Jules-Bertholet commented on Oct 29, 2022

    @Jules-Bertholet
    Contributor

    Found an ICE involving this feature: #103736

    (Maybe we could use an F-closure_lifetime_binder tag?)

  11. added a commit that references this issue on Nov 4, 2022
  12. 11 remaining items

  13. added
    B-unstableBlocker: Implemented in the nightly compiler and unstable.
    on Mar 1, 2024
  14. zirconium-n commented on Mar 7, 2024

    @zirconium-n
    Contributor

    Is this feature blocked by any ongoing process? The implementation seems completed for a while, maybe we can push this to stabilization?

  15. removed their assignment
    on Mar 7, 2024
  16. opsnull commented on Apr 1, 2024

    @opsnull

    Is this feature blocked by any ongoing process? The implementation seems completed for a while, maybe we can push this to stabilization?

    same question here.

  17. runiq commented on Apr 2, 2024

    @runiq

    A question out of interest: Is this in any way a prerequisite for #68923?

  18. safinaskar commented on Jun 21, 2024

    @safinaskar
  19. workingjubilee commented on Jun 21, 2024

    @workingjubilee
  20. safinaskar commented on Jun 21, 2024

    @safinaskar
  21. Jules-Bertholet commented on Jun 21, 2024

    @Jules-Bertholet
    Contributor

    Ideally, the compiler would infer the most permissive signature possible, and so the for<'a> syntax would not be necessary (except as documentation).

  22. workingjubilee commented on Jun 21, 2024

    @workingjubilee
    Member

    I'm just saying for<'a> |x: &'a ()| -> &'a () { x } should work exactly like |x: &()| -> &() { x }, but it is currently not.

    It is my understanding that the binding of a specific lifetime and a for<'lt> (which, as I understand it, is effectively the ∀ lifetime) are not interchangeable in all cases, for the precise reason that ∀ and ∃ are different quantifiers.

  23. WanderLanz commented on Jun 21, 2024

    @WanderLanz

    @safinaskar As far as I understand compiler internals, a closure is inherently not invariant in regards to the lifetime of the arguments, and you need strong hints in order to make a closure such similar to a normal fn. For example, the higher ranked closure macros in the lending_iterator crate.

    In other words, the compiler is very conservative when closures could possibly have something like a for<'all> where Closure: 'all bound and instead only inherently satisfies FnOnce(&'1 ()) -> &'2 ().

    #![feature(closure_lifetime_binder)]
    
    trait X<'a> {
    }
    
    impl<'a, T, K> X<'a> for T
    where
        T: FnOnce(&'a ()) -> K
    {}
    
    fn foo<F>(f: F)
    where
        F: for<'a> X<'a>,
    {}
    
    fn main() {
        foo(for<'a> |x: &'a ()| -> &'a () { x }); // COMPILES
        // foo(|x: &()| -> &() { x }); // DOESN'T COMPILE
        
        fn hrc_hint<F>(f: F) -> F
        where
            F: for<'all> FnOnce(&'all ()) -> &'all ()
        {
            f
        }
        foo(hrc_hint(|x: &()| -> &() { x })); // NOW COMPILES
    }

    Finally, to avoid this, as far as I can tell, either: the compiler becomes less conservative on closures (possibly E.2024?), we get bounded HRTBs (for<'all> where *: 'all) (very unlikely), or closure_lifetime_binder becomes popular enough to be stabilized.

  24. Kixunil commented on Jul 17, 2024

    @Kixunil
    Contributor

    @runiq I don't know if it's required, it certainly looks helpful but FYI it's not suffficient - I tried using this and the code still doesn't compile.

  25. vojtechkral commented on Aug 30, 2024

    @vojtechkral
  26. compiler-errors commented on Aug 30, 2024

    @compiler-errors
    Contributor

    This is a tracking issue, for the record. If you have a bug with a specific feature, please open a new issue! If you want to discuss the implementation, please also open a new issue and it can be tagged C-discussion. Tracking issues have a linear history so they are not conducive to any kind of discussion.

  27. locked as off topic and limited conversation to collaborators on Aug 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    B-RFC-approvedBlocker: Approved by a merged RFC but not yet implemented.B-unstableBlocker: Implemented in the nightly compiler and unstable.C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCF-closure_lifetime_binder`#![feature(closure_lifetime_binder)]`S-tracking-needs-summaryStatus: It's hard to tell what's been done and what hasn't! Someone should do some investigation.T-langRelevant to the language teamT-typesRelevant to the types team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions