types/ptr: deprecate ptr.To, use Go 1.26 new
Updates #18682 Change-Id: I62f6aa0de2a15ef8c1435032c6aa74a181c25f8f Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
committed by
Brad Fitzpatrick
parent
8cfbaa717d
commit
2a64c03c95
@@ -24,7 +24,6 @@ import (
|
||||
"go4.org/netipx"
|
||||
"tailscale.com/tailcfg"
|
||||
"tailscale.com/types/key"
|
||||
"tailscale.com/types/ptr"
|
||||
"tailscale.com/util/deephash/testtype"
|
||||
"tailscale.com/util/hashx"
|
||||
"tailscale.com/version"
|
||||
@@ -382,7 +381,7 @@ func TestGetTypeHasher(t *testing.T) {
|
||||
},
|
||||
{
|
||||
name: "time_ptr", // addressable, as opposed to "time" test above
|
||||
val: ptr.To(time.Unix(1234, 5678).In(time.UTC)),
|
||||
val: new(time.Unix(1234, 5678).In(time.UTC)),
|
||||
out: u8(1) + u64(1234) + u32(5678) + u32(0),
|
||||
},
|
||||
{
|
||||
@@ -412,7 +411,7 @@ func TestGetTypeHasher(t *testing.T) {
|
||||
},
|
||||
{
|
||||
name: "array_ptr_memhash",
|
||||
val: ptr.To([4]byte{1, 2, 3, 4}),
|
||||
val: new([4]byte{1, 2, 3, 4}),
|
||||
out: "\x01\x01\x02\x03\x04",
|
||||
},
|
||||
{
|
||||
@@ -640,7 +639,7 @@ var filterRules = []tailcfg.FilterRule{
|
||||
SrcIPs: []string{"*", "10.1.3.4/32", "10.0.0.0/24"},
|
||||
DstPorts: []tailcfg.NetPortRange{{
|
||||
IP: "1.2.3.4/32",
|
||||
Bits: ptr.To(32),
|
||||
Bits: new(32),
|
||||
Ports: tailcfg.PortRange{First: 1, Last: 2},
|
||||
}},
|
||||
IPProto: []int{1, 2, 3, 4},
|
||||
@@ -823,7 +822,7 @@ func TestHashThroughView(t *testing.T) {
|
||||
SSHPolicy: &sshPolicyOut{
|
||||
Rules: []tailcfg.SSHRuleView{
|
||||
(&tailcfg.SSHRule{
|
||||
RuleExpires: ptr.To(time.Unix(123, 0)),
|
||||
RuleExpires: new(time.Unix(123, 0)),
|
||||
}).View(),
|
||||
},
|
||||
},
|
||||
|
||||
@@ -20,7 +20,6 @@ import (
|
||||
"golang.org/x/sys/unix"
|
||||
"tailscale.com/net/tsaddr"
|
||||
"tailscale.com/types/logger"
|
||||
"tailscale.com/types/ptr"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -955,7 +954,7 @@ const (
|
||||
// via netfilter via nftables, as a last resort measure to detect that nftables
|
||||
// can be used. It cleans up the dummy chains after creation.
|
||||
func (n *nftablesRunner) createDummyPostroutingChains() (retErr error) {
|
||||
polAccept := ptr.To(nftables.ChainPolicyAccept)
|
||||
polAccept := new(nftables.ChainPolicyAccept)
|
||||
for _, table := range n.getTables() {
|
||||
nat, err := createTableIfNotExist(n.conn, table.Proto, tsDummyTableName)
|
||||
if err != nil {
|
||||
|
||||
+1
-3
@@ -12,8 +12,6 @@ package pool
|
||||
import (
|
||||
"fmt"
|
||||
"math/rand/v2"
|
||||
|
||||
"tailscale.com/types/ptr"
|
||||
)
|
||||
|
||||
// consistencyCheck enables additional runtime checks to ensure that the pool
|
||||
@@ -77,7 +75,7 @@ func (p *Pool[V]) AppendTakeAll(dst []V) []V {
|
||||
func (p *Pool[V]) Add(item V) Handle[V] {
|
||||
// Store the index in a pointer, so that we can pass it to both the
|
||||
// handle and store it in the itemAndIndex.
|
||||
idx := ptr.To(len(p.s))
|
||||
idx := new(len(p.s))
|
||||
p.s = append(p.s, itemAndIndex[V]{
|
||||
item: item,
|
||||
index: idx,
|
||||
|
||||
@@ -5,8 +5,6 @@ package setting
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"tailscale.com/types/ptr"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -39,7 +37,7 @@ type ErrorText string
|
||||
|
||||
// NewErrorText returns a [ErrorText] with the specified error message.
|
||||
func NewErrorText(text string) *ErrorText {
|
||||
return ptr.To(ErrorText(text))
|
||||
return new(ErrorText(text))
|
||||
}
|
||||
|
||||
// MaybeErrorText returns an [ErrorText] with the text of the specified error,
|
||||
@@ -51,7 +49,7 @@ func MaybeErrorText(err error) *ErrorText {
|
||||
if err, ok := err.(*ErrorText); ok {
|
||||
return err
|
||||
}
|
||||
return ptr.To(ErrorText(err.Error()))
|
||||
return new(ErrorText(err.Error()))
|
||||
}
|
||||
|
||||
// Error implements error.
|
||||
|
||||
@@ -9,7 +9,6 @@ import (
|
||||
"testing"
|
||||
|
||||
"tailscale.com/types/lazy"
|
||||
"tailscale.com/types/ptr"
|
||||
"tailscale.com/util/syspolicy/internal"
|
||||
"tailscale.com/util/syspolicy/pkey"
|
||||
)
|
||||
@@ -138,7 +137,7 @@ func TestSettingDefinition(t *testing.T) {
|
||||
if !tt.setting.Equal(tt.setting) {
|
||||
t.Errorf("the setting should be equal to itself")
|
||||
}
|
||||
if tt.setting != nil && !tt.setting.Equal(ptr.To(*tt.setting)) {
|
||||
if tt.setting != nil && !tt.setting.Equal(new(*tt.setting)) {
|
||||
t.Errorf("the setting should be equal to its shallow copy")
|
||||
}
|
||||
if gotKey := tt.setting.Key(); gotKey != tt.wantKey {
|
||||
|
||||
Reference in New Issue
Block a user