internal/lsp: fix fillstruct for structs with unsafe.Pointer

Provide a default value for unsafe.Pointer in fillstruct.

Fixes golang/go#52640

Change-Id: I10a1878fbf53b082f83f44e0ba2788ead14439d6
Reviewed-on: https://go-review.googlesource.com/c/tools/+/403535
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Suzy Mueller <suzmue@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
Reviewed-by: David Chase <drchase@google.com>
diff --git a/internal/lsp/analysis/fillstruct/fillstruct.go b/internal/lsp/analysis/fillstruct/fillstruct.go
index 8523ae7..6987f78 100644
--- a/internal/lsp/analysis/fillstruct/fillstruct.go
+++ b/internal/lsp/analysis/fillstruct/fillstruct.go
@@ -368,6 +368,8 @@
 			return &ast.Ident{Name: "false"}
 		case u.Info()&types.IsString != 0:
 			return &ast.BasicLit{Kind: token.STRING, Value: `""`}
+		case u.Kind() == types.UnsafePointer:
+			return ast.NewIdent("nil")
 		default:
 			panic("unknown basic type")
 		}
diff --git a/internal/lsp/analysis/fillstruct/testdata/src/a/a.go b/internal/lsp/analysis/fillstruct/testdata/src/a/a.go
index f69fe83..6856009 100644
--- a/internal/lsp/analysis/fillstruct/testdata/src/a/a.go
+++ b/internal/lsp/analysis/fillstruct/testdata/src/a/a.go
@@ -8,6 +8,7 @@
 	data "b"
 	"go/ast"
 	"go/token"
+	"unsafe"
 )
 
 type emptyStruct struct{}
@@ -104,3 +105,9 @@
 
 var _ = []ast.BasicLit{{}, // want ""
 }
+
+type unsafeStruct struct {
+	foo unsafe.Pointer
+}
+
+var _ = unsafeStruct{} // want ""
diff --git a/internal/lsp/testdata/fillstruct/fill_struct_unsafe.go b/internal/lsp/testdata/fillstruct/fill_struct_unsafe.go
new file mode 100644
index 0000000..50877e9
--- /dev/null
+++ b/internal/lsp/testdata/fillstruct/fill_struct_unsafe.go
@@ -0,0 +1,12 @@
+package fillstruct
+
+import "unsafe"
+
+type unsafeStruct struct {
+	x int
+	p unsafe.Pointer
+}
+
+func fill() {
+	_ := unsafeStruct{} //@suggestedfix("}", "refactor.rewrite")
+}
diff --git a/internal/lsp/testdata/fillstruct/fill_struct_unsafe.go.golden b/internal/lsp/testdata/fillstruct/fill_struct_unsafe.go.golden
new file mode 100644
index 0000000..9936954
--- /dev/null
+++ b/internal/lsp/testdata/fillstruct/fill_struct_unsafe.go.golden
@@ -0,0 +1,17 @@
+-- suggestedfix_fill_struct_unsafe_11_20 --
+package fillstruct
+
+import "unsafe"
+
+type unsafeStruct struct {
+	x int
+	p unsafe.Pointer
+}
+
+func fill() {
+	_ := unsafeStruct{
+		x: 0,
+		p: nil,
+	} //@suggestedfix("}", "refactor.rewrite")
+}
+
diff --git a/internal/lsp/testdata/summary.txt.golden b/internal/lsp/testdata/summary.txt.golden
index 2949392..89f9579 100644
--- a/internal/lsp/testdata/summary.txt.golden
+++ b/internal/lsp/testdata/summary.txt.golden
@@ -13,7 +13,7 @@
 FormatCount = 6
 ImportCount = 8
 SemanticTokenCount = 3
-SuggestedFixCount = 61
+SuggestedFixCount = 62
 FunctionExtractionCount = 25
 MethodExtractionCount = 6
 DefinitionsCount = 95
diff --git a/internal/lsp/testdata/summary_go1.18.txt.golden b/internal/lsp/testdata/summary_go1.18.txt.golden
index f2f0eac..1b4891e 100644
--- a/internal/lsp/testdata/summary_go1.18.txt.golden
+++ b/internal/lsp/testdata/summary_go1.18.txt.golden
@@ -13,7 +13,7 @@
 FormatCount = 6
 ImportCount = 8
 SemanticTokenCount = 3
-SuggestedFixCount = 62
+SuggestedFixCount = 63
 FunctionExtractionCount = 25
 MethodExtractionCount = 6
 DefinitionsCount = 108