From aebafba4bba5d0034edba046821b83ff65ef2a37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ozan=20Kenan=20G=C3=BCng=C3=B6r?= Date: Thu, 19 Feb 2026 21:22:06 +0300 Subject: [PATCH] resolve: do not suggest `_` for unresolved imports `use _` is never valid, so it should not be suggested as a similar name. --- compiler/rustc_resolve/src/imports.rs | 3 +++ .../underscore-bindings-disambiguators.stderr | 12 ------------ 2 files changed, 3 insertions(+), 12 deletions(-) diff --git a/compiler/rustc_resolve/src/imports.rs b/compiler/rustc_resolve/src/imports.rs index d9f9d1ff5a479..704c316bce650 100644 --- a/compiler/rustc_resolve/src/imports.rs +++ b/compiler/rustc_resolve/src/imports.rs @@ -1282,6 +1282,9 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { if i.name == ident.name { return None; } // Never suggest the same name + if i.name == kw::Underscore { + return None; + } // `use _` is never valid let resolution = resolution.borrow(); if let Some(name_binding) = resolution.best_decl() { diff --git a/tests/ui/resolve/underscore-bindings-disambiguators.stderr b/tests/ui/resolve/underscore-bindings-disambiguators.stderr index 69ac95158f8cb..ec1dec8fe8e28 100644 --- a/tests/ui/resolve/underscore-bindings-disambiguators.stderr +++ b/tests/ui/resolve/underscore-bindings-disambiguators.stderr @@ -3,24 +3,12 @@ error[E0432]: unresolved import `X` | LL | use X as Y; | ^^^^^^ no `X` in the root - | -help: a similar name exists in the module - | -LL - use X as Y; -LL + use _ as Y; - | error[E0432]: unresolved import `Z` --> $DIR/underscore-bindings-disambiguators.rs:26:5 | LL | use Z as W; | ^^^^^^ no `Z` in the root - | -help: a similar name exists in the module - | -LL - use Z as W; -LL + use _ as W; - | error[E0080]: evaluation panicked: not yet implemented --> $DIR/underscore-bindings-disambiguators.rs:19:19