You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
proc bounds and closure lifetimes are parsed incorrectly #10553
<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
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>.)
Activity
Kimundi commentedon Nov 18, 2013
cc @nikomatsakis
pnkfelix commentedon Dec 2, 2013
cc me
pnkfelix commentedon Dec 12, 2013
Note in particular that attempting to make
'a |T| -> Ua type expression leads to ambiguities when parsing a generic instantiation where you are trying to pass a closure type as the type parameter, likeFoo<'a |T| -> U>, because the parser will eagerly treat theFoo<'aprefix as a lifetime parameter being passed toFoo, and thus it expects a comma next.(An easy work-around for the type being is to use a
typedeclaration liketype closure<'a, T, U> = 'a |T| -> U;and then you can instantiate
Fooon the typeclosure<'a, T, U>.)flaper87 commentedon Jan 30, 2014
cc @flaper87
nikomatsakis commentedon Feb 27, 2014
Another parser issue: something like
proc:Senddoesn't parsenikomatsakis commentedon Feb 27, 2014
Nominating.
pnkfelix commentedon Feb 27, 2014
Assigning 1.0, P-backcompat-lang
emberian commentedon Feb 27, 2014
cc me
nikomatsakis commentedon Feb 27, 2014
For reference, I believe the syntax ought to be:
nikomatsakis commentedon Feb 27, 2014
Except of course that parameter lists are comma-separated
alexcrichton commentedon Feb 27, 2014
I'm assuming that with that syntax you can also have multiple
Kvalues+-separate? Would I be correct in these translations:17 remaining items
auto merge of #13268 : alexcrichton/rust/parse-closure, r=cmr
Auto merge of rust-lang#10553 - Nilstrieb:better-uninit, r=Alexendoo
Merge rust-lang#10555