I'd like to find out exactly how this feature in pattern position interacts with pattern ergonomics. In the "motivating" example, self
(the scrutinee of the match
) is &HeaderError
, but the rhetorical compiler apparently has no difficulty resolving _
to HeaderError
(no &
). Am I to infer that _
can only be resolved to a "sufficiently deref'd version" of the scrutinee expression? What direction does the arrow of inference point here - can we determine from the scrutinee (without looking at the pattern itself) what _
must mean, or is there some kind of try-try-again algorithm (like we already have for .
resolution, except that wouldn't work here, because patterns)? Does _::
feature as a unique syntactic element in that _
can only be resolved specifically to an enum
(seems to be what people are assuming, but the syntax is misleading), or are associated constants also on the table, and if both are possible, how's that resolved?
re: social pressure
When pattern ergonomics made ref
partially redundant, there emerged quite a bit of social pressure to avoid ref
patterns entirely, despite the fact that it still works fine, and is occasionally still more readable than matching on a borrow. But because pattern ergonomics was the new thing around, ref
became, unnecessarily, a marker for "old" code. I feel that introducing _::
will make use Enum::*;
(which is perfectly fine as long as you don't give undue weight to overzealous clippy lints) a similar example of dated code, despite the fact that it's arguably still better than the "new" thing in many cases.
Despite the stated motivation being to reduce repetitive code, the "motivating example" is actually longer (and, in my opinion, noisier) using this rhetorical feature than it would be if the author had simply added a use HeaderError::*;
which works in Rust since 1.0. So, even if I accepted "it makes code shorter/prettier" as sufficient justification for adding a language feature (I don't), this one doesn't seem to meet even that relaxed criterion.
Despite some mention of inference farther up in the conversation, I'm not able to picture a non-contrived example of where you'd want the slight additional expressiveness of smart inference in _::
, and the OP's motivating example doesn't take advantage of that, either. In particular, it seems strange for a module to expose an enum's variants without exposing the enum itself - that it's supported for struct fields is more accident than design, and "we already do that for struct fields!" doesn't inherently motivate it for enum variants. Anyway, if we're to solve that problem, I think I'd rather have a more general typeof
mechanism, which would be far more practical and relevant in many more situations than just match
ing on unnameable enums.
In short, I don't think this suggested addition pulls its weight (but I'm open to being convinced by arguments that don't center wholly on code brevity).