@@ -218,29 +218,33 @@ algorithms.
218
218
[ `region_constraints` ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_infer/infer/region_constraints/index.html
219
219
[ `opportunistic_resolve_var` ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_infer/infer/region_constraints/struct.RegionConstraintCollector.html#method.opportunistic_resolve_var
220
220
221
- ## Extracting region constraints
221
+ ## Solving region constraints
222
222
223
- Ultimately, region constraints are only solved at the very end of
224
- type-checking, once all other constraints are known. There are two
223
+ Region constraints are only solved at the very end of
224
+ typechecking, once all other constraints are known and
225
+ all other obligations have been proven. There are two
225
226
ways to solve region constraints right now: lexical and
226
227
non-lexical. Eventually there will only be one.
227
228
229
+ An exception here is the leak-check which is used during trait solving
230
+ and relies on region constraints containing higher-ranked regions. Region
231
+ constraints in the root universe (i.e. not arising from a ` for<'a> ` ) must
232
+ not influence the trait system, as these regions are all erased during
233
+ codegen.
234
+
228
235
To solve ** lexical** region constraints, you invoke
229
236
[ ` resolve_regions_and_report_errors ` ] . This "closes" the region
230
237
constraint process and invokes the [ ` lexical_region_resolve ` ] code. Once
231
238
this is done, any further attempt to equate or create a subtyping
232
239
relationship will yield an ICE.
233
240
234
- Non-lexical region constraints are not handled within the inference
235
- context. Instead, the NLL solver (actually, the MIR type-checker)
236
- invokes [ ` take_and_reset_region_constraints ` ] periodically. This
237
- extracts all of the outlives constraints from the region solver, but
238
- leaves the set of variables intact. This is used to get * just* the
239
- region constraints that resulted from some particular point in the
240
- program, since the NLL solver needs to know not just * what* regions
241
- were subregions, but also * where* . Finally, the NLL solver invokes
242
- [ ` take_region_var_origins ` ] , which "closes" the region constraint
243
- process in the same way as normal solving.
241
+ The NLL solver (actually, the MIR type-checker) invokes does things slightly
242
+ differently. It uses canonical queries for trait solving which use
243
+ [ ` take_and_reset_region_constraints ` ] at the end. This extracts all of the
244
+ outlives constraints added during the canonical query. This is required
245
+ as the NLL solver must not only know * what* regions outlive each other,
246
+ but also * where* . Finally, the NLL solver invokes [ ` take_region_var_origins ` ] ,
247
+ providing all region variables to the solver.
244
248
245
249
[ `resolve_regions_and_report_errors` ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_infer/infer/struct.InferCtxt.html#method.resolve_regions_and_report_errors
246
250
[ `lexical_region_resolve` ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_infer/infer/lexical_region_resolve/index.html
0 commit comments