Skip to content

Commit

Permalink
constraints: remove package
Browse files Browse the repository at this point in the history
It has moved to golang.org/x/exp/constraints. Perhaps it will move
back to the standard library in a future release.

For #45458
Fixes #50792

Change-Id: I93aa251a7afe7b329a3d3faadc0c5d6388b1f0e9
Reviewed-on: https://go-review.googlesource.com/c/go/+/382460
Trust: Ian Lance Taylor <[email protected]>
Run-TryBot: Ian Lance Taylor <[email protected]>
Reviewed-by: Robert Griesemer <[email protected]>
TryBot-Result: Gopher Robot <[email protected]>
  • Loading branch information
ianlancetaylor committed Feb 3, 2022
1 parent 8384fe8 commit 070951c
Show file tree
Hide file tree
Showing 11 changed files with 28 additions and 203 deletions.
6 changes: 0 additions & 6 deletions api/go1.18.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
pkg bufio, method (*Writer) AvailableBuffer() []uint8
pkg bufio, method (ReadWriter) AvailableBuffer() []uint8
pkg bytes, func Cut([]uint8, []uint8) ([]uint8, []uint8, bool)
pkg constraints, type Complex interface {}
pkg constraints, type Float interface {}
pkg constraints, type Integer interface {}
pkg constraints, type Ordered interface {}
pkg constraints, type Signed interface {}
pkg constraints, type Unsigned interface {}
pkg crypto/tls, method (*Conn) NetConn() net.Conn
pkg debug/buildinfo, func Read(io.ReaderAt) (*debug.BuildInfo, error)
pkg debug/buildinfo, func ReadFile(string) (*debug.BuildInfo, error)
Expand Down
8 changes: 0 additions & 8 deletions doc/go1.18.html
Original file line number Diff line number Diff line change
Expand Up @@ -467,14 +467,6 @@ <h2 id="linker">Linker</h2>

<h2 id="library">Core library</h2>

<h3 id="constraints">New <code>constraints</code> package</h3>

<p><!-- CL 349709 -->
The new <a href="/pkg/constraints/"><code>constraints</code></a> package
defines a set of useful constraints that can be used with type parameters of
generic functions.
</p>

<h3 id="debug/buildinfo">New <code>debug/buildinfo</code> package</h3>

<p><!-- golang.org/issue/39301 -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@

package go1_17

import "constraints"

type T[P /* ERROR type parameters require go1\.18 or later */ any /* ERROR undeclared name: any \(requires version go1\.18 or later\) */ ] struct{}

// for init (and main, but we're not in package main) we should only get one error
Expand Down Expand Up @@ -57,5 +55,3 @@ type (
_ = C1
_ = C2
)

type Ordered constraints /* ERROR using type constraint constraints\.Ordered requires go1\.18 or later */ .Ordered
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@

package p

import "constraints"
type Integer interface {
~int | ~int8 | ~int16 | ~int32 | ~int64 |
~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr
}

func shl[I constraints.Integer](n int) I {
func shl[I Integer](n int) I {
return 1 << n
}
50 changes: 0 additions & 50 deletions src/constraints/constraints.go

This file was deleted.

117 changes: 0 additions & 117 deletions src/constraints/constraints_test.go

This file was deleted.

4 changes: 0 additions & 4 deletions src/go/types/testdata/fixedbugs/issue47818.go2
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@

package go1_17

import "constraints"

type T[P /* ERROR type parameters require go1\.18 or later */ any /* ERROR undeclared name: any \(requires version go1\.18 or later\) */ ] struct{}

// for init (and main, but we're not in package main) we should only get one error
Expand Down Expand Up @@ -57,5 +55,3 @@ type (
_ = C1
_ = C2
)

type Ordered constraints /* ERROR using type constraint constraints\.Ordered requires go1\.18 or later */ .Ordered
7 changes: 5 additions & 2 deletions src/go/types/testdata/fixedbugs/issue49705.go2
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@

package p

import "constraints"
type Integer interface {
~int | ~int8 | ~int16 | ~int32 | ~int64 |
~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr
}

func shl[I constraints.Integer](n int) I {
func shl[I Integer](n int) I {
return 1 << n
}
8 changes: 6 additions & 2 deletions test/typeparam/issue50121.dir/a.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@
package a

import (
"constraints"
"math/rand"
)

type Builder[T constraints.Integer] struct{}
type Integer interface {
~int | ~int8 | ~int16 | ~int32 | ~int64 |
~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr
}

type Builder[T Integer] struct{}

func (r Builder[T]) New() T {
return T(rand.Int())
Expand Down
9 changes: 5 additions & 4 deletions test/typeparam/issue50121b.dir/a.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@

package a

import (
"constraints"
)
type Integer interface {
~int | ~int8 | ~int16 | ~int32 | ~int64 |
~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr
}

type Builder[T constraints.Integer] struct{}
type Builder[T Integer] struct{}

func (r Builder[T]) New() T {
return T(42)
Expand Down
11 changes: 7 additions & 4 deletions test/typeparam/issue50193.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,20 @@
package main

import (
"constraints"
"fmt"
)

func zero[T constraints.Complex]() T {
type Complex interface {
~complex64 | ~complex128
}

func zero[T Complex]() T {
return T(0)
}
func pi[T constraints.Complex]() T {
func pi[T Complex]() T {
return T(3.14)
}
func sqrtN1[T constraints.Complex]() T {
func sqrtN1[T Complex]() T {
return T(-1i)
}

Expand Down

0 comments on commit 070951c

Please sign in to comment.