1
Fork 0

Rollup merge of #114549 - chenyukang:yukang-review-resolve-part, r=petrochenkov

Style fix and refactor on resolve diagnostics

- coding style
- refactor api of `span_look_ahead`
This commit is contained in:
Matthias Krüger 2023-08-07 05:29:13 +02:00 committed by GitHub
commit d804b74c6c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 53 additions and 61 deletions

View file

@ -1429,20 +1429,18 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
// Issue #109436, we need to add parentheses properly for method calls
// for example, `foo.into()` should be `(&foo).into()`
if let Ok(snippet) = self.tcx.sess.source_map().span_to_snippet(
self.tcx.sess.source_map().span_look_ahead(span, Some("."), Some(50)),
) {
if snippet == "." {
err.multipart_suggestion_verbose(
sugg_msg,
vec![
(span.shrink_to_lo(), format!("({sugg_prefix}")),
(span.shrink_to_hi(), ")".to_string()),
],
Applicability::MaybeIncorrect,
);
return true;
}
if let Some(_) =
self.tcx.sess.source_map().span_look_ahead(span, ".", Some(50))
{
err.multipart_suggestion_verbose(
sugg_msg,
vec![
(span.shrink_to_lo(), format!("({sugg_prefix}")),
(span.shrink_to_hi(), ")".to_string()),
],
Applicability::MaybeIncorrect,
);
return true;
}
// Issue #104961, we need to add parentheses properly for compound expressions