Skip to content

Commit d4d1cc4

Browse files
committed
Make helper functions private
1 parent 7281249 commit d4d1cc4

File tree

1 file changed

+30
-32
lines changed

1 file changed

+30
-32
lines changed

compiler/rustc_hir_typeck/src/fn_ctxt/adjust_fulfillment_errors.rs

+30-32
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
302302
.iter()
303303
.filter(|field| {
304304
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)
306306
})
307307
.collect();
308308

@@ -348,7 +348,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
348348
.inputs()
349349
.iter()
350350
.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))
352352
.collect();
353353
// If there's one field that references the given generic, great!
354354
if let [(idx, _)] = args_referencing_param.as_slice()
@@ -571,8 +571,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
571571
// Find out which of `in_ty_elements` refer to `param`.
572572
// FIXME: It may be better to take the first if there are multiple,
573573
// 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)
576576
})) else {
577577
// The param is not mentioned, or it is mentioned in multiple indexes.
578578
return Err(expr);
@@ -620,10 +620,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
620620
// We need to know which of the generic parameters mentions our target param.
621621
// We expect that at least one of them does, since it is expected to be mentioned.
622622
let Some((drill_generic_index, generic_argument_type)) =
623-
Self::is_iterator_singleton(
623+
is_iterator_singleton(
624624
in_ty_adt_generic_args.iter().enumerate().filter(
625625
|(_index, in_ty_generic)| {
626-
Self::find_param_in_ty(*in_ty_generic, param)
626+
find_param_in_ty(*in_ty_generic, param)
627627
},
628628
),
629629
) else {
@@ -729,10 +729,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
729729
// We need to know which of the generic parameters mentions our target param.
730730
// We expect that at least one of them does, since it is expected to be mentioned.
731731
let Some((drill_generic_index, generic_argument_type)) =
732-
Self::is_iterator_singleton(
732+
is_iterator_singleton(
733733
in_ty_adt_generic_args.iter().enumerate().filter(
734734
|(_index, in_ty_generic)| {
735-
Self::find_param_in_ty(*in_ty_generic, param)
735+
find_param_in_ty(*in_ty_generic, param)
736736
},
737737
),
738738
) else {
@@ -771,14 +771,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
771771
// outer contextual information.
772772

773773
// (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(
775775
in_ty_adt
776776
.variant_with_id(variant_def_id)
777777
.fields
778778
.iter()
779779
.map(|field| field.ty(self.tcx, *in_ty_adt_generic_args))
780780
.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))
782782
) else {
783783
return Err(expr);
784784
};
@@ -811,20 +811,20 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
811811

812812
Err(expr)
813813
}
814+
}
814815

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()
828828
&& let ty::Alias(ty::Projection, ..) = ty.kind()
829829
{
830830
// This logic may seem a bit strange, but typically when
@@ -835,16 +835,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
835835
// in some UI tests.
836836
walk.skip_current_subtree();
837837
}
838-
}
839-
false
840838
}
839+
false
840+
}
841841

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,
849847
}
850848
}

0 commit comments

Comments
 (0)