Skip to content

Commit fcb6088

Browse files
adonovangopherbot
authored andcommitted
x/tools: delete obsolete code
Change-Id: I85e2a628a2d737f7cf31598d1bb6249ecec85ff4 Reviewed-on: https://go-review.googlesource.com/c/tools/+/751980 Reviewed-by: Madeline Kalil <[email protected]> Auto-Submit: Alan Donovan <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]>
1 parent c3b48f5 commit fcb6088

File tree

10 files changed

+17
-189
lines changed

10 files changed

+17
-189
lines changed

go/analysis/passes/lostcancel/lostcancel.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import (
1616
"golang.org/x/tools/go/ast/inspector"
1717
"golang.org/x/tools/go/cfg"
1818
"golang.org/x/tools/internal/analysis/analyzerutil"
19-
"golang.org/x/tools/internal/astutil"
2019
"golang.org/x/tools/internal/typesinternal"
2120
)
2221

@@ -84,7 +83,7 @@ func runFunc(pass *analysis.Pass, node ast.Node) {
8483
// {FuncDecl,FuncLit,CallExpr,SelectorExpr}.
8584

8685
// Find the set of cancel vars to analyze.
87-
astutil.PreorderStack(node, nil, func(n ast.Node, stack []ast.Node) bool {
86+
ast.PreorderStack(node, nil, func(n ast.Node, stack []ast.Node) bool {
8887
if _, ok := n.(*ast.FuncLit); ok && len(stack) > 0 {
8988
return false // don't stray into nested functions
9089
}

go/analysis/passes/modernize/rangeint.go

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import (
1818
"golang.org/x/tools/internal/analysis/analyzerutil"
1919
typeindexanalyzer "golang.org/x/tools/internal/analysis/typeindex"
2020
"golang.org/x/tools/internal/astutil"
21-
"golang.org/x/tools/internal/moreiters"
2221
"golang.org/x/tools/internal/typesinternal"
2322
"golang.org/x/tools/internal/typesinternal/typeindex"
2423
"golang.org/x/tools/internal/versions"
@@ -142,15 +141,12 @@ func rangeint(pass *analysis.Pass) (any, error) {
142141

143142
// Find references to i within the loop body.
144143
v := info.ObjectOf(index).(*types.Var)
145-
// TODO(adonovan): use go1.25 v.Kind() == types.PackageVar
146-
if typesinternal.IsPackageLevel(v) {
144+
switch v.Kind() {
145+
case types.PackageVar:
147146
continue nextLoop
148-
}
149-
150-
// If v is a named result, it is implicitly
151-
// used after the loop (go.dev/issue/76880).
152-
// TODO(adonovan): use go1.25 v.Kind() == types.ResultVar.
153-
if moreiters.Contains(enclosingSignature(curLoop, info).Results().Variables(), v) {
147+
case types.ResultVar:
148+
// If v is a named result, it is implicitly
149+
// used after the loop (go.dev/issue/76880).
154150
continue nextLoop
155151
}
156152

go/analysis/passes/modernize/stringsbuilder.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import (
2222
typeindexanalyzer "golang.org/x/tools/internal/analysis/typeindex"
2323
"golang.org/x/tools/internal/astutil"
2424
"golang.org/x/tools/internal/refactor"
25-
"golang.org/x/tools/internal/typesinternal"
2625
"golang.org/x/tools/internal/typesinternal/typeindex"
2726
)
2827

@@ -57,7 +56,7 @@ func stringsbuilder(pass *analysis.Pass) (any, error) {
5756
assign := curAssign.Node().(*ast.AssignStmt)
5857
if assign.Tok == token.ADD_ASSIGN && is[*ast.Ident](assign.Lhs[0]) {
5958
if v, ok := pass.TypesInfo.Uses[assign.Lhs[0].(*ast.Ident)].(*types.Var); ok &&
60-
!typesinternal.IsPackageLevel(v) && // TODO(adonovan): in go1.25, use v.Kind() == types.LocalVar &&
59+
v.Kind() == types.LocalVar &&
6160
types.Identical(v.Type(), builtinString.Type()) {
6261
candidates[v] = true
6362
}

gopls/internal/golang/extract.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -998,7 +998,7 @@ func extractFunctionMethod(cpkg *cache.Package, pgf *parsego.File, start, end to
998998
}
999999
var branchStmts []*ast.BranchStmt
10001000
// Add the zero "ctrl" value to each return statement in the extracted block.
1001-
astutil.PreorderStack(extractedBlock, nil, func(n ast.Node, stack []ast.Node) bool {
1001+
ast.PreorderStack(extractedBlock, nil, func(n ast.Node, stack []ast.Node) bool {
10021002
switch n := n.(type) {
10031003
case *ast.ReturnStmt:
10041004
n.Results = append(n.Results, zeroValExpr)

gopls/internal/test/integration/workspace/goversion_test.go

Lines changed: 0 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,10 @@ package workspace
77
import (
88
"flag"
99
"os"
10-
"os/exec"
1110
"runtime"
12-
"strings"
1311
"testing"
1412

1513
. "golang.org/x/tools/gopls/internal/test/integration"
16-
"golang.org/x/tools/internal/testenv"
1714
)
1815

1916
var go121bin = flag.String("go121bin", "", "bin directory containing go 1.21 or later")
@@ -63,64 +60,3 @@ type I interface { string }
6360
)
6461
})
6562
}
66-
67-
func TestTypeCheckingFutureVersions(t *testing.T) {
68-
// This test checks the regression in golang/go#66677, where go/types fails
69-
// silently when the language version is 1.22.
70-
//
71-
// It does this by recreating the scenario of a toolchain upgrade to 1.22, as
72-
// reported in the issue. For this to work, the test must be able to download
73-
// toolchains from proxy.golang.org.
74-
//
75-
// This is really only a problem for Go 1.21, because with Go 1.23, the bug
76-
// is fixed, and starting with 1.23 we're going to *require* 1.23 to build
77-
// gopls.
78-
//
79-
// TODO(golang/go#65917): delete this test after Go 1.23 is released and
80-
// gopls requires the latest Go to build.
81-
testenv.SkipAfterGo1Point(t, 21)
82-
83-
if testing.Short() {
84-
t.Skip("skipping with -short, as this test uses the network")
85-
}
86-
87-
// If go 1.22.2 is already available in the module cache, reuse it rather
88-
// than downloading it anew.
89-
out, err := exec.Command("go", "env", "GOPATH").Output()
90-
if err != nil {
91-
t.Fatal(err)
92-
}
93-
gopath := strings.TrimSpace(string(out)) // use the ambient 1.22.2 toolchain if available
94-
95-
const files = `
96-
-- go.mod --
97-
module example.com/foo
98-
99-
go 1.22.2
100-
101-
-- main.go --
102-
package main
103-
104-
func main() {
105-
x := 1
106-
}
107-
`
108-
109-
WithOptions(
110-
Modes(Default), // slow test, only run in one mode
111-
EnvVars{
112-
"GOPATH": gopath,
113-
"GOTOOLCHAIN": "", // not local
114-
"GOPROXY": "https://proxy.golang.org",
115-
"GOSUMDB": "sum.golang.org",
116-
},
117-
).Run(t, files, func(t *testing.T, env *Env) {
118-
env.OpenFile("main.go")
119-
env.AfterChange(
120-
Diagnostics(
121-
env.AtRegexp("main.go", "x"),
122-
WithMessage("not used"),
123-
),
124-
)
125-
})
126-
}

internal/astutil/comment.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func Deprecation(doc *ast.CommentGroup) string {
3131

3232
// -- plundered from the future (CL 605517, issue #68021) --
3333

34-
// TODO(adonovan): replace with ast.Directive after go1.25 (#68021).
34+
// TODO(adonovan): replace with ast.Directive in go1.26 (#68021).
3535
// Beware of our local mods to handle analysistest
3636
// "want" comments on the same line.
3737

internal/astutil/util.go

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -15,40 +15,6 @@ import (
1515
"golang.org/x/tools/internal/moreiters"
1616
)
1717

18-
// PreorderStack traverses the tree rooted at root,
19-
// calling f before visiting each node.
20-
//
21-
// Each call to f provides the current node and traversal stack,
22-
// consisting of the original value of stack appended with all nodes
23-
// from root to n, excluding n itself. (This design allows calls
24-
// to PreorderStack to be nested without double counting.)
25-
//
26-
// If f returns false, the traversal skips over that subtree. Unlike
27-
// [ast.Inspect], no second call to f is made after visiting node n.
28-
// In practice, the second call is nearly always used only to pop the
29-
// stack, and it is surprisingly tricky to do this correctly; see
30-
// https://go.dev/issue/73319.
31-
//
32-
// TODO(adonovan): replace with [ast.PreorderStack] when go1.25 is assured.
33-
func PreorderStack(root ast.Node, stack []ast.Node, f func(n ast.Node, stack []ast.Node) bool) {
34-
before := len(stack)
35-
ast.Inspect(root, func(n ast.Node) bool {
36-
if n != nil {
37-
if !f(n, stack) {
38-
// Do not push, as there will be no corresponding pop.
39-
return false
40-
}
41-
stack = append(stack, n) // push
42-
} else {
43-
stack = stack[:len(stack)-1] // pop
44-
}
45-
return true
46-
})
47-
if len(stack) != before {
48-
panic("push/pop mismatch")
49-
}
50-
}
51-
5218
// NodeContains reports whether the Pos/End range of node n encloses
5319
// the given range.
5420
//

internal/astutil/util_test.go

Lines changed: 0 additions & 66 deletions
This file was deleted.

internal/refactor/inline/callee.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import (
1818
"strings"
1919

2020
"golang.org/x/tools/go/types/typeutil"
21-
"golang.org/x/tools/internal/astutil"
2221
"golang.org/x/tools/internal/typeparams"
2322
"golang.org/x/tools/internal/typesinternal"
2423
)
@@ -145,7 +144,7 @@ func AnalyzeCallee(logf func(string, ...any), fset *token.FileSet, pkg *types.Pa
145144
var f func(n ast.Node, stack []ast.Node) bool
146145
var stack []ast.Node
147146
stack = append(stack, decl.Type) // for scope of function itself
148-
visit := func(n ast.Node, stack []ast.Node) { astutil.PreorderStack(n, stack, f) }
147+
visit := func(n ast.Node, stack []ast.Node) { ast.PreorderStack(n, stack, f) }
149148
f = func(n ast.Node, stack []ast.Node) bool {
150149
switch n := n.(type) {
151150
case *ast.SelectorExpr:
@@ -469,7 +468,7 @@ func analyzeParams(logf func(string, ...any), fset *token.FileSet, info *types.I
469468
fieldObjs := fieldObjs(sig)
470469
var stack []ast.Node
471470
stack = append(stack, decl.Type) // for scope of function itself
472-
astutil.PreorderStack(decl.Body, stack, func(n ast.Node, stack []ast.Node) bool {
471+
ast.PreorderStack(decl.Body, stack, func(n ast.Node, stack []ast.Node) bool {
473472
if id, ok := n.(*ast.Ident); ok {
474473
if v, ok := info.Uses[id].(*types.Var); ok {
475474
if pinfo, ok := paramInfos[v]; ok {
@@ -533,7 +532,7 @@ func analyzeTypeParams(_ logger, fset *token.FileSet, info *types.Info, decl *as
533532
// TODO(jba): can we nevertheless combine this with the traversal in analyzeParams?
534533
var stack []ast.Node
535534
stack = append(stack, decl.Type) // for scope of function itself
536-
astutil.PreorderStack(decl.Body, stack, func(n ast.Node, stack []ast.Node) bool {
535+
ast.PreorderStack(decl.Body, stack, func(n ast.Node, stack []ast.Node) bool {
537536
if id, ok := n.(*ast.Ident); ok {
538537
if v, ok := info.Uses[id].(*types.TypeName); ok {
539538
if pinfo, ok := paramInfos[v]; ok {

refactor/rename/check.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import (
1313
"go/types"
1414

1515
"golang.org/x/tools/go/loader"
16-
"golang.org/x/tools/internal/astutil"
1716
"golang.org/x/tools/internal/typeparams"
1817
"golang.org/x/tools/internal/typesinternal"
1918
"golang.org/x/tools/refactor/satisfy"
@@ -332,7 +331,7 @@ func forEachLexicalRef(info *loader.PackageInfo, obj types.Object, fn func(id *a
332331

333332
case *ast.SelectorExpr:
334333
// don't visit n.Sel
335-
astutil.PreorderStack(n.X, stack, visit)
334+
ast.PreorderStack(n.X, stack, visit)
336335
return false // don't descend
337336

338337
case *ast.CompositeLit:
@@ -341,13 +340,13 @@ func forEachLexicalRef(info *loader.PackageInfo, obj types.Object, fn func(id *a
341340
tv := info.Types[n]
342341
if is[*types.Struct](typeparams.CoreType(typeparams.Deref(tv.Type))) {
343342
if n.Type != nil {
344-
astutil.PreorderStack(n.Type, stack, visit)
343+
ast.PreorderStack(n.Type, stack, visit)
345344
}
346345
for _, elt := range n.Elts {
347346
if kv, ok := elt.(*ast.KeyValueExpr); ok {
348-
astutil.PreorderStack(kv.Value, stack, visit)
347+
ast.PreorderStack(kv.Value, stack, visit)
349348
} else {
350-
astutil.PreorderStack(elt, stack, visit)
349+
ast.PreorderStack(elt, stack, visit)
351350
}
352351
}
353352
return false // don't descend
@@ -357,7 +356,7 @@ func forEachLexicalRef(info *loader.PackageInfo, obj types.Object, fn func(id *a
357356
}
358357

359358
for _, f := range info.Files {
360-
astutil.PreorderStack(f, nil, visit)
359+
ast.PreorderStack(f, nil, visit)
361360
if !ok {
362361
break
363362
}

0 commit comments

Comments
 (0)