@@ -498,7 +498,7 @@ impl InferenceContext<'_> {
498
498
499
499
// If `expected` is an infer ty, we try to equate it to an array if the given pattern
500
500
// 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 ( ) {
502
502
if let Some ( resolved_array_ty) =
503
503
self . try_resolve_slice_ty_to_array_ty ( prefix, suffix, slice)
504
504
{
@@ -601,42 +601,38 @@ impl InferenceContext<'_> {
601
601
Some ( array_ty)
602
602
}
603
603
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.
605
605
/// This is only possible if we're in an irrefutable pattern. If we were to allow this in refutable
606
606
/// patterns we wouldn't e.g. report ambiguity in the following situation:
607
607
///
608
608
/// ```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];
612
612
///
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] {
615
615
/// &ARR
616
- /// }
617
- /// }
616
+ /// }
617
+ /// }
618
618
///
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
+ /// }
624
624
///
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
+ /// }
630
630
/// ```
631
631
///
632
632
/// 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 } } ) )
640
636
}
641
637
}
642
638
0 commit comments