Skip to content

Commit 0176922

Browse files
committed
assemble_candidates_after_normalizing_self_ty docs
1 parent b4591cb commit 0176922

File tree

1 file changed

+13
-4
lines changed
  • compiler/rustc_trait_selection/src/solve/assembly

1 file changed

+13
-4
lines changed

compiler/rustc_trait_selection/src/solve/assembly/mod.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -321,11 +321,20 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
321321
candidates
322322
}
323323

324-
/// If the self type of a goal is an alias, computing the relevant candidates is difficult.
324+
/// If the self type of a goal is an alias we first try to normalize the self type
325+
/// and compute the candidates for the normalized self type in case that succeeds.
325326
///
326-
/// To deal with this, we first try to normalize the self type and add the candidates for the normalized
327-
/// self type to the list of candidates in case that succeeds. We also have to consider candidates with the
328-
/// projection as a self type as well
327+
/// These candidates are used in addition to the ones with the alias as a self type.
328+
/// We do this to simplify both builtin candidates and for better performance.
329+
///
330+
/// We generate the builtin candidates on the fly by looking at the self type, e.g.
331+
/// add `FnPtr` candidates if the self type is a function pointer. Handling builtin
332+
/// candidates while the self type is still an alias seems difficult. This is similar
333+
/// to `try_structurally_resolve_type` during hir typeck (FIXME once implemented).
334+
///
335+
/// Looking at all impls for some trait goal is prohibitively expensive. We therefore
336+
/// only look at implementations with a matching self type. Because of this function,
337+
/// we can avoid looking at all existing impls if the self type is an alias.
329338
#[instrument(level = "debug", skip_all)]
330339
fn assemble_candidates_after_normalizing_self_ty<G: GoalKind<'tcx>>(
331340
&mut self,

0 commit comments

Comments
 (0)