]> git.lizzy.rs Git - rust.git/blobdiff - compiler/rustc_typeck/src/check/pat.rs
Rollup merge of #94023 - krasimirgg:head-llvm-use-llvm-nm, r=Mark-Simulacrum
[rust.git] / compiler / rustc_typeck / src / check / pat.rs
index 320f5a97e0a24960be2bae19bda41f385d7277f1..e034adde1be86e1887ed089e52ef7f6b5f9298da 100644 (file)
@@ -2029,34 +2029,42 @@ fn error_expected_array_or_slice(&self, span: Span, expected_ty: Ty<'tcx>, ti: T
                 err.help("the semantics of slice patterns changed recently; see issue #62254");
             }
         } else if Autoderef::new(&self.infcx, self.param_env, self.body_id, span, expected_ty, span)
-            .any(|(ty, _)| matches!(ty.kind(), ty::Slice(..)))
+            .any(|(ty, _)| matches!(ty.kind(), ty::Slice(..) | ty::Array(..)))
         {
             if let (Some(span), true) = (ti.span, ti.origin_expr) {
                 if let Ok(snippet) = self.tcx.sess.source_map().span_to_snippet(span) {
-                    let applicability = match self.resolve_vars_if_possible(ti.expected).kind() {
-                        ty::Adt(adt_def, _)
-                            if self.tcx.is_diagnostic_item(sym::Option, adt_def.did)
-                                || self.tcx.is_diagnostic_item(sym::Result, adt_def.did) =>
-                        {
-                            // Slicing won't work here, but `.as_deref()` might (issue #91328).
-                            err.span_suggestion(
-                                span,
-                                "consider using `as_deref` here",
-                                format!("{}.as_deref()", snippet),
-                                Applicability::MaybeIncorrect,
-                            );
-                            None
-                        }
-                        // FIXME: instead of checking for Vec only, we could check whether the
-                        // type implements `Deref<Target=X>`; see
-                        // https://github.com/rust-lang/rust/pull/91343#discussion_r761466979
-                        ty::Adt(adt_def, _)
-                            if self.tcx.is_diagnostic_item(sym::Vec, adt_def.did) =>
-                        {
-                            Some(Applicability::MachineApplicable)
+                    let applicability = Autoderef::new(
+                        &self.infcx,
+                        self.param_env,
+                        self.body_id,
+                        span,
+                        self.resolve_vars_if_possible(ti.expected),
+                        span,
+                    )
+                    .find_map(|(ty, _)| {
+                        match ty.kind() {
+                            ty::Adt(adt_def, _)
+                                if self.tcx.is_diagnostic_item(sym::Option, adt_def.did)
+                                    || self.tcx.is_diagnostic_item(sym::Result, adt_def.did) =>
+                            {
+                                // Slicing won't work here, but `.as_deref()` might (issue #91328).
+                                err.span_suggestion(
+                                    span,
+                                    "consider using `as_deref` here",
+                                    format!("{}.as_deref()", snippet),
+                                    Applicability::MaybeIncorrect,
+                                );
+                                Some(None)
+                            }
+
+                            ty::Slice(..) | ty::Array(..) => {
+                                Some(Some(Applicability::MachineApplicable))
+                            }
+
+                            _ => None,
                         }
-                        _ => Some(Applicability::MaybeIncorrect),
-                    };
+                    })
+                    .unwrap_or(Some(Applicability::MaybeIncorrect));
 
                     if let Some(applicability) = applicability {
                         err.span_suggestion(