handle match auto-deref
This commit is contained in:
@@ -865,6 +865,41 @@ mod tests {
|
|||||||
check_no_diagnostic(content);
|
check_no_diagnostic(content);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn enum_ref_missing_arms() {
|
||||||
|
let content = r"
|
||||||
|
enum Either {
|
||||||
|
A,
|
||||||
|
B,
|
||||||
|
}
|
||||||
|
fn test_fn() {
|
||||||
|
match &Either::B {
|
||||||
|
Either::A => {},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
";
|
||||||
|
|
||||||
|
check_diagnostic_with_no_fix(content);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn enum_ref_no_diagnostic() {
|
||||||
|
let content = r"
|
||||||
|
enum Either {
|
||||||
|
A,
|
||||||
|
B,
|
||||||
|
}
|
||||||
|
fn test_fn() {
|
||||||
|
match &Either::B {
|
||||||
|
Either::A => {},
|
||||||
|
Either::B => {},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
";
|
||||||
|
|
||||||
|
check_no_diagnostic(content);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn enum_containing_bool_no_arms() {
|
fn enum_containing_bool_no_arms() {
|
||||||
let content = r"
|
let content = r"
|
||||||
|
|||||||
@@ -93,7 +93,16 @@ impl<'a, 'b> ExprValidator<'a, 'b> {
|
|||||||
// of the match expression. If we had a InvalidMatchArmPattern
|
// of the match expression. If we had a InvalidMatchArmPattern
|
||||||
// diagnostic or similar we could raise that in an else
|
// diagnostic or similar we could raise that in an else
|
||||||
// block here.
|
// block here.
|
||||||
if pat_ty == match_expr_ty {
|
//
|
||||||
|
// When comparing the types, we also have to consider that rustc
|
||||||
|
// will automatically de-reference the match expression type if
|
||||||
|
// necessary.
|
||||||
|
if pat_ty == match_expr_ty
|
||||||
|
|| match_expr_ty
|
||||||
|
.as_reference()
|
||||||
|
.map(|(match_expr_ty, _)| match_expr_ty == pat_ty)
|
||||||
|
.unwrap_or(false)
|
||||||
|
{
|
||||||
// If we had a NotUsefulMatchArm diagnostic, we could
|
// If we had a NotUsefulMatchArm diagnostic, we could
|
||||||
// check the usefulness of each pattern as we added it
|
// check the usefulness of each pattern as we added it
|
||||||
// to the matrix here.
|
// to the matrix here.
|
||||||
|
|||||||
Reference in New Issue
Block a user