@@ -172,7 +172,7 @@ func (a *analyzer) inlineCall(call *ast.CallExpr, cur inspector.Cursor) {
172172 a .pass .Reportf (call .Lparen , "invalid inlining candidate: cannot read source file: %v" , err )
173173 return
174174 }
175- curFile := currentFile (cur )
175+ curFile := astutil . EnclosingFile (cur )
176176 caller := & inline.Caller {
177177 Fset : a .pass .Fset ,
178178 Types : a .pass .Pkg ,
@@ -251,7 +251,7 @@ func (a *analyzer) inlineAlias(tn *types.TypeName, curId inspector.Cursor) {
251251 }
252252 rhs := alias .Rhs ()
253253 curPath := a .pass .Pkg .Path ()
254- curFile := currentFile (curId )
254+ curFile := astutil . EnclosingFile (curId )
255255 id := curId .Node ().(* ast.Ident )
256256 // We have an identifier A here (n), possibly qualified by a package
257257 // identifier (sel.n), and an inlinable "type A = rhs" elsewhere.
@@ -425,7 +425,7 @@ func (a *analyzer) inlineConst(con *types.Const, cur inspector.Cursor) {
425425 }
426426
427427 // If n is qualified by a package identifier, we'll need the full selector expression.
428- curFile := currentFile (cur )
428+ curFile := astutil . EnclosingFile (cur )
429429 n := cur .Node ().(* ast.Ident )
430430
431431 // We have an identifier A here (n), possibly qualified by a package identifier (sel.X,
@@ -503,14 +503,6 @@ func (a *analyzer) readFile(node ast.Node) ([]byte, error) {
503503 return content , nil
504504}
505505
506- // currentFile returns the unique ast.File for a cursor.
507- func currentFile (c inspector.Cursor ) * ast.File {
508- for cf := range c .Enclosing ((* ast .File )(nil )) {
509- return cf .Node ().(* ast.File )
510- }
511- panic ("no *ast.File enclosing a cursor: impossible" )
512- }
513-
514506// A goFixInlineFuncFact is exported for each function marked "//go:fix inline".
515507// It holds information about the callee to support inlining.
516508type goFixInlineFuncFact struct { Callee * inline.Callee }
0 commit comments