diff options
| author | Michael Howell <michael@notriddle.com> | 2023-02-27 08:48:50 -0700 |
|---|---|---|
| committer | Michael Howell <michael@notriddle.com> | 2023-02-27 09:22:51 -0700 |
| commit | f058bb0fcfeef3ebb0da19b2399f575c3aa9c3e8 (patch) | |
| tree | 27aac62b2cab6d91b454ab44e41ec207d25685db | |
| parent | 49b9cc5139dd4d11ef78dc08c1f9170de5b1ca39 (diff) | |
| download | rust-f058bb0fcfeef3ebb0da19b2399f575c3aa9c3e8.tar.gz rust-f058bb0fcfeef3ebb0da19b2399f575c3aa9c3e8.zip | |
diagnostics: avoid querying `associated_item` in the resolver
Fixes #108529
| -rw-r--r-- | compiler/rustc_resolve/src/diagnostics.rs | 8 | ||||
| -rw-r--r-- | tests/ui/resolve/issue-108529.rs | 8 | ||||
| -rw-r--r-- | tests/ui/resolve/issue-108529.stderr | 9 |
3 files changed, 23 insertions, 2 deletions
diff --git a/compiler/rustc_resolve/src/diagnostics.rs b/compiler/rustc_resolve/src/diagnostics.rs index ee2d2301399..7add59ac627 100644 --- a/compiler/rustc_resolve/src/diagnostics.rs +++ b/compiler/rustc_resolve/src/diagnostics.rs @@ -189,7 +189,9 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { } let container = match parent.kind { - ModuleKind::Def(kind, _, _) => self.tcx.def_kind_descr(kind, parent.def_id()), + // Avoid using TyCtxt::def_kind_descr in the resolver, because it + // indirectly *calls* the resolver, and would cause a query cycle. + ModuleKind::Def(kind, _, _) => kind.descr(parent.def_id()), ModuleKind::Block => "block", }; @@ -1804,7 +1806,9 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { found("module") } else { match binding.res() { - Res::Def(kind, id) => found(self.tcx.def_kind_descr(kind, id)), + // Avoid using TyCtxt::def_kind_descr in the resolver, because it + // indirectly *calls* the resolver, and would cause a query cycle. + Res::Def(kind, id) => found(kind.descr(id)), _ => found(ns_to_try.descr()), } } diff --git a/tests/ui/resolve/issue-108529.rs b/tests/ui/resolve/issue-108529.rs new file mode 100644 index 00000000000..8e3aafab6aa --- /dev/null +++ b/tests/ui/resolve/issue-108529.rs @@ -0,0 +1,8 @@ +#![allow(nonstandard_style)] +use f::f::f; //~ ERROR + +trait f { + extern "C" fn f(); +} + +fn main() {} diff --git a/tests/ui/resolve/issue-108529.stderr b/tests/ui/resolve/issue-108529.stderr new file mode 100644 index 00000000000..cf4e4759c37 --- /dev/null +++ b/tests/ui/resolve/issue-108529.stderr @@ -0,0 +1,9 @@ +error[E0432]: unresolved import `f::f` + --> $DIR/issue-108529.rs:2:8 + | +LL | use f::f::f; + | ^ expected type, found associated function `f` in `f` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0432`. |
