pub fn create_substs_for_generic_args<'tcx, 'a>(
tcx: TyCtxt<'tcx>,
def_id: DefId,
parent_substs: &[GenericArg<'tcx>],
has_self: bool,
self_ty: Option<Ty<'tcx>>,
arg_count: &GenericArgCountResult,
ctx: &mut impl CreateSubstsForGenericArgsCtxt<'a, 'tcx>
) -> SubstsRef<'tcx>Expand description
Creates the relevant generic argument substitutions corresponding to a set of generic parameters. This is a rather complex function. Let us try to explain the role of each of its parameters:
To start, we are given the def_id of the thing we are
creating the substitutions for, and a partial set of
substitutions parent_substs. In general, the substitutions
for an item begin with substitutions for all the “parents” of
that item – e.g., for a method it might include the
parameters from the impl.
Therefore, the method begins by walking down these parents,
starting with the outermost parent and proceed inwards until
it reaches def_id. For each parent P, it will check parent_substs
first to see if the parent’s substitutions are listed in there. If so,
we can append those and move on. Otherwise, it invokes the
three callback functions:
args_for_def_id: given theDefIdP, supplies back the generic arguments that were given to that parent from within the path; so e.g., if you have<T as Foo>::Bar, theDefIdmight refer to the traitFoo, and the arguments might be[T]. The boolean value indicates whether to infer values for arguments whose values were not explicitly provided.provided_kind: given the generic parameter and the value fromargs_for_def_id, instantiate aGenericArg.inferred_kind: if no parameter was provided, and inference is enabled, then creates a suitable inference variable.