Fair enough, although that one does not bind a new variable, so it's not that bad (cost to pay to get match ergonomics, since ref
and ref mut
are more noisy than "single-char
" sigils).
-
The following example, which indeeds fails with a type error on the assertion, is, however, much more saddening:
match outputs::<&i32>() {
two @ 2 => assert_eq!(two, 2),
…
}
But the fact we already have some inconsistencies shouldn't be an argument to get more, imho.
Note that without the whole ergonomic discussion, for &
(or &mut
) stuff, we can indeed disambiguate between the two bindings by doing:
match outputs::<&i32>() {
&(two @ 2) => assert_eq!(two, 2), // ✅ (except for unused_parens firing 😩)
two @ &2 => assert_eq!(two, &2), // ✅
…
}
So I think that Deref{,Mut}
generalizations should be no exception to this, as you mentioned, so there must be the option to use a sigil / an annotation. And, as I mentioned in my previous post, I think that such sigil elision should be left to a follow-up RFC; it shouldn't be mixed with discussions about the desired SpecialDeref
semantics.