From 5b802ed6c9fd23214f9201b8e05193c8a2240e73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ali=C3=A9nore=20Bouttefeux?= <77335613+ABouttefeux@users.noreply.github.com> Date: Sat, 22 May 2021 08:59:04 +0200 Subject: [PATCH] Apply suggestions from code review Co-authored-by: Esteban Kuber --- .../rustc_typeck/src/check/method/suggest.rs | 30 ++++++++----------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/compiler/rustc_typeck/src/check/method/suggest.rs b/compiler/rustc_typeck/src/check/method/suggest.rs index f46d4205a6bd..a36e0553c7ad 100644 --- a/compiler/rustc_typeck/src/check/method/suggest.rs +++ b/compiler/rustc_typeck/src/check/method/suggest.rs @@ -384,7 +384,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } else { span = item_name.span; - // issue #81576, elision of generic argument when no methode can be found in any implementation + // Don't show generic arguments when the method can't be found in any implementation (#81576). let mut ty_str_reported = ty_str.clone(); if let ty::Adt(_, ref generics) = actual.kind() { if generics.len() > 0 { @@ -493,22 +493,18 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { self.associated_item(*def_id, item_name, Namespace::ValueNS) { // Check for both mode is the same so we avoid suggesting - // incorect associated item. - match (mode, assoc.fn_has_self_parameter) { - (Mode::MethodCall, true) => { - if let SelfSource::MethodCall(_) = source { - // We check that the suggest type is actually - // different from the received one - // So we avoid suggestion method with Box - // for instance - self.tcx.at(span).type_of(*def_id) != actual - && self.tcx.at(span).type_of(*def_id) - != rcvr_ty - } else { - false - } + // incorrect associated item. + match (mode, assoc.fn_has_self_parameter, source) { + (Mode::MethodCall, true, SelfSource::MethodCall(_)) => { + // We check that the suggest type is actually + // different from the received one + // So we avoid suggestion method with Box + // for instance + self.tcx.at(span).type_of(*def_id) != actual + && self.tcx.at(span).type_of(*def_id) + != rcvr_ty } - (Mode::Path, false) => true, + (Mode::Path, false, _) => true, _ => false, } } else { @@ -521,7 +517,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { inherent_impls_candidate.dedup(); // number of type to shows at most. const LIMIT: usize = 3; - let mut note = format!("The {item_kind} was found for"); + let mut note = format!("the {item_kind} was found for"); if inherent_impls_candidate.len() > 1 { for impl_item in inherent_impls_candidate.iter().take(LIMIT - 2) {