11//! Code shared by trait and projection goals for candidate assembly.
22
3- use crate :: solve:: GoalSource ;
4- use crate :: solve:: { EvalCtxt , SolverMode } ;
53use rustc_hir:: def_id:: DefId ;
4+ use rustc_infer:: infer:: InferCtxt ;
65use rustc_infer:: traits:: query:: NoSolution ;
76use rustc_middle:: bug;
87use rustc_middle:: traits:: solve:: inspect:: ProbeKind ;
@@ -17,6 +16,9 @@ use rustc_middle::ty::{TypeVisitableExt, Upcast};
1716use rustc_span:: { ErrorGuaranteed , DUMMY_SP } ;
1817use std:: fmt:: Debug ;
1918
19+ use crate :: solve:: GoalSource ;
20+ use crate :: solve:: { EvalCtxt , SolverMode } ;
21+
2022pub ( super ) mod structural_traits;
2123
2224/// A candidate is a possible way to prove a goal.
@@ -46,18 +48,18 @@ pub(super) trait GoalKind<'tcx>:
4648 /// work, then produce a response (typically by executing
4749 /// [`EvalCtxt::evaluate_added_goals_and_make_canonical_response`]).
4850 fn probe_and_match_goal_against_assumption (
49- ecx : & mut EvalCtxt < ' _ , ' tcx > ,
51+ ecx : & mut EvalCtxt < ' _ , InferCtxt < ' tcx > > ,
5052 source : CandidateSource < ' tcx > ,
5153 goal : Goal < ' tcx , Self > ,
5254 assumption : ty:: Clause < ' tcx > ,
53- then : impl FnOnce ( & mut EvalCtxt < ' _ , ' tcx > ) -> QueryResult < ' tcx > ,
55+ then : impl FnOnce ( & mut EvalCtxt < ' _ , InferCtxt < ' tcx > > ) -> QueryResult < ' tcx > ,
5456 ) -> Result < Candidate < ' tcx > , NoSolution > ;
5557
5658 /// Consider a clause, which consists of a "assumption" and some "requirements",
5759 /// to satisfy a goal. If the requirements hold, then attempt to satisfy our
5860 /// goal by equating it with the assumption.
5961 fn probe_and_consider_implied_clause (
60- ecx : & mut EvalCtxt < ' _ , ' tcx > ,
62+ ecx : & mut EvalCtxt < ' _ , InferCtxt < ' tcx > > ,
6163 parent_source : CandidateSource < ' tcx > ,
6264 goal : Goal < ' tcx , Self > ,
6365 assumption : ty:: Clause < ' tcx > ,
@@ -75,7 +77,7 @@ pub(super) trait GoalKind<'tcx>:
7577 /// additionally checking all of the supertraits and object bounds to hold,
7678 /// since they're not implied by the well-formedness of the object type.
7779 fn probe_and_consider_object_bound_candidate (
78- ecx : & mut EvalCtxt < ' _ , ' tcx > ,
80+ ecx : & mut EvalCtxt < ' _ , InferCtxt < ' tcx > > ,
7981 source : CandidateSource < ' tcx > ,
8082 goal : Goal < ' tcx , Self > ,
8183 assumption : ty:: Clause < ' tcx > ,
@@ -99,7 +101,7 @@ pub(super) trait GoalKind<'tcx>:
99101 }
100102
101103 fn consider_impl_candidate (
102- ecx : & mut EvalCtxt < ' _ , ' tcx > ,
104+ ecx : & mut EvalCtxt < ' _ , InferCtxt < ' tcx > > ,
103105 goal : Goal < ' tcx , Self > ,
104106 impl_def_id : DefId ,
105107 ) -> Result < Candidate < ' tcx > , NoSolution > ;
@@ -111,7 +113,7 @@ pub(super) trait GoalKind<'tcx>:
111113 /// Trait goals always hold while projection goals never do. This is a bit arbitrary
112114 /// but prevents incorrect normalization while hiding any trait errors.
113115 fn consider_error_guaranteed_candidate (
114- ecx : & mut EvalCtxt < ' _ , ' tcx > ,
116+ ecx : & mut EvalCtxt < ' _ , InferCtxt < ' tcx > > ,
115117 guar : ErrorGuaranteed ,
116118 ) -> Result < Candidate < ' tcx > , NoSolution > ;
117119
@@ -120,13 +122,13 @@ pub(super) trait GoalKind<'tcx>:
120122 /// These components are given by built-in rules from
121123 /// [`structural_traits::instantiate_constituent_tys_for_auto_trait`].
122124 fn consider_auto_trait_candidate (
123- ecx : & mut EvalCtxt < ' _ , ' tcx > ,
125+ ecx : & mut EvalCtxt < ' _ , InferCtxt < ' tcx > > ,
124126 goal : Goal < ' tcx , Self > ,
125127 ) -> Result < Candidate < ' tcx > , NoSolution > ;
126128
127129 /// A trait alias holds if the RHS traits and `where` clauses hold.
128130 fn consider_trait_alias_candidate (
129- ecx : & mut EvalCtxt < ' _ , ' tcx > ,
131+ ecx : & mut EvalCtxt < ' _ , InferCtxt < ' tcx > > ,
130132 goal : Goal < ' tcx , Self > ,
131133 ) -> Result < Candidate < ' tcx > , NoSolution > ;
132134
@@ -135,7 +137,7 @@ pub(super) trait GoalKind<'tcx>:
135137 /// These components are given by built-in rules from
136138 /// [`structural_traits::instantiate_constituent_tys_for_sized_trait`].
137139 fn consider_builtin_sized_candidate (
138- ecx : & mut EvalCtxt < ' _ , ' tcx > ,
140+ ecx : & mut EvalCtxt < ' _ , InferCtxt < ' tcx > > ,
139141 goal : Goal < ' tcx , Self > ,
140142 ) -> Result < Candidate < ' tcx > , NoSolution > ;
141143
@@ -144,35 +146,35 @@ pub(super) trait GoalKind<'tcx>:
144146 /// These components are given by built-in rules from
145147 /// [`structural_traits::instantiate_constituent_tys_for_copy_clone_trait`].
146148 fn consider_builtin_copy_clone_candidate (
147- ecx : & mut EvalCtxt < ' _ , ' tcx > ,
149+ ecx : & mut EvalCtxt < ' _ , InferCtxt < ' tcx > > ,
148150 goal : Goal < ' tcx , Self > ,
149151 ) -> Result < Candidate < ' tcx > , NoSolution > ;
150152
151153 /// A type is `PointerLike` if we can compute its layout, and that layout
152154 /// matches the layout of `usize`.
153155 fn consider_builtin_pointer_like_candidate (
154- ecx : & mut EvalCtxt < ' _ , ' tcx > ,
156+ ecx : & mut EvalCtxt < ' _ , InferCtxt < ' tcx > > ,
155157 goal : Goal < ' tcx , Self > ,
156158 ) -> Result < Candidate < ' tcx > , NoSolution > ;
157159
158160 /// A type is a `FnPtr` if it is of `FnPtr` type.
159161 fn consider_builtin_fn_ptr_trait_candidate (
160- ecx : & mut EvalCtxt < ' _ , ' tcx > ,
162+ ecx : & mut EvalCtxt < ' _ , InferCtxt < ' tcx > > ,
161163 goal : Goal < ' tcx , Self > ,
162164 ) -> Result < Candidate < ' tcx > , NoSolution > ;
163165
164166 /// A callable type (a closure, fn def, or fn ptr) is known to implement the `Fn<A>`
165167 /// family of traits where `A` is given by the signature of the type.
166168 fn consider_builtin_fn_trait_candidates (
167- ecx : & mut EvalCtxt < ' _ , ' tcx > ,
169+ ecx : & mut EvalCtxt < ' _ , InferCtxt < ' tcx > > ,
168170 goal : Goal < ' tcx , Self > ,
169171 kind : ty:: ClosureKind ,
170172 ) -> Result < Candidate < ' tcx > , NoSolution > ;
171173
172174 /// An async closure is known to implement the `AsyncFn<A>` family of traits
173175 /// where `A` is given by the signature of the type.
174176 fn consider_builtin_async_fn_trait_candidates (
175- ecx : & mut EvalCtxt < ' _ , ' tcx > ,
177+ ecx : & mut EvalCtxt < ' _ , InferCtxt < ' tcx > > ,
176178 goal : Goal < ' tcx , Self > ,
177179 kind : ty:: ClosureKind ,
178180 ) -> Result < Candidate < ' tcx > , NoSolution > ;
@@ -181,13 +183,13 @@ pub(super) trait GoalKind<'tcx>:
181183 /// is used internally to delay computation for async closures until after
182184 /// upvar analysis is performed in HIR typeck.
183185 fn consider_builtin_async_fn_kind_helper_candidate (
184- ecx : & mut EvalCtxt < ' _ , ' tcx > ,
186+ ecx : & mut EvalCtxt < ' _ , InferCtxt < ' tcx > > ,
185187 goal : Goal < ' tcx , Self > ,
186188 ) -> Result < Candidate < ' tcx > , NoSolution > ;
187189
188190 /// `Tuple` is implemented if the `Self` type is a tuple.
189191 fn consider_builtin_tuple_candidate (
190- ecx : & mut EvalCtxt < ' _ , ' tcx > ,
192+ ecx : & mut EvalCtxt < ' _ , InferCtxt < ' tcx > > ,
191193 goal : Goal < ' tcx , Self > ,
192194 ) -> Result < Candidate < ' tcx > , NoSolution > ;
193195
@@ -197,63 +199,63 @@ pub(super) trait GoalKind<'tcx>:
197199 /// the built-in types. For structs, the metadata type is given by the struct
198200 /// tail.
199201 fn consider_builtin_pointee_candidate (
200- ecx : & mut EvalCtxt < ' _ , ' tcx > ,
202+ ecx : & mut EvalCtxt < ' _ , InferCtxt < ' tcx > > ,
201203 goal : Goal < ' tcx , Self > ,
202204 ) -> Result < Candidate < ' tcx > , NoSolution > ;
203205
204206 /// A coroutine (that comes from an `async` desugaring) is known to implement
205207 /// `Future<Output = O>`, where `O` is given by the coroutine's return type
206208 /// that was computed during type-checking.
207209 fn consider_builtin_future_candidate (
208- ecx : & mut EvalCtxt < ' _ , ' tcx > ,
210+ ecx : & mut EvalCtxt < ' _ , InferCtxt < ' tcx > > ,
209211 goal : Goal < ' tcx , Self > ,
210212 ) -> Result < Candidate < ' tcx > , NoSolution > ;
211213
212214 /// A coroutine (that comes from a `gen` desugaring) is known to implement
213215 /// `Iterator<Item = O>`, where `O` is given by the generator's yield type
214216 /// that was computed during type-checking.
215217 fn consider_builtin_iterator_candidate (
216- ecx : & mut EvalCtxt < ' _ , ' tcx > ,
218+ ecx : & mut EvalCtxt < ' _ , InferCtxt < ' tcx > > ,
217219 goal : Goal < ' tcx , Self > ,
218220 ) -> Result < Candidate < ' tcx > , NoSolution > ;
219221
220222 /// A coroutine (that comes from a `gen` desugaring) is known to implement
221223 /// `FusedIterator`
222224 fn consider_builtin_fused_iterator_candidate (
223- ecx : & mut EvalCtxt < ' _ , ' tcx > ,
225+ ecx : & mut EvalCtxt < ' _ , InferCtxt < ' tcx > > ,
224226 goal : Goal < ' tcx , Self > ,
225227 ) -> Result < Candidate < ' tcx > , NoSolution > ;
226228
227229 fn consider_builtin_async_iterator_candidate (
228- ecx : & mut EvalCtxt < ' _ , ' tcx > ,
230+ ecx : & mut EvalCtxt < ' _ , InferCtxt < ' tcx > > ,
229231 goal : Goal < ' tcx , Self > ,
230232 ) -> Result < Candidate < ' tcx > , NoSolution > ;
231233
232234 /// A coroutine (that doesn't come from an `async` or `gen` desugaring) is known to
233235 /// implement `Coroutine<R, Yield = Y, Return = O>`, given the resume, yield,
234236 /// and return types of the coroutine computed during type-checking.
235237 fn consider_builtin_coroutine_candidate (
236- ecx : & mut EvalCtxt < ' _ , ' tcx > ,
238+ ecx : & mut EvalCtxt < ' _ , InferCtxt < ' tcx > > ,
237239 goal : Goal < ' tcx , Self > ,
238240 ) -> Result < Candidate < ' tcx > , NoSolution > ;
239241
240242 fn consider_builtin_discriminant_kind_candidate (
241- ecx : & mut EvalCtxt < ' _ , ' tcx > ,
243+ ecx : & mut EvalCtxt < ' _ , InferCtxt < ' tcx > > ,
242244 goal : Goal < ' tcx , Self > ,
243245 ) -> Result < Candidate < ' tcx > , NoSolution > ;
244246
245247 fn consider_builtin_async_destruct_candidate (
246- ecx : & mut EvalCtxt < ' _ , ' tcx > ,
248+ ecx : & mut EvalCtxt < ' _ , InferCtxt < ' tcx > > ,
247249 goal : Goal < ' tcx , Self > ,
248250 ) -> Result < Candidate < ' tcx > , NoSolution > ;
249251
250252 fn consider_builtin_destruct_candidate (
251- ecx : & mut EvalCtxt < ' _ , ' tcx > ,
253+ ecx : & mut EvalCtxt < ' _ , InferCtxt < ' tcx > > ,
252254 goal : Goal < ' tcx , Self > ,
253255 ) -> Result < Candidate < ' tcx > , NoSolution > ;
254256
255257 fn consider_builtin_transmute_candidate (
256- ecx : & mut EvalCtxt < ' _ , ' tcx > ,
258+ ecx : & mut EvalCtxt < ' _ , InferCtxt < ' tcx > > ,
257259 goal : Goal < ' tcx , Self > ,
258260 ) -> Result < Candidate < ' tcx > , NoSolution > ;
259261
@@ -265,12 +267,12 @@ pub(super) trait GoalKind<'tcx>:
265267 /// otherwise recompute this for codegen. This is a bit of a mess but the
266268 /// easiest way to maintain the existing behavior for now.
267269 fn consider_structural_builtin_unsize_candidates (
268- ecx : & mut EvalCtxt < ' _ , ' tcx > ,
270+ ecx : & mut EvalCtxt < ' _ , InferCtxt < ' tcx > > ,
269271 goal : Goal < ' tcx , Self > ,
270272 ) -> Vec < Candidate < ' tcx > > ;
271273}
272274
273- impl < ' tcx > EvalCtxt < ' _ , ' tcx > {
275+ impl < ' tcx > EvalCtxt < ' _ , InferCtxt < ' tcx > > {
274276 pub ( super ) fn assemble_and_evaluate_candidates < G : GoalKind < ' tcx > > (
275277 & mut self ,
276278 goal : Goal < ' tcx , G > ,
0 commit comments