Commit a0530c2f71 for golang

commit a0530c2f71eb4b744aa6e1c792b4629ff7663d58
Author: Cristian Girlea <cristiangirlea@gmail.com>
Date:   Wed Oct 7 08:19:23 2026 +0000

    cmd/go: describe when go work use adds and removes directives

    The go work use documentation says that a use directive is added for
    an argument directory that exists and removed for one that does not.
    A directive is actually added or removed depending on whether the
    directory contains a go.mod file, and since CL 394154 an argument
    that is not an existing directory is an error. Only -r removes
    directives for directories that no longer exist. The text also had a
    stray "go.work file" after "command line".

    Describe the actual behavior.

    Fixes #81807

    Change-Id: I522cb35cfff205406198f2ce19ec738f72ab59f6
    GitHub-Last-Rev: 5995b73f2287dfe07ac8c543d19b16f27424910b
    GitHub-Pull-Request: golang/go#81940
    Reviewed-on: https://go-review.googlesource.com/c/go/+/843145
    Reviewed-by: Sean Liao <sean@liao.dev>
    Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
    LUCI-TryBot-Result: golang-scoped@luci-project-accounts.iam.gserviceaccount.com <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
    Reviewed-by: David Chase <drchase@google.com>
    Auto-Submit: Sean Liao <sean@liao.dev>

diff --git a/src/cmd/go/alldocs.go b/src/cmd/go/alldocs.go
index 893cbad7b8..471fd4c3a4 100644
--- a/src/cmd/go/alldocs.go
+++ b/src/cmd/go/alldocs.go
@@ -2069,10 +2069,10 @@
 // directories, optionally recursively, to a go.work file.
 //
 // A use directive will be added to the go.work file for each argument
-// directory listed on the command line go.work file, if it exists,
-// or removed from the go.work file if it does not exist.
-// Use fails if any remaining use directives refer to modules that
-// do not exist.
+// directory listed on the command line that contains a go.mod file,
+// or removed from the go.work file if the directory has no go.mod file.
+// Use fails if an argument is not an existing directory, or if any
+// remaining use directives refer to modules that do not exist.
 //
 // Use updates the go line in go.work to specify a version at least as
 // new as all the go lines in the used modules, both preexisting ones
@@ -2081,8 +2081,9 @@
 //
 // The -r flag searches recursively for modules in the argument
 // directories, and the use command operates as if each of the directories
-// were specified as arguments. When -r is used, symlinks to directories
-// within the argument tree are ignored.
+// were specified as arguments. Use directives for directories within
+// the argument tree that no longer exist are removed. When -r is used,
+// symlinks to directories within the argument tree are ignored.
 //
 // The go command matches use paths to module directories without resolving
 // symbolic links. A use directive that names a symlink to a directory is
diff --git a/src/cmd/go/internal/workcmd/use.go b/src/cmd/go/internal/workcmd/use.go
index af9aff4fd8..deb71acd20 100644
--- a/src/cmd/go/internal/workcmd/use.go
+++ b/src/cmd/go/internal/workcmd/use.go
@@ -30,10 +30,10 @@ var cmdUse = &base.Command{
 directories, optionally recursively, to a go.work file.

 A use directive will be added to the go.work file for each argument
-directory listed on the command line go.work file, if it exists,
-or removed from the go.work file if it does not exist.
-Use fails if any remaining use directives refer to modules that
-do not exist.
+directory listed on the command line that contains a go.mod file,
+or removed from the go.work file if the directory has no go.mod file.
+Use fails if an argument is not an existing directory, or if any
+remaining use directives refer to modules that do not exist.

 Use updates the go line in go.work to specify a version at least as
 new as all the go lines in the used modules, both preexisting ones
@@ -42,8 +42,9 @@ thing that go work use does.

 The -r flag searches recursively for modules in the argument
 directories, and the use command operates as if each of the directories
-were specified as arguments. When -r is used, symlinks to directories
-within the argument tree are ignored.
+were specified as arguments. Use directives for directories within
+the argument tree that no longer exist are removed. When -r is used,
+symlinks to directories within the argument tree are ignored.

 The go command matches use paths to module directories without resolving
 symbolic links. A use directive that names a symlink to a directory is