Uh oh!
There was an error while loading. Please reload this page.
Fix grammar for variadic functions - #781
Conversation
First, variadic params can be named:
extern "C" {
fn f(_: *mut u8, _: ...);
}
Second, variadic params can be followed by a comma
extern "C" {
fn f(_: *mut u8, ...,);
}ehuss
commented
Mar 13, 2020
Hm, I'm wondering if this was stabilized accidentally. This was added in rust-lang/rust#57760 (RFC 2137), see also rust-lang/rust#44930 and rust-lang/wg-grammar#45. Is there any meaning to the identifier of a variadic parameter? Or is it just ignored? That should probably be documented. (Or, if this was truely a mistake, maybe it should be reverted/fixed/made unstable?) |
matklad
commented
Mar 13, 2020
I don't know, I guess cc @Centril / @petrochenkov ? But apparently people use this in the real world already, this was reported against rust-analyzer. |
The function parameter grammar as implemented in Let FnParams<RN> = "(" head:FirstParam<RN> tail:{","Param<RN> %% ","}")";FirstParam<RN> = SelfParam | Param<RN> ;Param<RN> = CVariadicTy | AlwaysNamedParam | MaybeNamedParam<RN> ;MaybeNamedParam<RN> ifRN(edition(current_token)) = Pat":"ParamTy;// Named param.MaybeNamedParam<RN> = ParamTy;// Unnamed param.// Ambiguous with ^-- but for precedence.AlwaysNamedParam = NamedStart? Ident":"ParamTy;NamedStart = NtPat | "&" | "&&" | "mut";ParamTy = CVariadicTy | TyPlusAllowed;CVariadicTy = "...";For:
This is translated starting with Beyond this, AST validation imposes other semantic restrictions. |
Havvy
commented
Jan 13, 2021
ehuss
commented
Jan 13, 2021
Ah, yes, this should now be resolved. |
https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=17340777c82dc328a58a93f9db6d71c2