diff options
| author | Manish Goregaokar <manishsmail@gmail.com> | 2020-07-09 11:50:50 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-07-09 11:50:50 -0700 |
| commit | 9353e21bfdea148e910b2530270a3418db836bf3 (patch) | |
| tree | 7bafe998869c457ebaa9f82179f49c37baf7a551 /src/librustc_resolve | |
| parent | 31d53decd06f9cd854bbfe11f03abcd398e396b6 (diff) | |
| parent | e771a4f989644fd6397c391af1db94d459980b2e (diff) | |
| download | rust-9353e21bfdea148e910b2530270a3418db836bf3.tar.gz rust-9353e21bfdea148e910b2530270a3418db836bf3.zip | |
Rollup merge of #74188 - estebank:tweak-ascription-typo-heuristic, r=petrochenkov
Tweak `::` -> `:` typo heuristic and reduce verbosity Do not trigger on correct type ascription expressions with trailing operators and _do_ trigger on likely path typos where a turbofish is used. On likely path typos, remove note explaining type ascription. Clean up indentation. r? @petrochenkov
Diffstat (limited to 'src/librustc_resolve')
| -rw-r--r-- | src/librustc_resolve/diagnostics.rs | 68 |
1 files changed, 33 insertions, 35 deletions
diff --git a/src/librustc_resolve/diagnostics.rs b/src/librustc_resolve/diagnostics.rs index c64c617b54b..561890723b3 100644 --- a/src/librustc_resolve/diagnostics.rs +++ b/src/librustc_resolve/diagnostics.rs @@ -898,44 +898,42 @@ impl<'a> Resolver<'a> { suggestion: Option<TypoSuggestion>, 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 { |
