Skip to content

Commit 090bd54

Browse files
Noratriebjyn514
authored andcommitted
Update some more things and improve wording
1 parent 0872241 commit 090bd54

File tree

1 file changed

+10
-20
lines changed

1 file changed

+10
-20
lines changed

src/query.md

+10-20
Original file line numberDiff line numberDiff line change
@@ -169,20 +169,25 @@ they define both a `provide` and a `provide_extern` function, through
169169
How do you add a new query?
170170
Defining a query takes place in two steps:
171171

172-
1. Specify the query name and its arguments.
172+
1. Declare the query name, its arguments and description.
173173
2. Supply query providers where needed.
174174

175-
To specify the query name and arguments, you simply add an entry to
176-
the big macro invocation in
177-
[`compiler/rustc_middle/src/query/mod.rs`][query-mod], which looks something like:
175+
To declare the query name and arguments, you simply add an entry to
176+
the big macro invocation in [`compiler/rustc_middle/src/query/mod.rs`][query-mod].
177+
Then you need to add a documentation comment to it with some _internal_ description.
178+
Then, provide the `desc` attribute which contains a short description of the query.
179+
This description is shown to the user in query cycles.
180+
181+
This looks something like:
178182

179183
[query-mod]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/query/index.html
180184

181185
```rust,ignore
182186
rustc_queries! {
183187
/// Records the type of every item.
184188
query type_of(key: DefId) -> Ty<'tcx> {
185-
cache { key.is_local() }
189+
cache_on_disk_if { key.is_local() }
190+
desc { |tcx| "computing the type of `{}`", tcx.def_path_str(key) }
186191
}
187192
...
188193
}
@@ -261,21 +266,6 @@ extra methods which are used by the query system.
261266
[QueryConfig]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_query_system/query/config/trait.QueryConfig.html
262267
[QueryDescription]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_query_system/query/config/trait.QueryDescription.html
263268

264-
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.
267-
268-
```rust,ignore
269-
rustc_queries! {
270-
Other {
271-
/// Records the type of every item.
272-
query type_of(key: DefId) -> Ty<'tcx> {
273-
desc { |tcx| "computing the type of `{}`", tcx.def_path_str(key) }
274-
}
275-
}
276-
}
277-
```
278-
279269
## External links
280270

281271
Related design ideas, and tracking issues:

0 commit comments

Comments
 (0)