Repository: go
Issue: cmd/go: do not allow the main module to replace (to or from) itself
Labels: help wanted,NeedsFix,GoCommand,modules

<!-- Please answer these questions before submitting your issue. Thanks! -->

### What version of Go are you using (`go version`)?

<pre>
$ go version
go version go1.13 darwin/amd64
</pre>

This problem is also seen on Linux using go1.12.3
<pre>
$ go version
go version go1.12.3 linux/amd64
</pre>

And on Mac with the tip branch
<pre>
$ gotip version
go version devel +fe2ed50 Thu Sep 19 16:26:58 2019 +0000 darwin/amd64
</pre>

### Does this issue reproduce with the latest release?

Yes.

### What operating system and processor architecture are you using (`go env`)?

<details><summary><code>go env</code> Output</summary><br><pre>
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/rselph/Library/Caches/go-build"
GOENV="/Users/rselph/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/rselph/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/opt/local/lib/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/opt/local/lib/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="/usr/bin/clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/4w/6dmz_gmd6fj_qy_nwdwclg8c0000gp/T/go-build675848548=/tmp/go-build -gno-record-gcc-switches -fno-common"
GOROOT/bin/go version: go version go1.13 darwin/amd64
GOROOT/bin/go tool compile -V: compile version go1.13
uname -v: Darwin Kernel Version 18.7.0: Tue Aug 20 16:57:14 PDT 2019; root:xnu-4903.271.2~2/RELEASE_X86_64
ProductName:	Mac OS X
ProductVersion:	10.14.6
BuildVersion:	18G95
lldb --version: lldb-1001.0.13.3
  Swift-5.0
</pre></details>

### What did you do?

Option A:
```
$ git clone https://github.com/rselph-tibco/go-unstable-mods.git
$ cd go-unstable-mods
$ git checkout start_here
$ git switch -c new_branch
$ ./run.sh
```
The  git repository will be updated with the results of each step.  Optionally, comment out the git 
commands to simply produce the error without recording results along the way.

This is equivalent to:

1. Start with the contents of the attached file
[go-unstable-mods-start_here.tar.gz](https://github.com/golang/go/files/3633168/go-unstable-mods-start_here.tar.gz)
1. Set GOPATH and GOCACHE to point at empty directories
1. From the sample1 directory run `go mod tidy`
1. From the sample2 directory run `go mod tidy`
1. From the sample2 directory run `go install ./...`
1. From the sample1 directory run `go install ./...`
1. Repeat the last step indefinitely

At this point, sample1/go.mod will never stabilize.

### What did you expect to see?

go.mod should stabilize when the build is given the same inputs over and over.


### What did you see instead?

go.mod eventually oscillates between two states, preventing `-mod readonly` from *ever* working, and wreaking
havoc with source control.