Skip to content

Commit 48a58c5

Browse files
cuishuanggopherbot
authored andcommitted
cmd/go/internal: use strings.CutSuffix
Updates #42537 Change-Id: I2d4c5e911c8a2ddfe9a976896b05d3cd8be61f6b GitHub-Last-Rev: a87597d GitHub-Pull-Request: #55830 Reviewed-on: https://go-review.googlesource.com/c/go/+/433275 TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]> Auto-Submit: Ian Lance Taylor <[email protected]> Reviewed-by: Benny Siegert <[email protected]> Run-TryBot: Ian Lance Taylor <[email protected]>
1 parent b0f8e20 commit 48a58c5

File tree

2 files changed

+4
-6
lines changed

2 files changed

+4
-6
lines changed

src/cmd/go/internal/clean/clean.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -340,16 +340,14 @@ func clean(p *load.Package) {
340340
continue
341341
}
342342

343-
if strings.HasSuffix(name, "_test.go") {
344-
base := name[:len(name)-len("_test.go")]
343+
if base, found := strings.CutSuffix(name, "_test.go"); found {
345344
allRemove = append(allRemove, base+".test", base+".test.exe")
346345
}
347346

348-
if strings.HasSuffix(name, ".go") {
347+
if base, found := strings.CutSuffix(name, ".go"); found {
349348
// TODO(adg,rsc): check that this .go file is actually
350349
// in "package main", and therefore capable of building
351350
// to an executable file.
352-
base := name[:len(name)-len(".go")]
353351
allRemove = append(allRemove, base, base+".exe")
354352
}
355353
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3115,10 +3115,10 @@ func PackagesAndErrorsOutsideModule(ctx context.Context, opts PackageOpts, args
31153115
}
31163116
patterns := make([]string, len(args))
31173117
for i, arg := range args {
3118-
if !strings.HasSuffix(arg, "@"+version) {
3118+
p, found := strings.CutSuffix(arg, "@"+version)
3119+
if !found {
31193120
return nil, fmt.Errorf("%s: all arguments must refer to packages in the same module at the same version (@%s)", arg, version)
31203121
}
3121-
p := arg[:len(arg)-len(version)-1]
31223122
switch {
31233123
case build.IsLocalImport(p):
31243124
return nil, fmt.Errorf("%s: argument must be a package path, not a relative path", arg)

0 commit comments

Comments
 (0)