]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go/internal: use strings.CutSuffix
authorcui fliter <imcusg@gmail.com>
Tue, 27 Sep 2022 09:16:32 +0000 (09:16 +0000)
committerGopher Robot <gobot@golang.org>
Tue, 27 Sep 2022 16:36:36 +0000 (16:36 +0000)
Updates #42537

Change-Id: I2d4c5e911c8a2ddfe9a976896b05d3cd8be61f6b
GitHub-Last-Rev: a87597d8a7a84c4975fb5e13004feda9b6abce34
GitHub-Pull-Request: golang/go#55830
Reviewed-on: https://go-review.googlesource.com/c/go/+/433275
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: Benny Siegert <bsiegert@gmail.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>

src/cmd/go/internal/clean/clean.go
src/cmd/go/internal/load/pkg.go

index 2417cc077e8daa3e0f94f561bbafe8442c5dce6d..368288f0fc692a1fca9e5d94c7f0fab78730b258 100644 (file)
@@ -340,16 +340,14 @@ func clean(p *load.Package) {
                        continue
                }
 
-               if strings.HasSuffix(name, "_test.go") {
-                       base := name[:len(name)-len("_test.go")]
+               if base, found := strings.CutSuffix(name, "_test.go"); found {
                        allRemove = append(allRemove, base+".test", base+".test.exe")
                }
 
-               if strings.HasSuffix(name, ".go") {
+               if base, found := strings.CutSuffix(name, ".go"); found {
                        // TODO(adg,rsc): check that this .go file is actually
                        // in "package main", and therefore capable of building
                        // to an executable file.
-                       base := name[:len(name)-len(".go")]
                        allRemove = append(allRemove, base, base+".exe")
                }
        }
index a6e380b89f002dd867c49b745f44a9c86669b9e9..cebec51d424aa242c32d02cccdb641bf8d412c1c 100644 (file)
@@ -3115,10 +3115,10 @@ func PackagesAndErrorsOutsideModule(ctx context.Context, opts PackageOpts, args
        }
        patterns := make([]string, len(args))
        for i, arg := range args {
-               if !strings.HasSuffix(arg, "@"+version) {
+               p, found := strings.CutSuffix(arg, "@"+version)
+               if !found {
                        return nil, fmt.Errorf("%s: all arguments must refer to packages in the same module at the same version (@%s)", arg, version)
                }
-               p := arg[:len(arg)-len(version)-1]
                switch {
                case build.IsLocalImport(p):
                        return nil, fmt.Errorf("%s: argument must be a package path, not a relative path", arg)