Repository: google/wire
Pull request #360 (2022-05-19 22:31:45)

Update dependencies to support Generics
Hello! First of all, thanks for this project. It is very helpful and makes dependency injection a breeze.

We've experience some problems working with wire and generics (as I think other people has experienced too according to #354)

I dont know for sure if these changes added full support for generics but I've managed to fix all the issues I had in my projects.

Mainly, I had to update the dependencies to use `golang.org/x/tools@v0.1.10`

The main issue was here:
https://github.com/golang/tools/blob/master/go/ast/astutil/rewrite.go#L255
that was included in [this commit](https://github.com/golang/tools/commit/942994fc75ba3b8f8cbe2f1898518dcaa2aea50d)

this is a version adapted from the tutorial that works only with the updated version:

```
// main.go
package main

import (
	"errors"
	"fmt"
	"os"
	"time"
)

// Message is what greeters will use to greet guests.
type Message string

type Resolver[K comparable, V any] struct {
	store map[K]V
}

func NewResolver[K comparable, V any]() Resolver[K, V] {
	return Resolver[K, V]{
		store: map[K]V{},
	}
}

func (o Resolver[K, V]) Resolve(key K) (V, error) {
	val, exists := o.store[key]
	if !exists {
		return val, errors.New("not found")
	}

	return val, nil
}

func (o Resolver[K, V]) Add(key K, val V) {
	o.store[key] = val
}

// NewMessage creates a default Message.
func NewMessage(phrase string) Message {
	return Message(phrase)
}

// NewGreeter initializes a Greeter. If the current epoch time is an even
// number, NewGreeter will create a grumpy Greeter.
func NewGreeter(m Resolver[bool, Message]) Greeter {
	var grumpy bool
	if time.Now().Unix()%2 == 0 {
		grumpy = true
	}
	return Greeter{MessageResolver: m, Grumpy: grumpy}
}

// Greeter is the type charged with greeting guests.
type Greeter struct {
	Grumpy          bool
	MessageResolver Resolver[bool, Message]
}

// Greet produces a greeting for guests.
func (g Greeter) Greet() Message {
	m, err := g.MessageResolver.Resolve(g.Grumpy)
	if err != nil {
		return Message("not found")
	}
	return m
}

// NewEvent creates an event with the specified greeter.
func NewEvent(g Greeter) (Event, error) {
	if g.Grumpy {
		return Event{}, errors.New("could not create event: event greeter is grumpy")
	}
	return Event{Greeter: g}, nil
}

// Event is a gathering with greeters.
type Event struct {
	Greeter Greeter
}

// Start ensures the event starts with greeting all guests.
func (e Event) Start() {
	msg := e.Greeter.Greet()
	fmt.Println(msg)
}

func main() {
	e, err := InitializeEvent("hi there!")
	if err != nil {
		fmt.Printf("failed to create event: %s\n", err)
		os.Exit(2)
	}
	e.Start()
}
```
```
// wire.go
package main

import "github.com/google/wire"

func getMessageResolver() Resolver[bool, Message] {
	r := NewResolver[bool, Message]()
	r.Add(false, Message("happy false"))
	r.Add(true, Message("grumpy true"))
	return r
}

// InitializeEvent creates an Event. It will error if the Event is staffed with
// a grumpy greeter.
func InitializeEvent(phrase string) (Event, error) {
	wire.Build(NewEvent, NewGreeter, getMessageResolver)
	return Event{}, nil
}
```









google-cla[bot]: Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

For more information, open the [CLA check for this pull request](https://github.com/google/wire/pull/360/checks?check_run_id=6516021511).
efueyo: > Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).
> 
> For more information, open the [CLA check for this pull request](https://github.com/google/wire/pull/360/checks?check_run_id=6516021511).

signed  ⚡ ✍️ 
efueyo: Great @jayzhuang . should we merge this PR or wait until the whole functionality is there? (I'm now working with my forked repo and would love to come back to using the original `go install github.com/google/wire` instead of `git clone + go install .`)
jayzhuang: Hey Enrique, I'm supportive of merging this PR, but I don't have write access. @stytchiz can you take a look?

Patch:
diff --git a/_tutorial/README.md b/_tutorial/README.md
index cfccde1..f39fba2 100644
--- a/_tutorial/README.md
+++ b/_tutorial/README.md
@@ -163,7 +163,7 @@ injector complete, we are ready to use the `wire` command line tool.
 Install the tool with:
 
 ``` shell
-go get github.com/google/wire/cmd/wire
+go install github.com/google/wire/cmd/wire@latest
 ```
 
 Then in the same directory with the above code, simply run `wire`. Wire will
diff --git a/_tutorial/wire_gen.go b/_tutorial/wire_gen.go
index 7a93a7b..fe54ab7 100644
--- a/_tutorial/wire_gen.go
+++ b/_tutorial/wire_gen.go
@@ -1,6 +1,6 @@
 // Code generated by Wire. DO NOT EDIT.
 
-//go:generate go run github.com/google/wire/cmd/wire
+//go:generate go run -mod=mod github.com/google/wire/cmd/wire
 //go:build !wireinject
 // +build !wireinject
 
diff --git a/docs/guide.md b/docs/guide.md
index dc1b42e..530650a 100644
--- a/docs/guide.md
+++ b/docs/guide.md
@@ -151,7 +151,7 @@ Wire will produce an implementation of the injector in a file called
 ```go
 // Code generated by Wire. DO NOT EDIT.
 
-//go:generate go run github.com/google/wire/cmd/wire
+//go:generate go run -mod=mod github.com/google/wire/cmd/wire
 //+build !wireinject
 
 package main
diff --git a/go.mod b/go.mod
index 7335ae1..aa12806 100644
--- a/go.mod
+++ b/go.mod
@@ -6,7 +6,5 @@ require (
 	github.com/google/go-cmp v0.2.0
 	github.com/google/subcommands v1.2.0
 	github.com/pmezard/go-difflib v1.0.0
-	golang.org/x/mod v0.4.1 // indirect
-	golang.org/x/sys v0.0.0-20210216224549-f992740a1bac // indirect
-	golang.org/x/tools v0.1.0
+	golang.org/x/tools v0.1.10
 )
diff --git a/go.sum b/go.sum
index ff9cc31..1e80ef8 100644
--- a/go.sum
+++ b/go.sum
@@ -4,30 +4,31 @@ github.com/google/subcommands v1.2.0 h1:vWQspBTo2nEqTUFita5/KeEWlUL8kQObDFbub/EN
 github.com/google/subcommands v1.2.0/go.mod h1:ZjhPrFU+Olkh9WazFPsl27BQ4UPiG37m3yTrtFlrHVk=
 github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
 github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
-github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
+github.com/yuin/goldmark v1.4.1/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
 golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
-golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
-golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
-golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
-golang.org/x/mod v0.4.1 h1:Kvvh58BN8Y9/lBi7hTekvtMpm07eUZ0ck5pRHpsMWrY=
-golang.org/x/mod v0.4.1/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
-golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
+golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
+golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3 h1:kQgndtyPBW/JIYERgdxfwMYh3AVStj88WQTlNDi2a+o=
+golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3/go.mod h1:3p9vT2HGsQu2K1YbXdKPJLVgG5VJdoTa1poYQBtP1AY=
 golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
-golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
+golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
+golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
 golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
-golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
+golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
 golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
-golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
-golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
-golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
-golang.org/x/sys v0.0.0-20210216224549-f992740a1bac h1:9glrpwtNjBYgRpb67AZJKHfzj1stG/8BL5H7In2oTC4=
-golang.org/x/sys v0.0.0-20210216224549-f992740a1bac/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
+golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
+golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
+golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
+golang.org/x/sys v0.0.0-20211019181941-9d821ace8654 h1:id054HUawV2/6IGm2IV8KZQjqtwAOo2CYlOToYqa0d0=
+golang.org/x/sys v0.0.0-20211019181941-9d821ace8654/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
+golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
 golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
 golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
+golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
+golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
 golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
 golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
-golang.org/x/tools v0.1.0 h1:po9/4sTYwZU9lPhi1tOrb4hCv3qrhiQ77LZfGa2OjwY=
-golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0=
+golang.org/x/tools v0.1.10 h1:QjFRCZxdOhBJ/UNgnBZLbNV13DlbnK0quyivTnXJM20=
+golang.org/x/tools v0.1.10/go.mod h1:Uh6Zz+xoGYZom868N8YTex3t7RhtHDBrE8Gzo9bV56E=
 golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
 golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
 golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
diff --git a/internal/wire/copyast.go b/internal/wire/copyast.go
index 179d1c6..9ec63d7 100644
--- a/internal/wire/copyast.go
+++ b/internal/wire/copyast.go
@@ -263,6 +263,13 @@ func copyAST(original ast.Node) ast.Node {
 				Index:  exprFromMap(m, node.Index),
 				Rbrack: node.Rbrack,
 			}
+		case *ast.IndexListExpr:
+			m[node] = &ast.IndexListExpr{
+				X:       exprFromMap(m, node.X),
+				Lbrack:  node.Lbrack,
+				Indices: copyExprList(m, node.Indices),
+				Rbrack:  node.Rbrack,
+			}
 		case *ast.InterfaceType:
 			m[node] = &ast.InterfaceType{
 				Interface:  node.Interface,
diff --git a/internal/wire/wire.go b/internal/wire/wire.go
index a9b7a50..5cedeb1 100644
--- a/internal/wire/wire.go
+++ b/internal/wire/wire.go
@@ -267,7 +267,7 @@ func (g *gen) frame(tags string) []byte {
 		tags = fmt.Sprintf(" gen -tags \"%s\"", tags)
 	}
 	buf.WriteString("// Code generated by Wire. DO NOT EDIT.\n\n")
-	buf.WriteString("//go:generate go run github.com/google/wire/cmd/wire" + tags + "\n")
+	buf.WriteString("//go:generate go run -mod=mod github.com/google/wire/cmd/wire" + tags + "\n")
 	buf.WriteString("//+build !wireinject\n\n")
 	buf.WriteString("package ")
 	buf.WriteString(g.pkg.Name)


Test patch:
diff --git a/internal/wire/testdata/BindInjectorArg/want/wire_gen.go b/internal/wire/testdata/BindInjectorArg/want/wire_gen.go
index 25ce723..5f5b210 100644
--- a/internal/wire/testdata/BindInjectorArg/want/wire_gen.go
+++ b/internal/wire/testdata/BindInjectorArg/want/wire_gen.go
@@ -1,6 +1,6 @@
 // Code generated by Wire. DO NOT EDIT.
 
-//go:generate go run github.com/google/wire/cmd/wire
+//go:generate go run -mod=mod github.com/google/wire/cmd/wire
 //go:build !wireinject
 // +build !wireinject
 
diff --git a/internal/wire/testdata/BindInjectorArgPointer/want/wire_gen.go b/internal/wire/testdata/BindInjectorArgPointer/want/wire_gen.go
index 20a9f53..15d6f0e 100644
--- a/internal/wire/testdata/BindInjectorArgPointer/want/wire_gen.go
+++ b/internal/wire/testdata/BindInjectorArgPointer/want/wire_gen.go
@@ -1,6 +1,6 @@
 // Code generated by Wire. DO NOT EDIT.
 
-//go:generate go run github.com/google/wire/cmd/wire
+//go:generate go run -mod=mod github.com/google/wire/cmd/wire
 //go:build !wireinject
 // +build !wireinject
 
diff --git a/internal/wire/testdata/BindInterfaceWithValue/want/wire_gen.go b/internal/wire/testdata/BindInterfaceWithValue/want/wire_gen.go
index b6255e1..58d82bf 100644
--- a/internal/wire/testdata/BindInterfaceWithValue/want/wire_gen.go
+++ b/internal/wire/testdata/BindInterfaceWithValue/want/wire_gen.go
@@ -1,6 +1,6 @@
 // Code generated by Wire. DO NOT EDIT.
 
-//go:generate go run github.com/google/wire/cmd/wire
+//go:generate go run -mod=mod github.com/google/wire/cmd/wire
 //go:build !wireinject
 // +build !wireinject
 
diff --git a/internal/wire/testdata/BuildTagsAllPackages/want/wire_gen.go b/internal/wire/testdata/BuildTagsAllPackages/want/wire_gen.go
index f75adb5..16c0df2 100644
--- a/internal/wire/testdata/BuildTagsAllPackages/want/wire_gen.go
+++ b/internal/wire/testdata/BuildTagsAllPackages/want/wire_gen.go
@@ -1,6 +1,6 @@
 // Code generated by Wire. DO NOT EDIT.
 
-//go:generate go run github.com/google/wire/cmd/wire
+//go:generate go run -mod=mod github.com/google/wire/cmd/wire
 //go:build !wireinject
 // +build !wireinject
 
diff --git a/internal/wire/testdata/Chain/want/wire_gen.go b/internal/wire/testdata/Chain/want/wire_gen.go
index 257e642..cf9e9ee 100644
--- a/internal/wire/testdata/Chain/want/wire_gen.go
+++ b/internal/wire/testdata/Chain/want/wire_gen.go
@@ -1,6 +1,6 @@
 // Code generated by Wire. DO NOT EDIT.
 
-//go:generate go run github.com/google/wire/cmd/wire
+//go:generate go run -mod=mod github.com/google/wire/cmd/wire
 //go:build !wireinject
 // +build !wireinject
 
diff --git a/internal/wire/testdata/Cleanup/want/wire_gen.go b/internal/wire/testdata/Cleanup/want/wire_gen.go
index eea8b22..1519c10 100644
--- a/internal/wire/testdata/Cleanup/want/wire_gen.go
+++ b/internal/wire/testdata/Cleanup/want/wire_gen.go
@@ -1,6 +1,6 @@
 // Code generated by Wire. DO NOT EDIT.
 
-//go:generate go run github.com/google/wire/cmd/wire
+//go:generate go run -mod=mod github.com/google/wire/cmd/wire
 //go:build !wireinject
 // +build !wireinject
 
diff --git a/internal/wire/testdata/CopyOtherDecls/want/wire_gen.go b/internal/wire/testdata/CopyOtherDecls/want/wire_gen.go
index 3dcb4b5..c654540 100644
--- a/internal/wire/testdata/CopyOtherDecls/want/wire_gen.go
+++ b/internal/wire/testdata/CopyOtherDecls/want/wire_gen.go
@@ -1,6 +1,6 @@
 // Code generated by Wire. DO NOT EDIT.
 
-//go:generate go run github.com/google/wire/cmd/wire
+//go:generate go run -mod=mod github.com/google/wire/cmd/wire
 //go:build !wireinject
 // +build !wireinject
 
diff --git a/internal/wire/testdata/DocComment/want/wire_gen.go b/internal/wire/testdata/DocComment/want/wire_gen.go
index a1027b9..3efb22a 100644
--- a/internal/wire/testdata/DocComment/want/wire_gen.go
+++ b/internal/wire/testdata/DocComment/want/wire_gen.go
@@ -1,6 +1,6 @@
 // Code generated by Wire. DO NOT EDIT.
 
-//go:generate go run github.com/google/wire/cmd/wire
+//go:generate go run -mod=mod github.com/google/wire/cmd/wire
 //go:build !wireinject
 // +build !wireinject
 
diff --git a/internal/wire/testdata/ExampleWithMocks/want/wire_gen.go b/internal/wire/testdata/ExampleWithMocks/want/wire_gen.go
index 9f2fd0f..9cb7b01 100644
--- a/internal/wire/testdata/ExampleWithMocks/want/wire_gen.go
+++ b/internal/wire/testdata/ExampleWithMocks/want/wire_gen.go
@@ -1,6 +1,6 @@
 // Code generated by Wire. DO NOT EDIT.
 
-//go:generate go run github.com/google/wire/cmd/wire
+//go:generate go run -mod=mod github.com/google/wire/cmd/wire
 //go:build !wireinject
 // +build !wireinject
 
diff --git a/internal/wire/testdata/ExportedValue/want/wire_gen.go b/internal/wire/testdata/ExportedValue/want/wire_gen.go
index d3ba454..7563ca2 100644
--- a/internal/wire/testdata/ExportedValue/want/wire_gen.go
+++ b/internal/wire/testdata/ExportedValue/want/wire_gen.go
@@ -1,6 +1,6 @@
 // Code generated by Wire. DO NOT EDIT.
 
-//go:generate go run github.com/google/wire/cmd/wire
+//go:generate go run -mod=mod github.com/google/wire/cmd/wire
 //go:build !wireinject
 // +build !wireinject
 
diff --git a/internal/wire/testdata/ExportedValueDifferentPackage/want/wire_gen.go b/internal/wire/testdata/ExportedValueDifferentPackage/want/wire_gen.go
index d8bdd24..d8c74d4 100644
--- a/internal/wire/testdata/ExportedValueDifferentPackage/want/wire_gen.go
+++ b/internal/wire/testdata/ExportedValueDifferentPackage/want/wire_gen.go
@@ -1,6 +1,6 @@
 // Code generated by Wire. DO NOT EDIT.
 
-//go:generate go run github.com/google/wire/cmd/wire
+//go:generate go run -mod=mod github.com/google/wire/cmd/wire
 //go:build !wireinject
 // +build !wireinject
 
diff --git a/internal/wire/testdata/FieldsOfImportedStruct/want/wire_gen.go b/internal/wire/testdata/FieldsOfImportedStruct/want/wire_gen.go
index fbdc062..8467ee3 100644
--- a/internal/wire/testdata/FieldsOfImportedStruct/want/wire_gen.go
+++ b/internal/wire/testdata/FieldsOfImportedStruct/want/wire_gen.go
@@ -1,6 +1,6 @@
 // Code generated by Wire. DO NOT EDIT.
 
-//go:generate go run github.com/google/wire/cmd/wire
+//go:generate go run -mod=mod github.com/google/wire/cmd/wire
 //go:build !wireinject
 // +build !wireinject
 
diff --git a/internal/wire/testdata/FieldsOfStruct/want/wire_gen.go b/internal/wire/testdata/FieldsOfStruct/want/wire_gen.go
index c27e6d0..5b8ca2f 100644
--- a/internal/wire/testdata/FieldsOfStruct/want/wire_gen.go
+++ b/internal/wire/testdata/FieldsOfStruct/want/wire_gen.go
@@ -1,6 +1,6 @@
 // Code generated by Wire. DO NOT EDIT.
 
-//go:generate go run github.com/google/wire/cmd/wire
+//go:generate go run -mod=mod github.com/google/wire/cmd/wire
 //go:build !wireinject
 // +build !wireinject
 
diff --git a/internal/wire/testdata/FieldsOfStructPointer/want/wire_gen.go b/internal/wire/testdata/FieldsOfStructPointer/want/wire_gen.go
index 6a03e81..c9fe795 100644
--- a/internal/wire/testdata/FieldsOfStructPointer/want/wire_gen.go
+++ b/internal/wire/testdata/FieldsOfStructPointer/want/wire_gen.go
@@ -1,6 +1,6 @@
 // Code generated by Wire. DO NOT EDIT.
 
-//go:generate go run github.com/google/wire/cmd/wire
+//go:generate go run -mod=mod github.com/google/wire/cmd/wire
 //go:build !wireinject
 // +build !wireinject
 
diff --git a/internal/wire/testdata/FieldsOfValueStruct/want/wire_gen.go b/internal/wire/testdata/FieldsOfValueStruct/want/wire_gen.go
index 5b61dfe..793c04d 100644
--- a/internal/wire/testdata/FieldsOfValueStruct/want/wire_gen.go
+++ b/internal/wire/testdata/FieldsOfValueStruct/want/wire_gen.go
@@ -1,6 +1,6 @@
 // Code generated by Wire. DO NOT EDIT.
 
-//go:generate go run github.com/google/wire/cmd/wire
+//go:generate go run -mod=mod github.com/google/wire/cmd/wire
 //go:build !wireinject
 // +build !wireinject
 
diff --git a/internal/wire/testdata/Header/want/wire_gen.go b/internal/wire/testdata/Header/want/wire_gen.go
index 3ab2107..2f8c5c6 100644
--- a/internal/wire/testdata/Header/want/wire_gen.go
+++ b/internal/wire/testdata/Header/want/wire_gen.go
@@ -2,7 +2,7 @@
 //
 // Code generated by Wire. DO NOT EDIT.
 
-//go:generate go run github.com/google/wire/cmd/wire
+//go:generate go run -mod=mod github.com/google/wire/cmd/wire
 //go:build !wireinject
 // +build !wireinject
 
diff --git a/internal/wire/testdata/ImportedInterfaceBinding/want/wire_gen.go b/internal/wire/testdata/ImportedInterfaceBinding/want/wire_gen.go
index 6a7cd42..b68a1db 100644
--- a/internal/wire/testdata/ImportedInterfaceBinding/want/wire_gen.go
+++ b/internal/wire/testdata/ImportedInterfaceBinding/want/wire_gen.go
@@ -1,6 +1,6 @@
 // Code generated by Wire. DO NOT EDIT.
 
-//go:generate go run github.com/google/wire/cmd/wire
+//go:generate go run -mod=mod github.com/google/wire/cmd/wire
 //go:build !wireinject
 // +build !wireinject
 
diff --git a/internal/wire/testdata/InjectInput/want/wire_gen.go b/internal/wire/testdata/InjectInput/want/wire_gen.go
index c17559c..9471cf6 100644
--- a/internal/wire/testdata/InjectInput/want/wire_gen.go
+++ b/internal/wire/testdata/InjectInput/want/wire_gen.go
@@ -1,6 +1,6 @@
 // Code generated by Wire. DO NOT EDIT.
 
-//go:generate go run github.com/google/wire/cmd/wire
+//go:generate go run -mod=mod github.com/google/wire/cmd/wire
 //go:build !wireinject
 // +build !wireinject
 
diff --git a/internal/wire/testdata/InjectWithPanic/want/wire_gen.go b/internal/wire/testdata/InjectWithPanic/want/wire_gen.go
index 92cb390..8b124e5 100644
--- a/internal/wire/testdata/InjectWithPanic/want/wire_gen.go
+++ b/internal/wire/testdata/InjectWithPanic/want/wire_gen.go
@@ -1,6 +1,6 @@
 // Code generated by Wire. DO NOT EDIT.
 
-//go:generate go run github.com/google/wire/cmd/wire
+//go:generate go run -mod=mod github.com/google/wire/cmd/wire
 //go:build !wireinject
 // +build !wireinject
 
diff --git a/internal/wire/testdata/InterfaceBinding/want/wire_gen.go b/internal/wire/testdata/InterfaceBinding/want/wire_gen.go
index f1d7f17..2c1a67b 100644
--- a/internal/wire/testdata/InterfaceBinding/want/wire_gen.go
+++ b/internal/wire/testdata/InterfaceBinding/want/wire_gen.go
@@ -1,6 +1,6 @@
 // Code generated by Wire. DO NOT EDIT.
 
-//go:generate go run github.com/google/wire/cmd/wire
+//go:generate go run -mod=mod github.com/google/wire/cmd/wire
 //go:build !wireinject
 // +build !wireinject
 
diff --git a/internal/wire/testdata/InterfaceBindingReuse/want/wire_gen.go b/internal/wire/testdata/InterfaceBindingReuse/want/wire_gen.go
index bff6877..1c43771 100644
--- a/internal/wire/testdata/InterfaceBindingReuse/want/wire_gen.go
+++ b/internal/wire/testdata/InterfaceBindingReuse/want/wire_gen.go
@@ -1,6 +1,6 @@
 // Code generated by Wire. DO NOT EDIT.
 
-//go:generate go run github.com/google/wire/cmd/wire
+//go:generate go run -mod=mod github.com/google/wire/cmd/wire
 //go:build !wireinject
 // +build !wireinject
 
diff --git a/internal/wire/testdata/InterfaceValue/want/wire_gen.go b/internal/wire/testdata/InterfaceValue/want/wire_gen.go
index 0cc1e8c..9868a90 100644
--- a/internal/wire/testdata/InterfaceValue/want/wire_gen.go
+++ b/internal/wire/testdata/InterfaceValue/want/wire_gen.go
@@ -1,6 +1,6 @@
 // Code generated by Wire. DO NOT EDIT.
 
-//go:generate go run github.com/google/wire/cmd/wire
+//go:generate go run -mod=mod github.com/google/wire/cmd/wire
 //go:build !wireinject
 // +build !wireinject
 
diff --git a/internal/wire/testdata/MultipleSimilarPackages/want/wire_gen.go b/internal/wire/testdata/MultipleSimilarPackages/want/wire_gen.go
index a43b6e4..e406820 100644
--- a/internal/wire/testdata/MultipleSimilarPackages/want/wire_gen.go
+++ b/internal/wire/testdata/MultipleSimilarPackages/want/wire_gen.go
@@ -1,6 +1,6 @@
 // Code generated by Wire. DO NOT EDIT.
 
-//go:generate go run github.com/google/wire/cmd/wire
+//go:generate go run -mod=mod github.com/google/wire/cmd/wire
 //go:build !wireinject
 // +build !wireinject
 
diff --git a/internal/wire/testdata/NamingWorstCase/want/wire_gen.go b/internal/wire/testdata/NamingWorstCase/want/wire_gen.go
index 23dd8fa..e32329d 100644
--- a/internal/wire/testdata/NamingWorstCase/want/wire_gen.go
+++ b/internal/wire/testdata/NamingWorstCase/want/wire_gen.go
@@ -1,6 +1,6 @@
 // Code generated by Wire. DO NOT EDIT.
 
-//go:generate go run github.com/google/wire/cmd/wire
+//go:generate go run -mod=mod github.com/google/wire/cmd/wire
 //go:build !wireinject
 // +build !wireinject
 
diff --git a/internal/wire/testdata/NamingWorstCaseAllInOne/want/wire_gen.go b/internal/wire/testdata/NamingWorstCaseAllInOne/want/wire_gen.go
index dac690d..c081520 100644
--- a/internal/wire/testdata/NamingWorstCaseAllInOne/want/wire_gen.go
+++ b/internal/wire/testdata/NamingWorstCaseAllInOne/want/wire_gen.go
@@ -1,6 +1,6 @@
 // Code generated by Wire. DO NOT EDIT.
 
-//go:generate go run github.com/google/wire/cmd/wire
+//go:generate go run -mod=mod github.com/google/wire/cmd/wire
 //go:build !wireinject
 // +build !wireinject
 
diff --git a/internal/wire/testdata/NiladicIdentity/want/wire_gen.go b/internal/wire/testdata/NiladicIdentity/want/wire_gen.go
index 92cb390..8b124e5 100644
--- a/internal/wire/testdata/NiladicIdentity/want/wire_gen.go
+++ b/internal/wire/testdata/NiladicIdentity/want/wire_gen.go
@@ -1,6 +1,6 @@
 // Code generated by Wire. DO NOT EDIT.
 
-//go:generate go run github.com/google/wire/cmd/wire
+//go:generate go run -mod=mod github.com/google/wire/cmd/wire
 //go:build !wireinject
 // +build !wireinject
 
diff --git a/internal/wire/testdata/NiladicValue/want/wire_gen.go b/internal/wire/testdata/NiladicValue/want/wire_gen.go
index f75adb5..16c0df2 100644
--- a/internal/wire/testdata/NiladicValue/want/wire_gen.go
+++ b/internal/wire/testdata/NiladicValue/want/wire_gen.go
@@ -1,6 +1,6 @@
 // Code generated by Wire. DO NOT EDIT.
 
-//go:generate go run github.com/google/wire/cmd/wire
+//go:generate go run -mod=mod github.com/google/wire/cmd/wire
 //go:build !wireinject
 // +build !wireinject
 
diff --git a/internal/wire/testdata/NoInjectParamNames/want/wire_gen.go b/internal/wire/testdata/NoInjectParamNames/want/wire_gen.go
index c943b5c..b8760db 100644
--- a/internal/wire/testdata/NoInjectParamNames/want/wire_gen.go
+++ b/internal/wire/testdata/NoInjectParamNames/want/wire_gen.go
@@ -1,6 +1,6 @@
 // Code generated by Wire. DO NOT EDIT.
 
-//go:generate go run github.com/google/wire/cmd/wire
+//go:generate go run -mod=mod github.com/google/wire/cmd/wire
 //go:build !wireinject
 // +build !wireinject
 
diff --git a/internal/wire/testdata/PartialCleanup/want/wire_gen.go b/internal/wire/testdata/PartialCleanup/want/wire_gen.go
index a3ef6a4..6cf2640 100644
--- a/internal/wire/testdata/PartialCleanup/want/wire_gen.go
+++ b/internal/wire/testdata/PartialCleanup/want/wire_gen.go
@@ -1,6 +1,6 @@
 // Code generated by Wire. DO NOT EDIT.
 
-//go:generate go run github.com/google/wire/cmd/wire
+//go:generate go run -mod=mod github.com/google/wire/cmd/wire
 //go:build !wireinject
 // +build !wireinject
 
diff --git a/internal/wire/testdata/PkgImport/want/wire_gen.go b/internal/wire/testdata/PkgImport/want/wire_gen.go
index 7dbc469..5f3e127 100644
--- a/internal/wire/testdata/PkgImport/want/wire_gen.go
+++ b/internal/wire/testdata/PkgImport/want/wire_gen.go
@@ -1,6 +1,6 @@
 // Code generated by Wire. DO NOT EDIT.
 
-//go:generate go run github.com/google/wire/cmd/wire
+//go:generate go run -mod=mod github.com/google/wire/cmd/wire
 //go:build !wireinject
 // +build !wireinject
 
diff --git a/internal/wire/testdata/RelativePkg/want/wire_gen.go b/internal/wire/testdata/RelativePkg/want/wire_gen.go
index 92cb390..8b124e5 100644
--- a/internal/wire/testdata/RelativePkg/want/wire_gen.go
+++ b/internal/wire/testdata/RelativePkg/want/wire_gen.go
@@ -1,6 +1,6 @@
 // Code generated by Wire. DO NOT EDIT.
 
-//go:generate go run github.com/google/wire/cmd/wire
+//go:generate go run -mod=mod github.com/google/wire/cmd/wire
 //go:build !wireinject
 // +build !wireinject
 
diff --git a/internal/wire/testdata/ReservedKeywords/want/wire_gen.go b/internal/wire/testdata/ReservedKeywords/want/wire_gen.go
index a8a6ae7..7ff3110 100644
--- a/internal/wire/testdata/ReservedKeywords/want/wire_gen.go
+++ b/internal/wire/testdata/ReservedKeywords/want/wire_gen.go
@@ -1,6 +1,6 @@
 // Code generated by Wire. DO NOT EDIT.
 
-//go:generate go run github.com/google/wire/cmd/wire
+//go:generate go run -mod=mod github.com/google/wire/cmd/wire
 //go:build !wireinject
 // +build !wireinject
 
diff --git a/internal/wire/testdata/ReturnArgumentAsInterface/want/wire_gen.go b/internal/wire/testdata/ReturnArgumentAsInterface/want/wire_gen.go
index 5d73b54..9d1a331 100644
--- a/internal/wire/testdata/ReturnArgumentAsInterface/want/wire_gen.go
+++ b/internal/wire/testdata/ReturnArgumentAsInterface/want/wire_gen.go
@@ -1,6 +1,6 @@
 // Code generated by Wire. DO NOT EDIT.
 
-//go:generate go run github.com/google/wire/cmd/wire
+//go:generate go run -mod=mod github.com/google/wire/cmd/wire
 //go:build !wireinject
 // +build !wireinject
 
diff --git a/internal/wire/testdata/ReturnError/want/wire_gen.go b/internal/wire/testdata/ReturnError/want/wire_gen.go
index 6a75977..5d97466 100644
--- a/internal/wire/testdata/ReturnError/want/wire_gen.go
+++ b/internal/wire/testdata/ReturnError/want/wire_gen.go
@@ -1,6 +1,6 @@
 // Code generated by Wire. DO NOT EDIT.
 
-//go:generate go run github.com/google/wire/cmd/wire
+//go:generate go run -mod=mod github.com/google/wire/cmd/wire
 //go:build !wireinject
 // +build !wireinject
 
diff --git a/internal/wire/testdata/Struct/want/wire_gen.go b/internal/wire/testdata/Struct/want/wire_gen.go
index 3529cb2..e4bf0c7 100644
--- a/internal/wire/testdata/Struct/want/wire_gen.go
+++ b/internal/wire/testdata/Struct/want/wire_gen.go
@@ -1,6 +1,6 @@
 // Code generated by Wire. DO NOT EDIT.
 
-//go:generate go run github.com/google/wire/cmd/wire
+//go:generate go run -mod=mod github.com/google/wire/cmd/wire
 //go:build !wireinject
 // +build !wireinject
 
diff --git a/internal/wire/testdata/StructPointer/want/wire_gen.go b/internal/wire/testdata/StructPointer/want/wire_gen.go
index 1fa1bd8..e96e8cd 100644
--- a/internal/wire/testdata/StructPointer/want/wire_gen.go
+++ b/internal/wire/testdata/StructPointer/want/wire_gen.go
@@ -1,6 +1,6 @@
 // Code generated by Wire. DO NOT EDIT.
 
-//go:generate go run github.com/google/wire/cmd/wire
+//go:generate go run -mod=mod github.com/google/wire/cmd/wire
 //go:build !wireinject
 // +build !wireinject
 
diff --git a/internal/wire/testdata/TwoDeps/want/wire_gen.go b/internal/wire/testdata/TwoDeps/want/wire_gen.go
index 29cde76..bfc52d7 100644
--- a/internal/wire/testdata/TwoDeps/want/wire_gen.go
+++ b/internal/wire/testdata/TwoDeps/want/wire_gen.go
@@ -1,6 +1,6 @@
 // Code generated by Wire. DO NOT EDIT.
 
-//go:generate go run github.com/google/wire/cmd/wire
+//go:generate go run -mod=mod github.com/google/wire/cmd/wire
 //go:build !wireinject
 // +build !wireinject
 
diff --git a/internal/wire/testdata/ValueChain/want/wire_gen.go b/internal/wire/testdata/ValueChain/want/wire_gen.go
index 9e4a669..da2cccb 100644
--- a/internal/wire/testdata/ValueChain/want/wire_gen.go
+++ b/internal/wire/testdata/ValueChain/want/wire_gen.go
@@ -1,6 +1,6 @@
 // Code generated by Wire. DO NOT EDIT.
 
-//go:generate go run github.com/google/wire/cmd/wire
+//go:generate go run -mod=mod github.com/google/wire/cmd/wire
 //go:build !wireinject
 // +build !wireinject
 
diff --git a/internal/wire/testdata/ValueConversion/want/wire_gen.go b/internal/wire/testdata/ValueConversion/want/wire_gen.go
index 9c1c4b6..b663861 100644
--- a/internal/wire/testdata/ValueConversion/want/wire_gen.go
+++ b/internal/wire/testdata/ValueConversion/want/wire_gen.go
@@ -1,6 +1,6 @@
 // Code generated by Wire. DO NOT EDIT.
 
-//go:generate go run github.com/google/wire/cmd/wire
+//go:generate go run -mod=mod github.com/google/wire/cmd/wire
 //go:build !wireinject
 // +build !wireinject
 
diff --git a/internal/wire/testdata/ValueIsStruct/want/wire_gen.go b/internal/wire/testdata/ValueIsStruct/want/wire_gen.go
index 9e0b96c..f41ed12 100644
--- a/internal/wire/testdata/ValueIsStruct/want/wire_gen.go
+++ b/internal/wire/testdata/ValueIsStruct/want/wire_gen.go
@@ -1,6 +1,6 @@
 // Code generated by Wire. DO NOT EDIT.
 
-//go:generate go run github.com/google/wire/cmd/wire
+//go:generate go run -mod=mod github.com/google/wire/cmd/wire
 //go:build !wireinject
 // +build !wireinject
 
diff --git a/internal/wire/testdata/VarValue/want/wire_gen.go b/internal/wire/testdata/VarValue/want/wire_gen.go
index 8a2bc61..07e4f01 100644
--- a/internal/wire/testdata/VarValue/want/wire_gen.go
+++ b/internal/wire/testdata/VarValue/want/wire_gen.go
@@ -1,6 +1,6 @@
 // Code generated by Wire. DO NOT EDIT.
 
-//go:generate go run github.com/google/wire/cmd/wire
+//go:generate go run -mod=mod github.com/google/wire/cmd/wire
 //go:build !wireinject
 // +build !wireinject
 
diff --git a/internal/wire/testdata/Varargs/want/wire_gen.go b/internal/wire/testdata/Varargs/want/wire_gen.go
index d6cef6a..703a549 100644
--- a/internal/wire/testdata/Varargs/want/wire_gen.go
+++ b/internal/wire/testdata/Varargs/want/wire_gen.go
@@ -1,6 +1,6 @@
 // Code generated by Wire. DO NOT EDIT.
 
-//go:generate go run github.com/google/wire/cmd/wire
+//go:generate go run -mod=mod github.com/google/wire/cmd/wire
 //go:build !wireinject
 // +build !wireinject