Skip to content

proc bounds and closure lifetimes are parsed incorrectly #10553

Closed

Description

@Kimundi
<kimundi> If you have a function that takes a reference to a closure the lifetime specifier becomes confusing
<kimundi> fn foo(&|T| -> U), fn foo(&'a |T| -> U) and fn foo(&'a 'a |T| -> U) are all valid, and in the second one you can't tell which one of both the lifetimes is supposed to belong to
<nmatsakis> kimundi: this is parser bug, 'a |T| shouldn't parse
<nmatsakis> it should be |T|:'a

<nmatsakis> the parser may well be wrong
<nmatsakis> maybe got overlooked

<kimundi> well, if I change to that syntax I get compile errors
<kimundi> this works: impl<'a> StringPrefixMatch for 'a |$self_anon| -> bool
<kimundi> this doesn't: impl<'a> StringPrefixMatch for |$self_anon|:'a -> bool
<kimundi> I get a "'static is the only valid region allowed here" error

<nmatsakis> kimundi: I think it's just a parser bug
<nmatsakis> kimundi: yes, I can understand why that would occur
<kimundi> why?

<nmatsakis> kimundi: basically because some cleanup is needed
<nmatsakis> we are interpreting |...|:K with K as a list of bounds , which is correct,
<nmatsakis> but we currently haven't implemented support for arbitrary lifetimes in bounds,
<nmatsakis> which is wrong,
<nmatsakis> and instead we have special case treatment for closures,
<kimundi> Ah, so it only accepts the 'static bound there
<nmatsakis> which kind of fit ok with the old syntax,
<nmatsakis> but in the newer one we really should be just using general lifetimes in bounds

Activity

  1. Kimundi commented on Nov 18, 2013

    @Kimundi
    ContributorAuthor
  2. pnkfelix commented on Dec 2, 2013

    @pnkfelix
    Contributor

    cc me

  3. pnkfelix commented on Dec 12, 2013

    @pnkfelix
    Contributor

    Note in particular that attempting to make 'a |T| -> U a type expression leads to ambiguities when parsing a generic instantiation where you are trying to pass a closure type as the type parameter, like Foo<'a |T| -> U>, because the parser will eagerly treat the Foo<'a prefix as a lifetime parameter being passed to Foo, and thus it expects a comma next.

    (An easy work-around for the type being is to use a type declaration like
    type closure<'a, T, U> = 'a |T| -> U;
    and then you can instantiate Foo on the type closure<'a, T, U>.)

  4. flaper87 commented on Jan 30, 2014

    @flaper87
    Contributor
  5. nikomatsakis commented on Feb 27, 2014

    @nikomatsakis
    Contributor

    Another parser issue: something like proc:Send doesn't parse

  6. nikomatsakis commented on Feb 27, 2014

    @nikomatsakis
    Contributor

    Nominating.

  7. pnkfelix commented on Feb 27, 2014

    @pnkfelix
    Contributor

    Assigning 1.0, P-backcompat-lang

  8. added this to the 1.0 milestone on Feb 27, 2014
  9. emberian commented on Feb 27, 2014

    @emberian
    Contributor

    cc me

  10. nikomatsakis commented on Feb 27, 2014

    @nikomatsakis
    Contributor

    For reference, I believe the syntax ought to be:

    T = '|' ( id : T ) * '|' [ ':' K ] [ '->' T ]
      | 'proc' '(' ( id : T ) * ')' [ ':' K ] [ '->' T ]
      | ...
    K = TraitReference | Lifetime 
    
  11. nikomatsakis commented on Feb 27, 2014

    @nikomatsakis
    Contributor

    Except of course that parameter lists are comma-separated

  12. alexcrichton commented on Feb 27, 2014

    @alexcrichton
    Member

    I'm assuming that with that syntax you can also have multiple K values +-separate? Would I be correct in these translations:

    'a || => ||: 'a
    ||: 'static => ||: 'static
    'a ||: Send => ||: 'a + Send
  13. 17 remaining items

  14. added a commit that references this issue on Apr 6, 2014
    667f82a
  15. added a commit that references this issue on Apr 6, 2023
  16. added a commit that references this issue on Aug 21, 2026
    c4e88e9
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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions