Skip to content

Commit f058bb0

Browse files
committed
diagnostics: avoid querying associated_item in the resolver
Fixes #108529
1 parent 49b9cc5 commit f058bb0

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

compiler/rustc_resolve/src/diagnostics.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,9 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
189189
}
190190

191191
let container = match parent.kind {
192-
ModuleKind::Def(kind, _, _) => self.tcx.def_kind_descr(kind, parent.def_id()),
192+
// Avoid using TyCtxt::def_kind_descr in the resolver, because it
193+
// indirectly *calls* the resolver, and would cause a query cycle.
194+
ModuleKind::Def(kind, _, _) => kind.descr(parent.def_id()),
193195
ModuleKind::Block => "block",
194196
};
195197

@@ -1804,7 +1806,9 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
18041806
found("module")
18051807
} else {
18061808
match binding.res() {
1807-
Res::Def(kind, id) => found(self.tcx.def_kind_descr(kind, id)),
1809+
// Avoid using TyCtxt::def_kind_descr in the resolver, because it
1810+
// indirectly *calls* the resolver, and would cause a query cycle.
1811+
Res::Def(kind, id) => found(kind.descr(id)),
18081812
_ => found(ns_to_try.descr()),
18091813
}
18101814
}

tests/ui/resolve/issue-108529.rs

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#![allow(nonstandard_style)]
2+
use f::f::f; //~ ERROR
3+
4+
trait f {
5+
extern "C" fn f();
6+
}
7+
8+
fn main() {}

tests/ui/resolve/issue-108529.stderr

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0432]: unresolved import `f::f`
2+
--> $DIR/issue-108529.rs:2:8
3+
|
4+
LL | use f::f::f;
5+
| ^ expected type, found associated function `f` in `f`
6+
7+
error: aborting due to previous error
8+
9+
For more information about this error, try `rustc --explain E0432`.

0 commit comments

Comments
 (0)