@@ -498,7 +498,7 @@ impl InferenceContext<'_> {
498498
499499 // If `expected` is an infer ty, we try to equate it to an array if the given pattern
500500 // allows it. See issue #16609
501- if self . decl_allows_array_type_infer ( decl) && expected. is_ty_var ( ) {
501+ if self . pat_is_irrefutable ( decl) && expected. is_ty_var ( ) {
502502 if let Some ( resolved_array_ty) =
503503 self . try_resolve_slice_ty_to_array_ty ( prefix, suffix, slice)
504504 {
@@ -601,42 +601,38 @@ impl InferenceContext<'_> {
601601 Some ( array_ty)
602602 }
603603
604- /// Determines whether we can infer the expected type in the slice pattern to be of type array.
604+ /// Used to determine whether we can infer the expected type in the slice pattern to be of type array.
605605 /// This is only possible if we're in an irrefutable pattern. If we were to allow this in refutable
606606 /// patterns we wouldn't e.g. report ambiguity in the following situation:
607607 ///
608608 /// ```ignore(rust)
609- /// struct Zeroes;
610- /// const ARR: [usize; 2] = [0; 2];
611- /// const ARR2: [usize; 2] = [2; 2];
609+ /// struct Zeroes;
610+ /// const ARR: [usize; 2] = [0; 2];
611+ /// const ARR2: [usize; 2] = [2; 2];
612612 ///
613- /// impl Into<&'static [usize; 2]> for Zeroes {
614- /// fn into(self) -> &'static [usize; 2] {
613+ /// impl Into<&'static [usize; 2]> for Zeroes {
614+ /// fn into(self) -> &'static [usize; 2] {
615615 /// &ARR
616- /// }
617- /// }
616+ /// }
617+ /// }
618618 ///
619- /// impl Into<&'static [usize]> for Zeroes {
620- /// fn into(self) -> &'static [usize] {
621- /// &ARR2
622- /// }
623- /// }
619+ /// impl Into<&'static [usize]> for Zeroes {
620+ /// fn into(self) -> &'static [usize] {
621+ /// &ARR2
622+ /// }
623+ /// }
624624 ///
625- /// fn main() {
626- /// let &[a, b]: &[usize] = Zeroes.into() else {
627- /// ..
628- /// };
629- /// }
625+ /// fn main() {
626+ /// let &[a, b]: &[usize] = Zeroes.into() else {
627+ /// ..
628+ /// };
629+ /// }
630630 /// ```
631631 ///
632632 /// If we're in an irrefutable pattern we prefer the array impl candidate given that
633- /// the slice impl candidate would be be rejected anyway (if no ambiguity existed).
634- fn decl_allows_array_type_infer ( & self , decl_ctxt : Option < DeclContext > ) -> bool {
635- if let Some ( decl_ctxt) = decl_ctxt {
636- !decl_ctxt. has_else && matches ! ( decl_ctxt. origin, DeclOrigin :: LocalDecl )
637- } else {
638- false
639- }
633+ /// the slice impl candidate would be rejected anyway (if no ambiguity existed).
634+ fn pat_is_irrefutable ( & self , decl_ctxt : Option < DeclContext > ) -> bool {
635+ matches ! ( decl_ctxt, Some ( DeclContext { origin: DeclOrigin :: LocalDecl { has_else: false } } ) )
640636 }
641637}
642638
0 commit comments