1
Fork 0

refactor on span_look_ahead

This commit is contained in:
yukang 2023-08-06 22:28:14 +08:00
parent 026c4b6a65
commit eb0fcc5ad1
3 changed files with 28 additions and 33 deletions

View file

@ -1428,20 +1428,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