Skip to content

Commit 0654374

Browse files
Add some comments
1 parent ff2413d commit 0654374

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

compiler/rustc_trait_selection/src/solve/assembly.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
//! Code shared by trait and projection goals for candidate assembly.
22
33
use super::infcx_ext::InferCtxtExt;
4+
#[cfg(doc)]
5+
use super::trait_goals::structural_traits::*;
46
use super::{CanonicalResponse, Certainty, EvalCtxt, Goal, QueryResult};
57
use rustc_hir::def_id::DefId;
68
use rustc_infer::traits::query::NoSolution;
@@ -98,52 +100,75 @@ pub(super) trait GoalKind<'tcx>: TypeFoldable<'tcx> + Copy + Eq {
98100
assumption: ty::Predicate<'tcx>,
99101
) -> QueryResult<'tcx>;
100102

103+
// A type implements an `auto trait` if its components do as well. These components
104+
// are given by built-in rules from [`instantiate_constituent_tys_for_auto_trait`].
101105
fn consider_auto_trait_candidate(
102106
ecx: &mut EvalCtxt<'_, 'tcx>,
103107
goal: Goal<'tcx, Self>,
104108
) -> QueryResult<'tcx>;
105109

110+
// A trait alias holds if the RHS traits and `where` clauses hold.
106111
fn consider_trait_alias_candidate(
107112
ecx: &mut EvalCtxt<'_, 'tcx>,
108113
goal: Goal<'tcx, Self>,
109114
) -> QueryResult<'tcx>;
110115

116+
// A type is `Copy` or `Clone` if its components are `Sized`. These components
117+
// are given by built-in rules from [`instantiate_constituent_tys_for_sized_trait`].
111118
fn consider_builtin_sized_candidate(
112119
ecx: &mut EvalCtxt<'_, 'tcx>,
113120
goal: Goal<'tcx, Self>,
114121
) -> QueryResult<'tcx>;
115122

123+
// A type is `Copy` or `Clone` if its components are `Copy` or `Clone`. These
124+
// components are given by built-in rules from [`instantiate_constituent_tys_for_copy_clone_trait`].
116125
fn consider_builtin_copy_clone_candidate(
117126
ecx: &mut EvalCtxt<'_, 'tcx>,
118127
goal: Goal<'tcx, Self>,
119128
) -> QueryResult<'tcx>;
120129

130+
// A type is `PointerSized` if we can compute its layout, and that layout
131+
// matches the layout of `usize`.
121132
fn consider_builtin_pointer_sized_candidate(
122133
ecx: &mut EvalCtxt<'_, 'tcx>,
123134
goal: Goal<'tcx, Self>,
124135
) -> QueryResult<'tcx>;
125136

137+
// A callable type (a closure, fn def, or fn ptr) is known to implement the `Fn<A>`
138+
// family of traits where `A` is given by the signature of the type.
126139
fn consider_builtin_fn_trait_candidates(
127140
ecx: &mut EvalCtxt<'_, 'tcx>,
128141
goal: Goal<'tcx, Self>,
129142
kind: ty::ClosureKind,
130143
) -> QueryResult<'tcx>;
131144

145+
// `Tuple` is implemented if the `Self` type is a tuple.
132146
fn consider_builtin_tuple_candidate(
133147
ecx: &mut EvalCtxt<'_, 'tcx>,
134148
goal: Goal<'tcx, Self>,
135149
) -> QueryResult<'tcx>;
136150

151+
// `Pointee` is always implemented.
152+
//
153+
// See the projection implementation for the `Metadata` types for all of
154+
// the built-in types. For structs, the metadata type is given by the struct
155+
// tail.
137156
fn consider_builtin_pointee_candidate(
138157
ecx: &mut EvalCtxt<'_, 'tcx>,
139158
goal: Goal<'tcx, Self>,
140159
) -> QueryResult<'tcx>;
141160

161+
// A generator (that comes from an `async` desugaring) is known to implement
162+
// `Future<Output = O>`, where `O` is given by the generator's return type
163+
// that was computed during type-checking.
142164
fn consider_builtin_future_candidate(
143165
ecx: &mut EvalCtxt<'_, 'tcx>,
144166
goal: Goal<'tcx, Self>,
145167
) -> QueryResult<'tcx>;
146168

169+
// A generator (that doesn't come from an `async` desugaring) is known to
170+
// implement `Generator<R, Yield = Y, Return = O>`, given the resume, yield,
171+
// and return types of the generator computed during type-checking.
147172
fn consider_builtin_generator_candidate(
148173
ecx: &mut EvalCtxt<'_, 'tcx>,
149174
goal: Goal<'tcx, Self>,

compiler/rustc_trait_selection/src/solve/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,8 @@ impl<'a, 'tcx> EvalCtxt<'a, 'tcx> {
390390
}
391391

392392
impl<'tcx> EvalCtxt<'_, 'tcx> {
393+
// Recursively evaluates a list of goals to completion, returning the certainty
394+
// of all of the goals.
393395
fn evaluate_all(
394396
&mut self,
395397
mut goals: Vec<Goal<'tcx, ty::Predicate<'tcx>>>,
@@ -426,6 +428,10 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
426428
})
427429
}
428430

431+
// Recursively evaluates a list of goals to completion, making a query response.
432+
//
433+
// This is just a convenient way of calling [`EvalCtxt::evaluate_all`],
434+
// then [`EvalCtxt::make_canonical_response`].
429435
fn evaluate_all_and_make_canonical_response(
430436
&mut self,
431437
goals: Vec<Goal<'tcx, ty::Predicate<'tcx>>>,

0 commit comments

Comments
 (0)