Avoid suggesting self in visibility spec

Co-authored-by: Esteban Kuber <estebank@users.noreply.github.com>
This commit is contained in:
Dániel Buga 2021-12-11 17:32:15 +01:00
parent b9a37ad0d9
commit f3a08fd8e7
3 changed files with 50 additions and 1 deletions

View file

@ -298,11 +298,16 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
.get(0)
.map(|p| (p.span.shrink_to_lo(), "&self, "))
.unwrap_or_else(|| {
// Try to look for the "(" after the function name, if possible.
// This avoids placing the suggestion into the visibility specifier.
let span = fn_kind
.ident()
.map_or(*span, |ident| span.with_lo(ident.span.hi()));
(
self.r
.session
.source_map()
.span_through_char(*span, '(')
.span_through_char(span, '(')
.shrink_to_hi(),
"&self",
)