@@ -302,7 +302,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
302
302
.iter()
303
303
.filter(|field| {
304
304
let field_ty = field.ty(self.tcx, identity_substs);
305
- Self:: find_param_in_ty(field_ty.into(), param_to_point_at)
305
+ find_param_in_ty(field_ty.into(), param_to_point_at)
306
306
})
307
307
.collect();
308
308
@@ -348,7 +348,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
348
348
.inputs()
349
349
.iter()
350
350
.enumerate()
351
- .filter(|(_, ty)| Self:: find_param_in_ty((**ty).into(), param_to_point_at))
351
+ .filter(|(_, ty)| find_param_in_ty((**ty).into(), param_to_point_at))
352
352
.collect();
353
353
// If there's one field that references the given generic, great!
354
354
if let [(idx, _)] = args_referencing_param.as_slice()
@@ -571,8 +571,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
571
571
// Find out which of `in_ty_elements` refer to `param`.
572
572
// FIXME: It may be better to take the first if there are multiple,
573
573
// just so that the error points to a smaller expression.
574
- let Some((drill_expr, drill_ty)) = Self:: is_iterator_singleton(expr_elements.iter().zip( in_ty_elements.iter()).filter(|(_expr_elem, in_ty_elem)| {
575
- Self:: find_param_in_ty((*in_ty_elem).into(), param)
574
+ let Some((drill_expr, drill_ty)) = is_iterator_singleton(expr_elements.iter().zip( in_ty_elements.iter()).filter(|(_expr_elem, in_ty_elem)| {
575
+ find_param_in_ty((*in_ty_elem).into(), param)
576
576
})) else {
577
577
// The param is not mentioned, or it is mentioned in multiple indexes.
578
578
return Err(expr);
@@ -620,10 +620,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
620
620
// We need to know which of the generic parameters mentions our target param.
621
621
// We expect that at least one of them does, since it is expected to be mentioned.
622
622
let Some((drill_generic_index, generic_argument_type)) =
623
- Self:: is_iterator_singleton(
623
+ is_iterator_singleton(
624
624
in_ty_adt_generic_args.iter().enumerate().filter(
625
625
|(_index, in_ty_generic)| {
626
- Self:: find_param_in_ty(*in_ty_generic, param)
626
+ find_param_in_ty(*in_ty_generic, param)
627
627
},
628
628
),
629
629
) else {
@@ -729,10 +729,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
729
729
// We need to know which of the generic parameters mentions our target param.
730
730
// We expect that at least one of them does, since it is expected to be mentioned.
731
731
let Some((drill_generic_index, generic_argument_type)) =
732
- Self:: is_iterator_singleton(
732
+ is_iterator_singleton(
733
733
in_ty_adt_generic_args.iter().enumerate().filter(
734
734
|(_index, in_ty_generic)| {
735
- Self:: find_param_in_ty(*in_ty_generic, param)
735
+ find_param_in_ty(*in_ty_generic, param)
736
736
},
737
737
),
738
738
) else {
@@ -771,14 +771,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
771
771
// outer contextual information.
772
772
773
773
// (1) Find the (unique) field index which mentions the type in our constraint:
774
- let Some((field_index, field_type)) = Self:: is_iterator_singleton(
774
+ let Some((field_index, field_type)) = is_iterator_singleton(
775
775
in_ty_adt
776
776
.variant_with_id(variant_def_id)
777
777
.fields
778
778
.iter()
779
779
.map(|field| field.ty(self.tcx, *in_ty_adt_generic_args))
780
780
.enumerate()
781
- .filter(|(_index, field_type)| Self:: find_param_in_ty((*field_type).into(), param))
781
+ .filter(|(_index, field_type)| find_param_in_ty((*field_type).into(), param))
782
782
) else {
783
783
return Err(expr);
784
784
};
@@ -811,20 +811,20 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
811
811
812
812
Err(expr)
813
813
}
814
+ }
814
815
815
- // FIXME: This can be made into a private, non-impl function later.
816
- /// Traverses the given ty (either a `ty::Ty` or a `ty::GenericArg`) and searches for references
817
- /// to the given `param_to_point_at`. Returns `true` if it finds any use of the param.
818
- pub fn find_param_in_ty(
819
- ty: ty::GenericArg<'tcx>,
820
- param_to_point_at: ty::GenericArg<'tcx>,
821
- ) -> bool {
822
- let mut walk = ty.walk();
823
- while let Some(arg) = walk.next() {
824
- if arg == param_to_point_at {
825
- return true;
826
- }
827
- if let ty::GenericArgKind::Type(ty) = arg.unpack()
816
+ /// Traverses the given ty (either a `ty::Ty` or a `ty::GenericArg`) and searches for references
817
+ /// to the given `param_to_point_at`. Returns `true` if it finds any use of the param.
818
+ fn find_param_in_ty<'tcx>(
819
+ ty: ty::GenericArg<'tcx>,
820
+ param_to_point_at: ty::GenericArg<'tcx>,
821
+ ) -> bool {
822
+ let mut walk = ty.walk();
823
+ while let Some(arg) = walk.next() {
824
+ if arg == param_to_point_at {
825
+ return true;
826
+ }
827
+ if let ty::GenericArgKind::Type(ty) = arg.unpack()
828
828
&& let ty::Alias(ty::Projection, ..) = ty.kind()
829
829
{
830
830
// This logic may seem a bit strange, but typically when
@@ -835,16 +835,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
835
835
// in some UI tests.
836
836
walk.skip_current_subtree();
837
837
}
838
- }
839
- false
840
838
}
839
+ false
840
+ }
841
841
842
- // FIXME: This can be made into a private, non-impl function later.
843
- /// Returns `Some(iterator.next())` if it has exactly one item, and `None` otherwise.
844
- pub fn is_iterator_singleton<T>(mut iterator: impl Iterator<Item = T>) -> Option<T> {
845
- match (iterator.next(), iterator.next()) {
846
- (_, Some(_)) => None,
847
- (first, _) => first,
848
- }
842
+ /// Returns `Some(iterator.next())` if it has exactly one item, and `None` otherwise.
843
+ fn is_iterator_singleton<T>(mut iterator: impl Iterator<Item = T>) -> Option<T> {
844
+ match (iterator.next(), iterator.next()) {
845
+ (_, Some(_)) => None,
846
+ (first, _) => first,
849
847
}
850
848
}
0 commit comments