Skip to content

Commit 762bdbf

Browse files
committed
Change signature of point_at_arg_instead_of_call_if_possible
1 parent ecf7299 commit 762bdbf

File tree

1 file changed

+12
-6
lines changed
  • compiler/rustc_typeck/src/check/fn_ctxt

1 file changed

+12
-6
lines changed

compiler/rustc_typeck/src/check/fn_ctxt/checks.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -315,13 +315,15 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
315315

316316
assert_eq!(expected_input_tys.len(), formal_input_tys.len());
317317

318+
let provided_arg_count: usize = provided_args.len();
319+
318320
// Keep track of the fully coerced argument types
319-
let mut final_arg_types: Vec<(usize, Ty<'_>, Ty<'_>)> = vec![];
321+
let mut final_arg_types: Vec<Option<(Ty<'_>, Ty<'_>)>> = vec![None; provided_arg_count];
320322

321323
// We introduce a helper function to demand that a given argument satisfy a given input
322324
// This is more complicated than just checking type equality, as arguments could be coerced
323325
// This version writes those types back so further type checking uses the narrowed types
324-
let demand_compatible = |idx, final_arg_types: &mut Vec<(usize, Ty<'tcx>, Ty<'tcx>)>| {
326+
let demand_compatible = |idx, final_arg_types: &mut Vec<Option<(Ty<'tcx>, Ty<'tcx>)>>| {
325327
let formal_input_ty: Ty<'tcx> = formal_input_tys[idx];
326328
let expected_input_ty: Ty<'tcx> = expected_input_tys[idx];
327329
let provided_arg = &provided_args[idx];
@@ -340,7 +342,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
340342
let coerced_ty = expectation.only_has_type(self).unwrap_or(formal_input_ty);
341343

342344
// Keep track of these for below
343-
final_arg_types.push((idx, checked_ty, coerced_ty));
345+
final_arg_types[idx] = Some((checked_ty, coerced_ty));
344346

345347
// Cause selection errors caused by resolving a single argument to point at the
346348
// argument and not the call. This is otherwise redundant with the `demand_coerce`
@@ -975,7 +977,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
975977
fn point_at_arg_instead_of_call_if_possible(
976978
&self,
977979
errors: &mut Vec<traits::FulfillmentError<'tcx>>,
978-
final_arg_types: &[(usize, Ty<'tcx>, Ty<'tcx>)],
980+
final_arg_types: &[Option<(Ty<'tcx>, Ty<'tcx>)>],
979981
expr: &'tcx hir::Expr<'tcx>,
980982
call_sp: Span,
981983
args: &'tcx [hir::Expr<'tcx>],
@@ -1030,8 +1032,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
10301032
// `FulfillmentError`.
10311033
let mut referenced_in = final_arg_types
10321034
.iter()
1033-
.map(|&(i, checked_ty, _)| (i, checked_ty))
1034-
.chain(final_arg_types.iter().map(|&(i, _, coerced_ty)| (i, coerced_ty)))
1035+
.enumerate()
1036+
.filter_map(|(i, arg)| match arg {
1037+
Some((checked_ty, coerce_ty)) => Some([(i, *checked_ty), (i, *coerce_ty)]),
1038+
_ => None,
1039+
})
1040+
.flatten()
10351041
.flat_map(|(i, ty)| {
10361042
let ty = self.resolve_vars_if_possible(ty);
10371043
// We walk the argument type because the argument's type could have

0 commit comments

Comments
 (0)