-
Notifications
You must be signed in to change notification settings - Fork 13k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
default methods: parser rejects methods with underscore names for parameters #8468
Comments
part of #2794 |
There is a related issue where it accepts unnamed arguments in the definition of a default method. (But then ICEs on them.) The problem is that when parsing function declarations in traits, it uses the code for parsing arguments in function types. That is, allowing a name to be missing, not allowing patterns. This makes sense for required methods, but for provided ones, we would rather not allow a missing name, but allow full patterns. At least, that is my opinion. How to actually handle this in the parser is problematic, though, since we can't know whether it is a default method definition until after the argument list has been parsed. We could perhaps allow both, and then have a check afterwards... |
Normally we try to avoid having it be ambiguous whether something is a type, pattern, or expression (this is part of guaranteeing that the grammar is LL(1) or whatever our goal is). We may have to make fns in trait declarations require patterns. |
Yes, if we take this ticket to its natural limit, then we end up wanting to support arbitrary patterns in trait default methods, and thus hit the problem of arbitrary token look-ahead to find the colon that would allow us to distinguish whether we are looking at an pattern or at a type. I think I would be weakly in favor of making fns in trait declarations require patterns. (but only weakly so. in the meantime, I'm going to try to fix this particular special case, especially since doing so would make a port towards the aforementioned requirement go more smoothly, since we could add all the |
…me-in-trait-default-method, r=alexcrichton Fix #8468. (Though the right answer in the end, as noted on the dialogue on the ticket, might be to just require trait methods to name their parameters, regardless of whether they have a default method implementation or not.)
Rustup r? `@ghost` changelog: none
The text was updated successfully, but these errors were encountered: