Skip to content

Commit

Permalink
chore: simplify ptrs.Ptr (#5330)
Browse files Browse the repository at this point in the history
Inside the function, the value is already addressable now that it has a
name, so declaring a new variable to take the address of isn't
necessary.
  • Loading branch information
dzhu authored Oct 25, 2022
1 parent 0370f54 commit 5f8c3e2
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions master/pkg/ptrs/ptrs.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package ptrs

// Ptr returns a pointer to a copy of a value. This let's you take the address of some
// non-addressible[1] values, like boolean literals. So if a struct has a *bool field, you can do:
// Ptr returns a pointer to a copy of a value. This lets you take the address of some
// non-addressable[1] values, like boolean literals. So if a struct has a *bool field, you can do:
//
// x := MyStruct{MyBool: Ptr(true)}
//
Expand All @@ -12,6 +12,5 @@ package ptrs
//
// [1] https://go.dev/ref/spec#Address_operators
func Ptr[T any](t T) *T {
x := t
return &x
return &t
}

0 comments on commit 5f8c3e2

Please sign in to comment.