Skip to content

Commit 6fb790a

Browse files
authored
Rollup merge of #113192 - lcnr:add-comment, r=compiler-errors
`assemble_candidates_after_normalizing_self_ty` docs I already explained that in different places a few times, should have added that explanation as a doc comment the first time I did so :3 r? `@BoxyUwU`
2 parents 4dbc7e3 + 0176922 commit 6fb790a

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
@@ -331,11 +331,20 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
331331
candidates
332332
}
333333

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

0 commit comments

Comments
 (0)