fn foo(x: &Option<u32>) -> Option<&u32> {
match x {
Some(ref inner) => Some(inner),
None => None,
}
}
because of match ergonomics, every binding inside of Some is already matched by ref implicitly, so the additional explicit ref is completely redundant. Consider the following example where l and r have the exact same type.
#![feature(type_name_of_val)]
use std::any::type_name_of_val;
fn foo(x: &Option<(u32, u32)>) {
match x {
Some((l, ref r)) => assert_eq!(
type_name_of_val(l),
type_name_of_val(r),
),
None => unreachable!(),
}
}
fn main() {
foo(&Some((3, 3)));
}
This lint should either suggest to disable match ergonomics by adding & and &mut patterns in the relevant places or to remove the ref.
There are a lot of places even inside of rustc which hit this pattern, so this lint feels really desirable to me.
because of match ergonomics, every binding inside of
Someis already matched byrefimplicitly, so the additional explicitrefis completely redundant. Consider the following example wherelandrhave the exact same type.This lint should either suggest to disable match ergonomics by adding
&and&mutpatterns in the relevant places or to remove theref.There are a lot of places even inside of rustc which hit this pattern, so this lint feels really desirable to me.