Skip to content

Commit

Permalink
Rollup merge of rust-lang#108533 - notriddle:notriddle/resolver-def-d…
Browse files Browse the repository at this point in the history
…escr, r=compiler-errors

diagnostics: avoid querying `associated_item` in the resolver

Fixes rust-lang#108529

CC rust-lang#108324
  • Loading branch information
matthiaskrgr committed Feb 27, 2023
2 parents 828b66e + f058bb0 commit a184150
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
8 changes: 6 additions & 2 deletions compiler/rustc_resolve/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
};

Expand Down Expand Up @@ -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()),
}
}
Expand Down
8 changes: 8 additions & 0 deletions tests/ui/resolve/issue-108529.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#![allow(nonstandard_style)]
use f::f::f; //~ ERROR

trait f {
extern "C" fn f();
}

fn main() {}
9 changes: 9 additions & 0 deletions tests/ui/resolve/issue-108529.stderr
Original file line number Diff line number Diff line change
@@ -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`.

0 comments on commit a184150

Please sign in to comment.