1
1
//! Code shared by trait and projection goals for candidate assembly.
2
2
3
- use crate :: solve:: GoalSource ;
4
- use crate :: solve:: { EvalCtxt , SolverMode } ;
5
3
use rustc_hir:: def_id:: DefId ;
4
+ use rustc_infer:: infer:: InferCtxt ;
6
5
use rustc_infer:: traits:: query:: NoSolution ;
7
6
use rustc_middle:: bug;
8
7
use rustc_middle:: traits:: solve:: inspect:: ProbeKind ;
@@ -17,6 +16,9 @@ use rustc_middle::ty::{TypeVisitableExt, Upcast};
17
16
use rustc_span:: { ErrorGuaranteed , DUMMY_SP } ;
18
17
use std:: fmt:: Debug ;
19
18
19
+ use crate :: solve:: GoalSource ;
20
+ use crate :: solve:: { EvalCtxt , SolverMode } ;
21
+
20
22
pub ( super ) mod structural_traits;
21
23
22
24
/// A candidate is a possible way to prove a goal.
@@ -46,18 +48,18 @@ pub(super) trait GoalKind<'tcx>:
46
48
/// work, then produce a response (typically by executing
47
49
/// [`EvalCtxt::evaluate_added_goals_and_make_canonical_response`]).
48
50
fn probe_and_match_goal_against_assumption (
49
- ecx : & mut EvalCtxt < ' _ , ' tcx > ,
51
+ ecx : & mut EvalCtxt < ' _ , InferCtxt < ' tcx > > ,
50
52
source : CandidateSource < ' tcx > ,
51
53
goal : Goal < ' tcx , Self > ,
52
54
assumption : ty:: Clause < ' tcx > ,
53
- then : impl FnOnce ( & mut EvalCtxt < ' _ , ' tcx > ) -> QueryResult < ' tcx > ,
55
+ then : impl FnOnce ( & mut EvalCtxt < ' _ , InferCtxt < ' tcx > > ) -> QueryResult < ' tcx > ,
54
56
) -> Result < Candidate < ' tcx > , NoSolution > ;
55
57
56
58
/// Consider a clause, which consists of a "assumption" and some "requirements",
57
59
/// to satisfy a goal. If the requirements hold, then attempt to satisfy our
58
60
/// goal by equating it with the assumption.
59
61
fn probe_and_consider_implied_clause (
60
- ecx : & mut EvalCtxt < ' _ , ' tcx > ,
62
+ ecx : & mut EvalCtxt < ' _ , InferCtxt < ' tcx > > ,
61
63
parent_source : CandidateSource < ' tcx > ,
62
64
goal : Goal < ' tcx , Self > ,
63
65
assumption : ty:: Clause < ' tcx > ,
@@ -75,7 +77,7 @@ pub(super) trait GoalKind<'tcx>:
75
77
/// additionally checking all of the supertraits and object bounds to hold,
76
78
/// since they're not implied by the well-formedness of the object type.
77
79
fn probe_and_consider_object_bound_candidate (
78
- ecx : & mut EvalCtxt < ' _ , ' tcx > ,
80
+ ecx : & mut EvalCtxt < ' _ , InferCtxt < ' tcx > > ,
79
81
source : CandidateSource < ' tcx > ,
80
82
goal : Goal < ' tcx , Self > ,
81
83
assumption : ty:: Clause < ' tcx > ,
@@ -99,7 +101,7 @@ pub(super) trait GoalKind<'tcx>:
99
101
}
100
102
101
103
fn consider_impl_candidate (
102
- ecx : & mut EvalCtxt < ' _ , ' tcx > ,
104
+ ecx : & mut EvalCtxt < ' _ , InferCtxt < ' tcx > > ,
103
105
goal : Goal < ' tcx , Self > ,
104
106
impl_def_id : DefId ,
105
107
) -> Result < Candidate < ' tcx > , NoSolution > ;
@@ -111,7 +113,7 @@ pub(super) trait GoalKind<'tcx>:
111
113
/// Trait goals always hold while projection goals never do. This is a bit arbitrary
112
114
/// but prevents incorrect normalization while hiding any trait errors.
113
115
fn consider_error_guaranteed_candidate (
114
- ecx : & mut EvalCtxt < ' _ , ' tcx > ,
116
+ ecx : & mut EvalCtxt < ' _ , InferCtxt < ' tcx > > ,
115
117
guar : ErrorGuaranteed ,
116
118
) -> Result < Candidate < ' tcx > , NoSolution > ;
117
119
@@ -120,13 +122,13 @@ pub(super) trait GoalKind<'tcx>:
120
122
/// These components are given by built-in rules from
121
123
/// [`structural_traits::instantiate_constituent_tys_for_auto_trait`].
122
124
fn consider_auto_trait_candidate (
123
- ecx : & mut EvalCtxt < ' _ , ' tcx > ,
125
+ ecx : & mut EvalCtxt < ' _ , InferCtxt < ' tcx > > ,
124
126
goal : Goal < ' tcx , Self > ,
125
127
) -> Result < Candidate < ' tcx > , NoSolution > ;
126
128
127
129
/// A trait alias holds if the RHS traits and `where` clauses hold.
128
130
fn consider_trait_alias_candidate (
129
- ecx : & mut EvalCtxt < ' _ , ' tcx > ,
131
+ ecx : & mut EvalCtxt < ' _ , InferCtxt < ' tcx > > ,
130
132
goal : Goal < ' tcx , Self > ,
131
133
) -> Result < Candidate < ' tcx > , NoSolution > ;
132
134
@@ -135,7 +137,7 @@ pub(super) trait GoalKind<'tcx>:
135
137
/// These components are given by built-in rules from
136
138
/// [`structural_traits::instantiate_constituent_tys_for_sized_trait`].
137
139
fn consider_builtin_sized_candidate (
138
- ecx : & mut EvalCtxt < ' _ , ' tcx > ,
140
+ ecx : & mut EvalCtxt < ' _ , InferCtxt < ' tcx > > ,
139
141
goal : Goal < ' tcx , Self > ,
140
142
) -> Result < Candidate < ' tcx > , NoSolution > ;
141
143
@@ -144,35 +146,35 @@ pub(super) trait GoalKind<'tcx>:
144
146
/// These components are given by built-in rules from
145
147
/// [`structural_traits::instantiate_constituent_tys_for_copy_clone_trait`].
146
148
fn consider_builtin_copy_clone_candidate (
147
- ecx : & mut EvalCtxt < ' _ , ' tcx > ,
149
+ ecx : & mut EvalCtxt < ' _ , InferCtxt < ' tcx > > ,
148
150
goal : Goal < ' tcx , Self > ,
149
151
) -> Result < Candidate < ' tcx > , NoSolution > ;
150
152
151
153
/// A type is `PointerLike` if we can compute its layout, and that layout
152
154
/// matches the layout of `usize`.
153
155
fn consider_builtin_pointer_like_candidate (
154
- ecx : & mut EvalCtxt < ' _ , ' tcx > ,
156
+ ecx : & mut EvalCtxt < ' _ , InferCtxt < ' tcx > > ,
155
157
goal : Goal < ' tcx , Self > ,
156
158
) -> Result < Candidate < ' tcx > , NoSolution > ;
157
159
158
160
/// A type is a `FnPtr` if it is of `FnPtr` type.
159
161
fn consider_builtin_fn_ptr_trait_candidate (
160
- ecx : & mut EvalCtxt < ' _ , ' tcx > ,
162
+ ecx : & mut EvalCtxt < ' _ , InferCtxt < ' tcx > > ,
161
163
goal : Goal < ' tcx , Self > ,
162
164
) -> Result < Candidate < ' tcx > , NoSolution > ;
163
165
164
166
/// A callable type (a closure, fn def, or fn ptr) is known to implement the `Fn<A>`
165
167
/// family of traits where `A` is given by the signature of the type.
166
168
fn consider_builtin_fn_trait_candidates (
167
- ecx : & mut EvalCtxt < ' _ , ' tcx > ,
169
+ ecx : & mut EvalCtxt < ' _ , InferCtxt < ' tcx > > ,
168
170
goal : Goal < ' tcx , Self > ,
169
171
kind : ty:: ClosureKind ,
170
172
) -> Result < Candidate < ' tcx > , NoSolution > ;
171
173
172
174
/// An async closure is known to implement the `AsyncFn<A>` family of traits
173
175
/// where `A` is given by the signature of the type.
174
176
fn consider_builtin_async_fn_trait_candidates (
175
- ecx : & mut EvalCtxt < ' _ , ' tcx > ,
177
+ ecx : & mut EvalCtxt < ' _ , InferCtxt < ' tcx > > ,
176
178
goal : Goal < ' tcx , Self > ,
177
179
kind : ty:: ClosureKind ,
178
180
) -> Result < Candidate < ' tcx > , NoSolution > ;
@@ -181,13 +183,13 @@ pub(super) trait GoalKind<'tcx>:
181
183
/// is used internally to delay computation for async closures until after
182
184
/// upvar analysis is performed in HIR typeck.
183
185
fn consider_builtin_async_fn_kind_helper_candidate (
184
- ecx : & mut EvalCtxt < ' _ , ' tcx > ,
186
+ ecx : & mut EvalCtxt < ' _ , InferCtxt < ' tcx > > ,
185
187
goal : Goal < ' tcx , Self > ,
186
188
) -> Result < Candidate < ' tcx > , NoSolution > ;
187
189
188
190
/// `Tuple` is implemented if the `Self` type is a tuple.
189
191
fn consider_builtin_tuple_candidate (
190
- ecx : & mut EvalCtxt < ' _ , ' tcx > ,
192
+ ecx : & mut EvalCtxt < ' _ , InferCtxt < ' tcx > > ,
191
193
goal : Goal < ' tcx , Self > ,
192
194
) -> Result < Candidate < ' tcx > , NoSolution > ;
193
195
@@ -197,63 +199,63 @@ pub(super) trait GoalKind<'tcx>:
197
199
/// the built-in types. For structs, the metadata type is given by the struct
198
200
/// tail.
199
201
fn consider_builtin_pointee_candidate (
200
- ecx : & mut EvalCtxt < ' _ , ' tcx > ,
202
+ ecx : & mut EvalCtxt < ' _ , InferCtxt < ' tcx > > ,
201
203
goal : Goal < ' tcx , Self > ,
202
204
) -> Result < Candidate < ' tcx > , NoSolution > ;
203
205
204
206
/// A coroutine (that comes from an `async` desugaring) is known to implement
205
207
/// `Future<Output = O>`, where `O` is given by the coroutine's return type
206
208
/// that was computed during type-checking.
207
209
fn consider_builtin_future_candidate (
208
- ecx : & mut EvalCtxt < ' _ , ' tcx > ,
210
+ ecx : & mut EvalCtxt < ' _ , InferCtxt < ' tcx > > ,
209
211
goal : Goal < ' tcx , Self > ,
210
212
) -> Result < Candidate < ' tcx > , NoSolution > ;
211
213
212
214
/// A coroutine (that comes from a `gen` desugaring) is known to implement
213
215
/// `Iterator<Item = O>`, where `O` is given by the generator's yield type
214
216
/// that was computed during type-checking.
215
217
fn consider_builtin_iterator_candidate (
216
- ecx : & mut EvalCtxt < ' _ , ' tcx > ,
218
+ ecx : & mut EvalCtxt < ' _ , InferCtxt < ' tcx > > ,
217
219
goal : Goal < ' tcx , Self > ,
218
220
) -> Result < Candidate < ' tcx > , NoSolution > ;
219
221
220
222
/// A coroutine (that comes from a `gen` desugaring) is known to implement
221
223
/// `FusedIterator`
222
224
fn consider_builtin_fused_iterator_candidate (
223
- ecx : & mut EvalCtxt < ' _ , ' tcx > ,
225
+ ecx : & mut EvalCtxt < ' _ , InferCtxt < ' tcx > > ,
224
226
goal : Goal < ' tcx , Self > ,
225
227
) -> Result < Candidate < ' tcx > , NoSolution > ;
226
228
227
229
fn consider_builtin_async_iterator_candidate (
228
- ecx : & mut EvalCtxt < ' _ , ' tcx > ,
230
+ ecx : & mut EvalCtxt < ' _ , InferCtxt < ' tcx > > ,
229
231
goal : Goal < ' tcx , Self > ,
230
232
) -> Result < Candidate < ' tcx > , NoSolution > ;
231
233
232
234
/// A coroutine (that doesn't come from an `async` or `gen` desugaring) is known to
233
235
/// implement `Coroutine<R, Yield = Y, Return = O>`, given the resume, yield,
234
236
/// and return types of the coroutine computed during type-checking.
235
237
fn consider_builtin_coroutine_candidate (
236
- ecx : & mut EvalCtxt < ' _ , ' tcx > ,
238
+ ecx : & mut EvalCtxt < ' _ , InferCtxt < ' tcx > > ,
237
239
goal : Goal < ' tcx , Self > ,
238
240
) -> Result < Candidate < ' tcx > , NoSolution > ;
239
241
240
242
fn consider_builtin_discriminant_kind_candidate (
241
- ecx : & mut EvalCtxt < ' _ , ' tcx > ,
243
+ ecx : & mut EvalCtxt < ' _ , InferCtxt < ' tcx > > ,
242
244
goal : Goal < ' tcx , Self > ,
243
245
) -> Result < Candidate < ' tcx > , NoSolution > ;
244
246
245
247
fn consider_builtin_async_destruct_candidate (
246
- ecx : & mut EvalCtxt < ' _ , ' tcx > ,
248
+ ecx : & mut EvalCtxt < ' _ , InferCtxt < ' tcx > > ,
247
249
goal : Goal < ' tcx , Self > ,
248
250
) -> Result < Candidate < ' tcx > , NoSolution > ;
249
251
250
252
fn consider_builtin_destruct_candidate (
251
- ecx : & mut EvalCtxt < ' _ , ' tcx > ,
253
+ ecx : & mut EvalCtxt < ' _ , InferCtxt < ' tcx > > ,
252
254
goal : Goal < ' tcx , Self > ,
253
255
) -> Result < Candidate < ' tcx > , NoSolution > ;
254
256
255
257
fn consider_builtin_transmute_candidate (
256
- ecx : & mut EvalCtxt < ' _ , ' tcx > ,
258
+ ecx : & mut EvalCtxt < ' _ , InferCtxt < ' tcx > > ,
257
259
goal : Goal < ' tcx , Self > ,
258
260
) -> Result < Candidate < ' tcx > , NoSolution > ;
259
261
@@ -265,12 +267,12 @@ pub(super) trait GoalKind<'tcx>:
265
267
/// otherwise recompute this for codegen. This is a bit of a mess but the
266
268
/// easiest way to maintain the existing behavior for now.
267
269
fn consider_structural_builtin_unsize_candidates (
268
- ecx : & mut EvalCtxt < ' _ , ' tcx > ,
270
+ ecx : & mut EvalCtxt < ' _ , InferCtxt < ' tcx > > ,
269
271
goal : Goal < ' tcx , Self > ,
270
272
) -> Vec < Candidate < ' tcx > > ;
271
273
}
272
274
273
- impl < ' tcx > EvalCtxt < ' _ , ' tcx > {
275
+ impl < ' tcx > EvalCtxt < ' _ , InferCtxt < ' tcx > > {
274
276
pub ( super ) fn assemble_and_evaluate_candidates < G : GoalKind < ' tcx > > (
275
277
& mut self ,
276
278
goal : Goal < ' tcx , G > ,
0 commit comments