Skip to content

Commit 2cfcca6

Browse files
authored
Rollup merge of rust-lang#109550 - Nathan-Fenner:nathanf/fixme-adjust-funcs, r=compiler-errors
Make helper functions private in fn_ctxt/adjust_fulfillment_errors Two helper functions in `rustc_hir_typeck/src/fn_ctxt/adjust_fulfillment_errors.rs` were previously made `pub` impl members, because they were also used in `rustc_hir_typeck/src/fn_ctxt/check.rs` (see rust-lang#107746). However, that's no longer the case, so the FIXME suggesting they be made private can now be implemented.
2 parents 4378369 + d4d1cc4 commit 2cfcca6

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
@@ -310,7 +310,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
310310
.iter()
311311
.filter(|field| {
312312
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)
314314
})
315315
.collect();
316316

@@ -356,7 +356,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
356356
.inputs()
357357
.iter()
358358
.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))
360360
.collect();
361361
// If there's one field that references the given generic, great!
362362
if let [(idx, _)] = args_referencing_param.as_slice()
@@ -579,8 +579,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
579579
// Find out which of `in_ty_elements` refer to `param`.
580580
// FIXME: It may be better to take the first if there are multiple,
581581
// 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)
584584
})) else {
585585
// The param is not mentioned, or it is mentioned in multiple indexes.
586586
return Err(expr);
@@ -628,10 +628,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
628628
// We need to know which of the generic parameters mentions our target param.
629629
// We expect that at least one of them does, since it is expected to be mentioned.
630630
let Some((drill_generic_index, generic_argument_type)) =
631-
Self::is_iterator_singleton(
631+
is_iterator_singleton(
632632
in_ty_adt_generic_args.iter().enumerate().filter(
633633
|(_index, in_ty_generic)| {
634-
Self::find_param_in_ty(*in_ty_generic, param)
634+
find_param_in_ty(*in_ty_generic, param)
635635
},
636636
),
637637
) else {
@@ -751,10 +751,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
751751
// We need to know which of the generic parameters mentions our target param.
752752
// We expect that at least one of them does, since it is expected to be mentioned.
753753
let Some((drill_generic_index, generic_argument_type)) =
754-
Self::is_iterator_singleton(
754+
is_iterator_singleton(
755755
in_ty_adt_generic_args.iter().enumerate().filter(
756756
|(_index, in_ty_generic)| {
757-
Self::find_param_in_ty(*in_ty_generic, param)
757+
find_param_in_ty(*in_ty_generic, param)
758758
},
759759
),
760760
) else {
@@ -793,14 +793,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
793793
// outer contextual information.
794794

795795
// (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(
797797
in_ty_adt
798798
.variant_with_id(variant_def_id)
799799
.fields
800800
.iter()
801801
.map(|field| field.ty(self.tcx, *in_ty_adt_generic_args))
802802
.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))
804804
) else {
805805
return Err(expr);
806806
};
@@ -833,20 +833,20 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
833833

834834
Err(expr)
835835
}
836+
}
836837

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()
850850
&& let ty::Alias(ty::Projection, ..) = ty.kind()
851851
{
852852
// This logic may seem a bit strange, but typically when
@@ -857,16 +857,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
857857
// in some UI tests.
858858
walk.skip_current_subtree();
859859
}
860-
}
861-
false
862860
}
861+
false
862+
}
863863

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,
871869
}
872870
}

0 commit comments

Comments
 (0)