X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=tests%2Fui%2Fmatch_expr_like_matches_macro.rs;h=2ef6cf42387f6e5b5cd71d788fbabe4f8f7ac01d;hb=39f39d5405b7e55eb08cb927e78686a5ce7377d4;hp=94c7c3cadacf749799ba4a32510e28466e560001;hpb=a02806e00d24f0fcb3e1f285ad9c25ed52ed7c8c;p=rust.git diff --git a/tests/ui/match_expr_like_matches_macro.rs b/tests/ui/match_expr_like_matches_macro.rs index 94c7c3cadac..2ef6cf42387 100644 --- a/tests/ui/match_expr_like_matches_macro.rs +++ b/tests/ui/match_expr_like_matches_macro.rs @@ -119,4 +119,66 @@ enum E { _ => false, }; } + + { + // should print "z" in suggestion (#6503) + let z = &Some(3); + let _z = match &z { + Some(3) => true, + _ => false, + }; + } + + { + // this could also print "z" in suggestion..? + let z = Some(3); + let _z = match &z { + Some(3) => true, + _ => false, + }; + } + + { + enum AnEnum { + X, + Y, + } + + fn foo(_x: AnEnum) {} + + fn main() { + let z = AnEnum::X; + // we can't remove the reference here! + let _ = match &z { + AnEnum::X => true, + _ => false, + }; + foo(z); + } + } + + { + struct S(i32); + + fn fun(_val: Option) {} + let val = Some(S(42)); + // we need the reference here because later val is consumed by fun() + let _res = match &val { + &Some(ref _a) => true, + _ => false, + }; + fun(val); + } + + { + struct S(i32); + + fn fun(_val: Option) {} + let val = Some(S(42)); + let _res = match &val { + &Some(ref _a) => true, + _ => false, + }; + fun(val); + } }