@@ -180,20 +180,14 @@ the big macro invocation in
180
180
181
181
``` rust,ignore
182
182
rustc_queries! {
183
- Other {
184
- /// Records the type of every item.
185
- query type_of(key: DefId) -> Ty<'tcx> {
186
- cache { key.is_local() }
187
- }
183
+ /// Records the type of every item.
184
+ query type_of(key: DefId) -> Ty<'tcx> {
185
+ cache { key.is_local() }
188
186
}
189
-
190
187
...
191
188
}
192
189
```
193
190
194
- Queries are grouped into categories (` Other ` , ` Codegen ` , ` TypeChecking ` , etc.).
195
- Each group contains one or more queries.
196
-
197
191
A query definition has the following form:
198
192
199
193
``` rust,ignore
@@ -260,26 +254,16 @@ impl<'tcx> QueryConfig for type_of<'tcx> {
260
254
}
261
255
```
262
256
263
- There is an additional trait that you may wish to implement called
264
- [ ` self::config::QueryDescription ` ] [ QueryDescription ] . This trait is
265
- used during cycle errors to give a "human readable" name for the query,
266
- so that we can summarize what was happening when the cycle occurred.
267
- Implementing this trait is optional if the query key is ` DefId ` , but
268
- if you * don't* implement it, you get a pretty generic error ("processing ` foo ` ...").
269
- You can put new impls into the ` config ` module. They look something like this:
257
+ There is an additional trait with more methods called
258
+ [ ` self::config::QueryDescription ` ] [ QueryDescription ] . This trait contains a few
259
+ extra methods which are used by the query system.
270
260
271
261
[ QueryConfig ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_query_system/query/config/trait.QueryConfig.html
272
262
[ QueryDescription ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_query_system/query/config/trait.QueryDescription.html
273
263
274
- ``` rust,ignore
275
- impl<'tcx> QueryDescription for queries::type_of<'tcx> {
276
- fn describe(tcx: TyCtxt, key: DefId) -> String {
277
- format!("computing the type of `{}`", tcx.def_path_str(key))
278
- }
279
- }
280
- ```
281
264
282
- Another option is to add ` desc ` modifier:
265
+ Queries also have a description, which is specified using the ` desc ` modifier.
266
+ This description is shown to the user when cycle errors happen.
283
267
284
268
``` rust,ignore
285
269
rustc_queries! {
@@ -292,8 +276,6 @@ rustc_queries! {
292
276
}
293
277
```
294
278
295
- ` rustc_queries ` macro will generate an appropriate ` impl ` automatically.
296
-
297
279
## External links
298
280
299
281
Related design ideas, and tracking issues:
0 commit comments