@@ -402,21 +402,44 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx>+'o {
402402 }
403403
404404 /// Creates the relevant generic argument substitutions
405- /// corresponding to a set of generic parameters.
406- pub fn create_substs_for_generic_args < ' a , ' b , A , P , I > (
405+ /// corresponding to a set of generic parameters. This is a
406+ /// rather complex little function. Let me try to explain the
407+ /// role of each of its parameters:
408+ ///
409+ /// To start, we are given the `def_id` of the thing we are
410+ /// creating the substitutions for, and a partial set of
411+ /// substitutions `parent_substs`. In general, the substitutions
412+ /// for an item begin with substitutions for all the "parents" of
413+ /// that item -- so e.g. for a method it might include the
414+ /// parameters from the impl.
415+ ///
416+ /// Therefore, the method begins by walking down these parents,
417+ /// starting with the outermost parent and proceed inwards until
418+ /// it reaches `def_id`. For each parent P, it will check `parent_substs`
419+ /// first to see if the parent's substitutions are listed in there. If so,
420+ /// we can append those and move on. Otherwise, it invokes the
421+ /// three callback functions:
422+ ///
423+ /// - `args_for_def_id`: given the def-id P, supplies back the
424+ /// generic arguments that were given to that parent from within
425+ /// the path; so e.g. if you have `<T as Foo>::Bar`, the def-id
426+ /// might refer to the trait `Foo`, and the arguments might be
427+ /// `[T]`. The boolean value indicates whether to infer values
428+ /// for arguments whose values were not explicitly provided.
429+ /// - `provided_kind`: given the generic parameter and the value from `args_for_def_id`,
430+ /// instantiate a `Kind`
431+ /// - `inferred_kind`: if no parameter was provided, and inference is enabled, then
432+ /// creates a suitable inference variable.
433+ pub fn create_substs_for_generic_args < ' a , ' b > (
407434 tcx : TyCtxt < ' a , ' gcx , ' tcx > ,
408435 def_id : DefId ,
409436 parent_substs : & [ Kind < ' tcx > ] ,
410437 has_self : bool ,
411438 self_ty : Option < Ty < ' tcx > > ,
412- args_for_def_id : A ,
413- provided_kind : P ,
414- inferred_kind : I ,
415- ) -> & ' tcx Substs < ' tcx > where
416- A : Fn ( DefId ) -> ( Option < & ' b GenericArgs > , bool ) ,
417- P : Fn ( & GenericParamDef , & GenericArg ) -> Kind < ' tcx > ,
418- I : Fn ( Option < & [ Kind < ' tcx > ] > , & GenericParamDef , bool ) -> Kind < ' tcx >
419- {
439+ args_for_def_id : impl Fn ( DefId ) -> ( Option < & ' b GenericArgs > , bool ) ,
440+ provided_kind : impl Fn ( & GenericParamDef , & GenericArg ) -> Kind < ' tcx > ,
441+ inferred_kind : impl Fn ( Option < & [ Kind < ' tcx > ] > , & GenericParamDef , bool ) -> Kind < ' tcx > ,
442+ ) -> & ' tcx Substs < ' tcx > {
420443 // Collect the segments of the path: we need to substitute arguments
421444 // for parameters throughout the entire path (wherever there are
422445 // generic parameters).
0 commit comments