From 3088ca0a53540e0d7ae14f0d18efcad16cad0735 Mon Sep 17 00:00:00 2001 From: Dawer <7803845+iDawer@users.noreply.github.com> Date: Wed, 19 May 2021 18:08:13 +0500 Subject: Take substitutions into account. --- crates/hir_ty/src/diagnostics/match_check.rs | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'crates/hir_ty/src/diagnostics/match_check.rs') diff --git a/crates/hir_ty/src/diagnostics/match_check.rs b/crates/hir_ty/src/diagnostics/match_check.rs index 5fb98ff35..992bb8682 100644 --- a/crates/hir_ty/src/diagnostics/match_check.rs +++ b/crates/hir_ty/src/diagnostics/match_check.rs @@ -39,8 +39,8 @@ pub(crate) struct Pat { } impl Pat { - pub(crate) fn wildcard_from_ty(ty: &Ty) -> Self { - Pat { ty: ty.clone(), kind: Box::new(PatKind::Wild) } + pub(crate) fn wildcard_from_ty(ty: Ty) -> Self { + Pat { ty, kind: Box::new(PatKind::Wild) } } } @@ -1145,6 +1145,22 @@ fn main() { ); } + #[test] + fn pattern_type_is_of_substitution() { + cov_mark::check!(match_check_wildcard_expanded_to_substitutions); + check_diagnostics( + r#" +struct Foo(T); +struct Bar; +fn main() { + match Foo(Bar) { + _ | Foo(Bar) => {} + } +} +"#, + ); + } + mod false_negatives { //! The implementation of match checking here is a work in progress. As we roll this out, we //! prefer false negatives to false positives (ideally there would be no false positives). This -- cgit v1.2.3