From c34d9e6a92fae416821f45d2b86c261f62aaf4f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Thu, 19 Sep 2019 14:52:38 -0700 Subject: [PATCH] add comments --- src/librustc_typeck/check/mod.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index bc115ec4bfd2c..0406d7a12d243 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -3372,6 +3372,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { vec![self.tcx.types.err; len] } + /// Given a vec of evaluated `FullfillmentError`s and an `fn` call argument expressions, we + /// walk the resolved types for each argument to see if any of the `FullfillmentError`s + /// reference a type argument. If they do, and there's only *one* argument that does, we point + /// at the corresponding argument's expression span instead of the `fn` call path span. fn point_at_arg_instead_of_call_if_possible( &self, errors: &mut Vec>, @@ -3384,9 +3388,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // the `?` operator. for error in errors { if let ty::Predicate::Trait(predicate) = error.obligation.predicate { + // Collect the argument position for all arguments that could have caused this + // `FullfillmentError`. let mut referenced_in = final_arg_types.iter() .flat_map(|(i, ty)| { let ty = self.resolve_vars_if_possible(ty); + // We walk the argument type because the argument's type could have + // been `Option`, but the `FullfillmentError` references `T`. ty.walk() .filter(|&ty| ty == predicate.skip_binder().self_ty()) .map(move |_| *i)