Skip to content

Commit 0872241

Browse files
Noratriebjyn514
authored andcommitted
Update query.md
- queries always need a description - `QueryDescription` isn't just for descriptions (it's actually not for descriptions at all now) and always implemented by the macro - queries are not grouped into categories
1 parent 2bdb02c commit 0872241

File tree

1 file changed

+8
-26
lines changed

1 file changed

+8
-26
lines changed

src/query.md

+8-26
Original file line numberDiff line numberDiff line change
@@ -180,20 +180,14 @@ the big macro invocation in
180180

181181
```rust,ignore
182182
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() }
188186
}
189-
190187
...
191188
}
192189
```
193190

194-
Queries are grouped into categories (`Other`, `Codegen`, `TypeChecking`, etc.).
195-
Each group contains one or more queries.
196-
197191
A query definition has the following form:
198192

199193
```rust,ignore
@@ -260,26 +254,16 @@ impl<'tcx> QueryConfig for type_of<'tcx> {
260254
}
261255
```
262256

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.
270260

271261
[QueryConfig]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_query_system/query/config/trait.QueryConfig.html
272262
[QueryDescription]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_query_system/query/config/trait.QueryDescription.html
273263

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-
```
281264

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.
283267

284268
```rust,ignore
285269
rustc_queries! {
@@ -292,8 +276,6 @@ rustc_queries! {
292276
}
293277
```
294278

295-
`rustc_queries` macro will generate an appropriate `impl` automatically.
296-
297279
## External links
298280

299281
Related design ideas, and tracking issues:

0 commit comments

Comments
 (0)