refactor on span_look_ahead
This commit is contained in:
parent
026c4b6a65
commit
eb0fcc5ad1
3 changed files with 28 additions and 33 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue