Skip to content

Commit 90e4a42

Browse files
committed
Use with_reduced_queries to avoid query cycles.
This changes the error message of `query-cycle-issue-124901.rs`, which doesn't matter much.
1 parent 48bcaf7 commit 90e4a42

3 files changed

Lines changed: 13 additions & 8 deletions

File tree

compiler/rustc_query_impl/src/plumbing.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -327,21 +327,23 @@ pub(crate) fn create_query_frame<
327327
description
328328
};
329329

330-
let span = if kind == dep_graph::dep_kinds::def_span || reduce_queries {
330+
let span = if reduce_queries {
331331
// The `def_span` query is used to calculate `default_span`,
332332
// so exit to avoid infinite recursion.
333333
None
334334
} else {
335-
Some(key.default_span(tcx))
335+
Some(tcx.with_reduced_queries(|| key.default_span(tcx)))
336336
};
337337

338338
let def_id = key.key_as_def_id();
339339

340-
let def_kind = if kind == dep_graph::dep_kinds::def_kind || reduce_queries {
340+
let def_kind = if reduce_queries {
341341
// Try to avoid infinite recursion.
342342
None
343343
} else {
344-
def_id.and_then(|def_id| def_id.as_local()).map(|def_id| tcx.def_kind(def_id))
344+
def_id
345+
.and_then(|def_id| def_id.as_local())
346+
.map(|def_id| tcx.with_reduced_queries(|| tcx.def_kind(def_id)))
345347
};
346348

347349
let def_id_for_ty_in_cycle = key.def_id_for_ty_in_cycle();

tests/ui/resolve/query-cycle-issue-124901.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//~ ERROR: cycle detected when looking up span for `Default`
1+
//~ ERROR: cycle detected when getting HIR ID of `Default`
22
trait Default {
33
type Id;
44

tests/ui/resolve/query-cycle-issue-124901.stderr

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
error[E0391]: cycle detected when looking up span for `Default`
1+
error[E0391]: cycle detected when getting HIR ID of `Default`
22
|
3-
= note: ...which immediately requires looking up span for `Default` again
4-
= note: cycle used when perform lints prior to AST lowering
3+
= note: ...which requires getting the crate HIR...
4+
= note: ...which requires perform lints prior to AST lowering...
5+
= note: ...which requires looking up span for `Default`...
6+
= note: ...which again requires getting HIR ID of `Default`, completing the cycle
7+
= note: cycle used when getting the resolver for lowering
58
= note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information
69

710
error: aborting due to 1 previous error

0 commit comments

Comments
 (0)