From 5c8c3a2c492a57c761e23ae19bdb63df487214f8 Mon Sep 17 00:00:00 2001 From: Martin Nordholts Date: Fri, 1 Dec 2023 21:19:39 +0100 Subject: [PATCH] rustc_hir_typeck: Fix ICE when probing for non-ASCII function alternative --- compiler/rustc_hir_typeck/src/method/probe.rs | 7 ++++--- tests/ui/suggestions/non_ascii_ident.rs | 3 +++ tests/ui/suggestions/non_ascii_ident.stderr | 8 +++++++- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/compiler/rustc_hir_typeck/src/method/probe.rs b/compiler/rustc_hir_typeck/src/method/probe.rs index 7d83f4a12b1..7a544c2f26d 100644 --- a/compiler/rustc_hir_typeck/src/method/probe.rs +++ b/compiler/rustc_hir_typeck/src/method/probe.rs @@ -1799,9 +1799,10 @@ fn probe_for_similar_candidate(&mut self) -> Result, Metho .iter() .find(|cand| self.matches_by_doc_alias(cand.def_id)) .map(|cand| cand.name) - }) - .unwrap(); - Ok(applicable_close_candidates.into_iter().find(|method| method.name == best_name)) + }); + Ok(best_name.and_then(|best_name| { + applicable_close_candidates.into_iter().find(|method| method.name == best_name) + })) } }) } diff --git a/tests/ui/suggestions/non_ascii_ident.rs b/tests/ui/suggestions/non_ascii_ident.rs index 679ac4bcb6e..9c897147518 100644 --- a/tests/ui/suggestions/non_ascii_ident.rs +++ b/tests/ui/suggestions/non_ascii_ident.rs @@ -1,4 +1,7 @@ fn main() { // There shall be no suggestions here. In particular not `Ok`. let _ = 读文; //~ ERROR cannot find value `读文` in this scope + + let f = 0f32; // Important line to make this an ICE regression test + 读文(f); //~ ERROR cannot find function `读文` in this scope } diff --git a/tests/ui/suggestions/non_ascii_ident.stderr b/tests/ui/suggestions/non_ascii_ident.stderr index 79fca3e1f61..fdcc64aef36 100644 --- a/tests/ui/suggestions/non_ascii_ident.stderr +++ b/tests/ui/suggestions/non_ascii_ident.stderr @@ -4,6 +4,12 @@ error[E0425]: cannot find value `读文` in this scope LL | let _ = 读文; | ^^^^ not found in this scope -error: aborting due to 1 previous error +error[E0425]: cannot find function `读文` in this scope + --> $DIR/non_ascii_ident.rs:6:5 + | +LL | 读文(f); + | ^^^^ not found in this scope + +error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0425`.