@@ -310,7 +310,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
310
310
. iter ( )
311
311
. filter ( |field| {
312
312
let field_ty = field. ty ( self . tcx , identity_substs) ;
313
- Self :: find_param_in_ty ( field_ty. into ( ) , param_to_point_at)
313
+ find_param_in_ty ( field_ty. into ( ) , param_to_point_at)
314
314
} )
315
315
. collect ( ) ;
316
316
@@ -356,7 +356,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
356
356
. inputs ( )
357
357
. iter ( )
358
358
. enumerate ( )
359
- . filter ( |( _, ty) | Self :: find_param_in_ty ( ( * * ty) . into ( ) , param_to_point_at) )
359
+ . filter ( |( _, ty) | find_param_in_ty ( ( * * ty) . into ( ) , param_to_point_at) )
360
360
. collect ( ) ;
361
361
// If there's one field that references the given generic, great!
362
362
if let [ ( idx, _) ] = args_referencing_param. as_slice ( )
@@ -579,8 +579,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
579
579
// Find out which of `in_ty_elements` refer to `param`.
580
580
// FIXME: It may be better to take the first if there are multiple,
581
581
// just so that the error points to a smaller expression.
582
- let Some ( ( drill_expr, drill_ty) ) = Self :: is_iterator_singleton ( expr_elements. iter ( ) . zip ( in_ty_elements. iter ( ) ) . filter ( |( _expr_elem, in_ty_elem) | {
583
- Self :: find_param_in_ty ( ( * in_ty_elem) . into ( ) , param)
582
+ let Some ( ( drill_expr, drill_ty) ) = is_iterator_singleton ( expr_elements. iter ( ) . zip ( in_ty_elements. iter ( ) ) . filter ( |( _expr_elem, in_ty_elem) | {
583
+ find_param_in_ty ( ( * in_ty_elem) . into ( ) , param)
584
584
} ) ) else {
585
585
// The param is not mentioned, or it is mentioned in multiple indexes.
586
586
return Err ( expr) ;
@@ -628,10 +628,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
628
628
// We need to know which of the generic parameters mentions our target param.
629
629
// We expect that at least one of them does, since it is expected to be mentioned.
630
630
let Some ( ( drill_generic_index, generic_argument_type) ) =
631
- Self :: is_iterator_singleton (
631
+ is_iterator_singleton (
632
632
in_ty_adt_generic_args. iter ( ) . enumerate ( ) . filter (
633
633
|( _index, in_ty_generic) | {
634
- Self :: find_param_in_ty ( * in_ty_generic, param)
634
+ find_param_in_ty ( * in_ty_generic, param)
635
635
} ,
636
636
) ,
637
637
) else {
@@ -751,10 +751,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
751
751
// We need to know which of the generic parameters mentions our target param.
752
752
// We expect that at least one of them does, since it is expected to be mentioned.
753
753
let Some ( ( drill_generic_index, generic_argument_type) ) =
754
- Self :: is_iterator_singleton (
754
+ is_iterator_singleton (
755
755
in_ty_adt_generic_args. iter ( ) . enumerate ( ) . filter (
756
756
|( _index, in_ty_generic) | {
757
- Self :: find_param_in_ty ( * in_ty_generic, param)
757
+ find_param_in_ty ( * in_ty_generic, param)
758
758
} ,
759
759
) ,
760
760
) else {
@@ -793,14 +793,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
793
793
// outer contextual information.
794
794
795
795
// (1) Find the (unique) field index which mentions the type in our constraint:
796
- let Some ( ( field_index, field_type) ) = Self :: is_iterator_singleton (
796
+ let Some ( ( field_index, field_type) ) = is_iterator_singleton (
797
797
in_ty_adt
798
798
. variant_with_id ( variant_def_id)
799
799
. fields
800
800
. iter ( )
801
801
. map ( |field| field. ty ( self . tcx , * in_ty_adt_generic_args) )
802
802
. enumerate ( )
803
- . filter ( |( _index, field_type) | Self :: find_param_in_ty ( ( * field_type) . into ( ) , param) )
803
+ . filter ( |( _index, field_type) | find_param_in_ty ( ( * field_type) . into ( ) , param) )
804
804
) else {
805
805
return Err ( expr) ;
806
806
} ;
@@ -833,20 +833,20 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
833
833
834
834
Err ( expr)
835
835
}
836
+ }
836
837
837
- // FIXME: This can be made into a private, non-impl function later.
838
- /// Traverses the given ty (either a `ty::Ty` or a `ty::GenericArg`) and searches for references
839
- /// to the given `param_to_point_at`. Returns `true` if it finds any use of the param.
840
- pub fn find_param_in_ty (
841
- ty : ty:: GenericArg < ' tcx > ,
842
- param_to_point_at : ty:: GenericArg < ' tcx > ,
843
- ) -> bool {
844
- let mut walk = ty. walk ( ) ;
845
- while let Some ( arg) = walk. next ( ) {
846
- if arg == param_to_point_at {
847
- return true ;
848
- }
849
- if let ty:: GenericArgKind :: Type ( ty) = arg. unpack ( )
838
+ /// Traverses the given ty (either a `ty::Ty` or a `ty::GenericArg`) and searches for references
839
+ /// to the given `param_to_point_at`. Returns `true` if it finds any use of the param.
840
+ fn find_param_in_ty < ' tcx > (
841
+ ty : ty:: GenericArg < ' tcx > ,
842
+ param_to_point_at : ty:: GenericArg < ' tcx > ,
843
+ ) -> bool {
844
+ let mut walk = ty. walk ( ) ;
845
+ while let Some ( arg) = walk. next ( ) {
846
+ if arg == param_to_point_at {
847
+ return true ;
848
+ }
849
+ if let ty:: GenericArgKind :: Type ( ty) = arg. unpack ( )
850
850
&& let ty:: Alias ( ty:: Projection , ..) = ty. kind ( )
851
851
{
852
852
// This logic may seem a bit strange, but typically when
@@ -857,16 +857,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
857
857
// in some UI tests.
858
858
walk. skip_current_subtree ( ) ;
859
859
}
860
- }
861
- false
862
860
}
861
+ false
862
+ }
863
863
864
- // FIXME: This can be made into a private, non-impl function later.
865
- /// Returns `Some(iterator.next())` if it has exactly one item, and `None` otherwise.
866
- pub fn is_iterator_singleton < T > ( mut iterator : impl Iterator < Item = T > ) -> Option < T > {
867
- match ( iterator. next ( ) , iterator. next ( ) ) {
868
- ( _, Some ( _) ) => None ,
869
- ( first, _) => first,
870
- }
864
+ /// Returns `Some(iterator.next())` if it has exactly one item, and `None` otherwise.
865
+ fn is_iterator_singleton < T > ( mut iterator : impl Iterator < Item = T > ) -> Option < T > {
866
+ match ( iterator. next ( ) , iterator. next ( ) ) {
867
+ ( _, Some ( _) ) => None ,
868
+ ( first, _) => first,
871
869
}
872
870
}
0 commit comments