From fc6ee8f38b42830378c770e3b786138be0f35ccd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Thu, 9 Jul 2020 09:05:40 -0700 Subject: [PATCH] Reduce indentation --- src/librustc_resolve/diagnostics.rs | 68 ++++++++++++++--------------- 1 file changed, 33 insertions(+), 35 deletions(-) diff --git a/src/librustc_resolve/diagnostics.rs b/src/librustc_resolve/diagnostics.rs index 2854683b61bab..be2ad6d17389e 100644 --- a/src/librustc_resolve/diagnostics.rs +++ b/src/librustc_resolve/diagnostics.rs @@ -840,44 +840,42 @@ impl<'a> Resolver<'a> { suggestion: Option, span: Span, ) -> bool { - if let Some(suggestion) = suggestion { + let suggestion = match suggestion { + None => return false, // We shouldn't suggest underscore. - if suggestion.candidate == kw::Underscore { - return false; - } - - let msg = format!( - "{} {} with a similar name exists", - suggestion.res.article(), - suggestion.res.descr() - ); - err.span_suggestion( - span, - &msg, - suggestion.candidate.to_string(), - Applicability::MaybeIncorrect, - ); - let def_span = suggestion.res.opt_def_id().and_then(|def_id| match def_id.krate { - LOCAL_CRATE => self.opt_span(def_id), - _ => Some( - self.session - .source_map() - .guess_head_span(self.cstore().get_span_untracked(def_id, self.session)), + Some(suggestion) if suggestion.candidate == kw::Underscore => return false, + Some(suggestion) => suggestion, + }; + let msg = format!( + "{} {} with a similar name exists", + suggestion.res.article(), + suggestion.res.descr() + ); + err.span_suggestion( + span, + &msg, + suggestion.candidate.to_string(), + Applicability::MaybeIncorrect, + ); + let def_span = suggestion.res.opt_def_id().and_then(|def_id| match def_id.krate { + LOCAL_CRATE => self.opt_span(def_id), + _ => Some( + self.session + .source_map() + .guess_head_span(self.cstore().get_span_untracked(def_id, self.session)), + ), + }); + if let Some(span) = def_span { + err.span_label( + self.session.source_map().guess_head_span(span), + &format!( + "similarly named {} `{}` defined here", + suggestion.res.descr(), + suggestion.candidate.as_str(), ), - }); - if let Some(span) = def_span { - err.span_label( - self.session.source_map().guess_head_span(span), - &format!( - "similarly named {} `{}` defined here", - suggestion.res.descr(), - suggestion.candidate.as_str(), - ), - ); - } - return true; + ); } - false + true } fn binding_description(&self, b: &NameBinding<'_>, ident: Ident, from_prelude: bool) -> String {