//go:build go1.21
// +build go1.21

// Package unsafe2 provides helpers to generate recursive struct types.
package unsafe2 import ( ) type dummy struct{} // DummyType represents a stand-in for a recursive type. var DummyType = reflect.TypeOf(dummy{}) // The following type sizes must match their original definition in Go src/internal/abi/type.go. type abiType struct { _ uintptr _ uintptr _ uint32 _ uint8 _ uint8 _ uint8 _ uint8 _ uintptr _ uintptr _ int32 _ int32 } type abiName struct { Bytes *byte } type abiStructField struct { Name abiName Typ *abiType Offset uintptr } type abiStructType struct { abiType PkgPath abiName Fields []abiStructField } type emptyInterface struct { typ *abiType _ unsafe.Pointer } // SetFieldType sets the type of the struct field at the given index, to the given type. // // The struct type must have been created at runtime. This is very unsafe. func ( reflect.Type, int, reflect.Type) { if .Kind() != reflect.Struct || >= .NumField() { return } := unpackType() := (*abiStructType)(unsafe.Pointer()) := .Fields[] .Typ = unpackType() .Fields[] = } func unpackType( reflect.Type) *abiType { := reflect.New().Elem().Interface() := *(*emptyInterface)(unsafe.Pointer(&)) return .typ }