@@ -147,21 +147,25 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
147
147
/// Let's work through an example to explain how it works. Assume
148
148
/// the current function is as follows:
149
149
///
150
- /// fn foo<'a, 'b>(..) -> (impl Bar<'a>, impl Bar<'b>)
150
+ /// ```text
151
+ /// fn foo<'a, 'b>(..) -> (impl Bar<'a>, impl Bar<'b>)
152
+ /// ```
151
153
///
152
154
/// Here, we have two `impl Trait` types whose values are being
153
155
/// inferred (the `impl Bar<'a>` and the `impl
154
156
/// Bar<'b>`). Conceptually, this is sugar for a setup where we
155
157
/// define underlying abstract types (`Foo1`, `Foo2`) and then, in
156
158
/// the return type of `foo`, we *reference* those definitions:
157
159
///
158
- /// abstract type Foo1<'x>: Bar<'x>;
159
- /// abstract type Foo2<'x>: Bar<'x>;
160
- /// fn foo<'a, 'b>(..) -> (Foo1<'a>, Foo2<'b>) { .. }
161
- /// // ^^^^ ^^
162
- /// // | |
163
- /// // | substs
164
- /// // def_id
160
+ /// ```text
161
+ /// abstract type Foo1<'x>: Bar<'x>;
162
+ /// abstract type Foo2<'x>: Bar<'x>;
163
+ /// fn foo<'a, 'b>(..) -> (Foo1<'a>, Foo2<'b>) { .. }
164
+ /// // ^^^^ ^^
165
+ /// // | |
166
+ /// // | substs
167
+ /// // def_id
168
+ /// ```
165
169
///
166
170
/// As indicating in the comments above, each of those references
167
171
/// is (in the compiler) basically a substitution (`substs`)
@@ -175,8 +179,10 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
175
179
/// `Foo2`. That is, this gives rise to higher-order (pattern) unification
176
180
/// constraints like:
177
181
///
178
- /// for<'a> (Foo1<'a> = C1)
179
- /// for<'b> (Foo1<'b> = C2)
182
+ /// ```text
183
+ /// for<'a> (Foo1<'a> = C1)
184
+ /// for<'b> (Foo1<'b> = C2)
185
+ /// ```
180
186
///
181
187
/// For these equation to be satisfiable, the types `C1` and `C2`
182
188
/// can only refer to a limited set of regions. For example, `C1`
@@ -189,15 +195,19 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
189
195
/// regions. In fact, it is fairly likely that they do! Consider
190
196
/// this possible definition of `foo`:
191
197
///
192
- /// fn foo<'a, 'b>(x: &'a i32, y: &'b i32) -> (impl Bar<'a>, impl Bar<'b>) {
198
+ /// ```text
199
+ /// fn foo<'a, 'b>(x: &'a i32, y: &'b i32) -> (impl Bar<'a>, impl Bar<'b>) {
193
200
/// (&*x, &*y)
194
201
/// }
202
+ /// ```
195
203
///
196
204
/// Here, the values for the concrete types of the two impl
197
205
/// traits will include inference variables:
198
206
///
199
- /// &'0 i32
200
- /// &'1 i32
207
+ /// ```text
208
+ /// &'0 i32
209
+ /// &'1 i32
210
+ /// ```
201
211
///
202
212
/// Ordinarily, the subtyping rules would ensure that these are
203
213
/// sufficiently large. But since `impl Bar<'a>` isn't a specific
@@ -207,7 +217,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
207
217
/// inferred type are regions that could validly appear.
208
218
///
209
219
/// This is actually a bit of a tricky constraint in general. We
210
- /// want to say that each variable (e.g., `'0`` ) can only take on
220
+ /// want to say that each variable (e.g., `'0`) can only take on
211
221
/// values that were supplied as arguments to the abstract type
212
222
/// (e.g., `'a` for `Foo1<'a>`) or `'static`, which is always in
213
223
/// scope. We don't have a constraint quite of this kind in the current
@@ -225,7 +235,9 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
225
235
///
226
236
/// In some cases, there is no minimum. Consider this example:
227
237
///
228
- /// fn baz<'a, 'b>() -> impl Trait<'a, 'b> { ... }
238
+ /// ```text
239
+ /// fn baz<'a, 'b>() -> impl Trait<'a, 'b> { ... }
240
+ /// ```
229
241
///
230
242
/// Here we would report an error, because `'a` and `'b` have no
231
243
/// relation to one another.
@@ -245,8 +257,10 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
245
257
/// which is the current function. It also means that we can
246
258
/// take "implied bounds" into account in some cases:
247
259
///
248
- /// trait SomeTrait<'a, 'b> { }
249
- /// fn foo<'a, 'b>(_: &'a &'b u32) -> impl SomeTrait<'a, 'b> { .. }
260
+ /// ```text
261
+ /// trait SomeTrait<'a, 'b> { }
262
+ /// fn foo<'a, 'b>(_: &'a &'b u32) -> impl SomeTrait<'a, 'b> { .. }
263
+ /// ```
250
264
///
251
265
/// Here, the fact that `'b: 'a` is known only because of the
252
266
/// implied bounds from the `&'a &'b u32` parameter, and is not
0 commit comments