|
1 | 1 | //! Code shared by trait and projection goals for candidate assembly.
|
2 | 2 |
|
3 | 3 | use super::infcx_ext::InferCtxtExt;
|
| 4 | +#[cfg(doc)] |
| 5 | +use super::trait_goals::structural_traits::*; |
4 | 6 | use super::{CanonicalResponse, Certainty, EvalCtxt, Goal, QueryResult};
|
5 | 7 | use rustc_hir::def_id::DefId;
|
6 | 8 | use rustc_infer::traits::query::NoSolution;
|
@@ -98,52 +100,75 @@ pub(super) trait GoalKind<'tcx>: TypeFoldable<'tcx> + Copy + Eq {
|
98 | 100 | assumption: ty::Predicate<'tcx>,
|
99 | 101 | ) -> QueryResult<'tcx>;
|
100 | 102 |
|
| 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`]. |
101 | 105 | fn consider_auto_trait_candidate(
|
102 | 106 | ecx: &mut EvalCtxt<'_, 'tcx>,
|
103 | 107 | goal: Goal<'tcx, Self>,
|
104 | 108 | ) -> QueryResult<'tcx>;
|
105 | 109 |
|
| 110 | + // A trait alias holds if the RHS traits and `where` clauses hold. |
106 | 111 | fn consider_trait_alias_candidate(
|
107 | 112 | ecx: &mut EvalCtxt<'_, 'tcx>,
|
108 | 113 | goal: Goal<'tcx, Self>,
|
109 | 114 | ) -> QueryResult<'tcx>;
|
110 | 115 |
|
| 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`]. |
111 | 118 | fn consider_builtin_sized_candidate(
|
112 | 119 | ecx: &mut EvalCtxt<'_, 'tcx>,
|
113 | 120 | goal: Goal<'tcx, Self>,
|
114 | 121 | ) -> QueryResult<'tcx>;
|
115 | 122 |
|
| 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`]. |
116 | 125 | fn consider_builtin_copy_clone_candidate(
|
117 | 126 | ecx: &mut EvalCtxt<'_, 'tcx>,
|
118 | 127 | goal: Goal<'tcx, Self>,
|
119 | 128 | ) -> QueryResult<'tcx>;
|
120 | 129 |
|
| 130 | + // A type is `PointerSized` if we can compute its layout, and that layout |
| 131 | + // matches the layout of `usize`. |
121 | 132 | fn consider_builtin_pointer_sized_candidate(
|
122 | 133 | ecx: &mut EvalCtxt<'_, 'tcx>,
|
123 | 134 | goal: Goal<'tcx, Self>,
|
124 | 135 | ) -> QueryResult<'tcx>;
|
125 | 136 |
|
| 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. |
126 | 139 | fn consider_builtin_fn_trait_candidates(
|
127 | 140 | ecx: &mut EvalCtxt<'_, 'tcx>,
|
128 | 141 | goal: Goal<'tcx, Self>,
|
129 | 142 | kind: ty::ClosureKind,
|
130 | 143 | ) -> QueryResult<'tcx>;
|
131 | 144 |
|
| 145 | + // `Tuple` is implemented if the `Self` type is a tuple. |
132 | 146 | fn consider_builtin_tuple_candidate(
|
133 | 147 | ecx: &mut EvalCtxt<'_, 'tcx>,
|
134 | 148 | goal: Goal<'tcx, Self>,
|
135 | 149 | ) -> QueryResult<'tcx>;
|
136 | 150 |
|
| 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. |
137 | 156 | fn consider_builtin_pointee_candidate(
|
138 | 157 | ecx: &mut EvalCtxt<'_, 'tcx>,
|
139 | 158 | goal: Goal<'tcx, Self>,
|
140 | 159 | ) -> QueryResult<'tcx>;
|
141 | 160 |
|
| 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. |
142 | 164 | fn consider_builtin_future_candidate(
|
143 | 165 | ecx: &mut EvalCtxt<'_, 'tcx>,
|
144 | 166 | goal: Goal<'tcx, Self>,
|
145 | 167 | ) -> QueryResult<'tcx>;
|
146 | 168 |
|
| 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. |
147 | 172 | fn consider_builtin_generator_candidate(
|
148 | 173 | ecx: &mut EvalCtxt<'_, 'tcx>,
|
149 | 174 | goal: Goal<'tcx, Self>,
|
|
0 commit comments