First of all, I really don’t want to retread the same territory here. Default match bindings is, sadly, part of the stable language now, and no amount of discussion about it here will change that. Many of these issues have already been posted elsewhere. So, to be clear up front: I’m happy to summarize the issues to help improve understanding and awareness, but this is not the appropriate thread for a discussion or debate on those issues (unless it’s specifically towards improving the compiler or tooling to help avoid errors and enforce typing). The subject of this thread is implementing a lint to more strictly enforce matching types in some codebases. Suggestions welcome for other machinery that would help ensure the compiler strictly enforces matching types as well.
Whether you’re doing type-directed reasoning/development, or trying to avoid or track down bugs, or trying to maintain efficiency, you may well care whether you have a reference or an owned object. When the compiler flags something like "you have a
T and you need a
&T", I generally put a moment’s thought into whether the right fix involves adding a
ref somewhere, or whether the right fix involves going back to where I declared a type and changing it to take a reference instead of an owned value.
This change, for many people, took away some of the feeling that the compiler is helping by providing type errors, and instead made us feel less supported by the compiler. Feeling safer allows coding more quickly and confidently.
When the compiler ignores whether I have a reference or an owned value, it prevents me from caring about that, and decides for me that I don’t get to care about that.
As an aside, this is one reason why I don’t actually mind if the compiler accepts a
&mut T when it expected a
&T; that doesn’t change a non-reference to a reference, it just says “I don’t plan to modify this”. I do, however, want the compiler to strictly enforce the difference between