Commit e15c0ac6 authored by Brad Fitzpatrick's avatar Brad Fitzpatrick

all: remove now-unnecessary unreachable panics

Take advantage of the new terminating statement rule.

R=golang-dev, r, gri
CC=golang-dev
https://golang.org/cl/7712044
parent 5f91a62a
...@@ -723,7 +723,6 @@ func (w *Walker) varValueType(vi interface{}) (string, error) { ...@@ -723,7 +723,6 @@ func (w *Walker) varValueType(vi interface{}) (string, error) {
default: default:
return "", fmt.Errorf("unknown const value type %T", vi) return "", fmt.Errorf("unknown const value type %T", vi)
} }
panic("unreachable")
} }
// resolveName finds a top-level node named name and returns the node // resolveName finds a top-level node named name and returns the node
......
...@@ -1291,7 +1291,6 @@ func (b *builder) runOut(dir string, desc string, cmdargs ...interface{}) ([]byt ...@@ -1291,7 +1291,6 @@ func (b *builder) runOut(dir string, desc string, cmdargs ...interface{}) ([]byt
return buf.Bytes(), err return buf.Bytes(), err
} }
panic("unreachable")
} }
// mkdir makes the named directory. // mkdir makes the named directory.
......
...@@ -274,7 +274,6 @@ func (b *Reader) ReadSlice(delim byte) (line []byte, err error) { ...@@ -274,7 +274,6 @@ func (b *Reader) ReadSlice(delim byte) (line []byte, err error) {
return b.buf, ErrBufferFull return b.buf, ErrBufferFull
} }
} }
panic("not reached")
} }
// ReadLine is a low-level line-reading primitive. Most callers should use // ReadLine is a low-level line-reading primitive. Most callers should use
......
...@@ -169,7 +169,6 @@ func (s *Scanner) Scan() bool { ...@@ -169,7 +169,6 @@ func (s *Scanner) Scan() bool {
} }
s.end += n s.end += n
} }
panic("not reached")
} }
// advance consumes n bytes of the buffer. It reports whether the advance was legal. // advance consumes n bytes of the buffer. It reports whether the advance was legal.
......
...@@ -54,8 +54,6 @@ func (t huffmanTree) Decode(br *bitReader) (v uint16) { ...@@ -54,8 +54,6 @@ func (t huffmanTree) Decode(br *bitReader) (v uint16) {
nodeIndex = node.right nodeIndex = node.right
} }
} }
panic("unreachable")
} }
// newHuffmanTree builds a Huffman tree from a slice containing the code // newHuffmanTree builds a Huffman tree from a slice containing the code
......
...@@ -158,7 +158,6 @@ func (b *syncBuffer) Read(p []byte) (n int, err error) { ...@@ -158,7 +158,6 @@ func (b *syncBuffer) Read(p []byte) (n int, err error) {
} }
<-b.ready <-b.ready
} }
panic("unreachable")
} }
func (b *syncBuffer) signal() { func (b *syncBuffer) signal() {
......
...@@ -263,7 +263,6 @@ func (f *decompressor) Read(b []byte) (int, error) { ...@@ -263,7 +263,6 @@ func (f *decompressor) Read(b []byte) (int, error) {
} }
f.step(f) f.step(f)
} }
panic("unreachable")
} }
func (f *decompressor) Close() error { func (f *decompressor) Close() error {
...@@ -495,7 +494,6 @@ func (f *decompressor) huffmanBlock() { ...@@ -495,7 +494,6 @@ func (f *decompressor) huffmanBlock() {
return return
} }
} }
panic("unreached")
} }
// copyHist copies f.copyLen bytes from f.hist (f.copyDist bytes ago) to itself. // copyHist copies f.copyLen bytes from f.hist (f.copyDist bytes ago) to itself.
......
...@@ -99,5 +99,4 @@ func offsetCode(off uint32) uint32 { ...@@ -99,5 +99,4 @@ func offsetCode(off uint32) uint32 {
default: default:
return offsetCodes[off>>14] + 28 return offsetCodes[off>>14] + 28
} }
panic("unreachable")
} }
...@@ -121,7 +121,6 @@ func (d *decoder) Read(b []byte) (int, error) { ...@@ -121,7 +121,6 @@ func (d *decoder) Read(b []byte) (int, error) {
} }
d.decode() d.decode()
} }
panic("unreachable")
} }
// decode decompresses bytes from r and leaves them in d.toRead. // decode decompresses bytes from r and leaves them in d.toRead.
......
...@@ -144,8 +144,6 @@ GeneratePrimes: ...@@ -144,8 +144,6 @@ GeneratePrimes:
params.G = g params.G = g
return return
} }
panic("unreachable")
} }
// GenerateKey generates a public&private key pair. The Parameters of the // GenerateKey generates a public&private key pair. The Parameters of the
......
...@@ -51,6 +51,4 @@ func ParsePKCS8PrivateKey(der []byte) (key interface{}, err error) { ...@@ -51,6 +51,4 @@ func ParsePKCS8PrivateKey(der []byte) (key interface{}, err error) {
default: default:
return nil, fmt.Errorf("crypto/x509: PKCS#8 wrapping contained private key with unknown algorithm: %v", privKey.Algo.Algorithm) return nil, fmt.Errorf("crypto/x509: PKCS#8 wrapping contained private key with unknown algorithm: %v", privKey.Algo.Algorithm)
} }
panic("unreachable")
} }
...@@ -729,7 +729,6 @@ func parsePublicKey(algo PublicKeyAlgorithm, keyData *publicKeyInfo) (interface{ ...@@ -729,7 +729,6 @@ func parsePublicKey(algo PublicKeyAlgorithm, keyData *publicKeyInfo) (interface{
default: default:
return nil, nil return nil, nil
} }
panic("unreachable")
} }
func parseCertificate(in *certificate) (*Certificate, error) { func parseCertificate(in *certificate) (*Certificate, error) {
......
...@@ -296,5 +296,4 @@ func (d *decoder) Read(p []byte) (n int, err error) { ...@@ -296,5 +296,4 @@ func (d *decoder) Read(p []byte) (n int, err error) {
nn, d.readErr = d.r.Read(d.buf[d.nbuf:]) nn, d.readErr = d.r.Read(d.buf[d.nbuf:])
d.nbuf += nn d.nbuf += nn
} }
panic("unreachable")
} }
...@@ -120,7 +120,6 @@ func ReadUvarint(r io.ByteReader) (uint64, error) { ...@@ -120,7 +120,6 @@ func ReadUvarint(r io.ByteReader) (uint64, error) {
x |= uint64(b&0x7f) << s x |= uint64(b&0x7f) << s
s += 7 s += 7
} }
panic("unreachable")
} }
// ReadVarint reads an encoded signed integer from r and returns it as an int64. // ReadVarint reads an encoded signed integer from r and returns it as an int64.
......
...@@ -171,7 +171,6 @@ func (r *Reader) ReadAll() (records [][]string, err error) { ...@@ -171,7 +171,6 @@ func (r *Reader) ReadAll() (records [][]string, err error) {
} }
records = append(records, record) records = append(records, record)
} }
panic("unreachable")
} }
// readRune reads one rune from r, folding \r\n to \n and keeping track // readRune reads one rune from r, folding \r\n to \n and keeping track
......
...@@ -739,6 +739,7 @@ func (d *decodeState) valueInterface() interface{} { ...@@ -739,6 +739,7 @@ func (d *decodeState) valueInterface() interface{} {
switch d.scanWhile(scanSkipSpace) { switch d.scanWhile(scanSkipSpace) {
default: default:
d.error(errPhase) d.error(errPhase)
panic("unreachable")
case scanBeginArray: case scanBeginArray:
return d.arrayInterface() return d.arrayInterface()
case scanBeginObject: case scanBeginObject:
...@@ -746,7 +747,6 @@ func (d *decodeState) valueInterface() interface{} { ...@@ -746,7 +747,6 @@ func (d *decodeState) valueInterface() interface{} {
case scanBeginLiteral: case scanBeginLiteral:
return d.literalInterface() return d.literalInterface()
} }
panic("unreachable")
} }
// arrayInterface is like array but returns []interface{}. // arrayInterface is like array but returns []interface{}.
......
...@@ -493,7 +493,6 @@ Loop: ...@@ -493,7 +493,6 @@ Loop:
return true, nil return true, nil
} }
} }
panic("unreachable")
} }
// Skip reads tokens until it has consumed the end element // Skip reads tokens until it has consumed the end element
...@@ -517,5 +516,4 @@ func (d *Decoder) Skip() error { ...@@ -517,5 +516,4 @@ func (d *Decoder) Skip() error {
return nil return nil
} }
} }
panic("unreachable")
} }
...@@ -89,8 +89,6 @@ func expectedErrors(t *testing.T, filename string, src []byte) map[token.Pos]str ...@@ -89,8 +89,6 @@ func expectedErrors(t *testing.T, filename string, src []byte) map[token.Pos]str
prev = pos prev = pos
} }
} }
panic("unreachable")
} }
// compareErrors compares the map of expected error messages with the list // compareErrors compares the map of expected error messages with the list
......
...@@ -71,7 +71,6 @@ func tText(c context, s []byte) (context, int) { ...@@ -71,7 +71,6 @@ func tText(c context, s []byte) (context, int) {
} }
k = j k = j
} }
panic("unreachable")
} }
var elementContentType = [...]state{ var elementContentType = [...]state{
......
...@@ -304,7 +304,6 @@ func (d *decoder) readExtension() error { ...@@ -304,7 +304,6 @@ func (d *decoder) readExtension() error {
return err return err
} }
} }
panic("unreachable")
} }
func (d *decoder) readGraphicControl() error { func (d *decoder) readGraphicControl() error {
......
...@@ -144,7 +144,6 @@ func (devNull) ReadFrom(r io.Reader) (n int64, err error) { ...@@ -144,7 +144,6 @@ func (devNull) ReadFrom(r io.Reader) (n int64, err error) {
return return
} }
} }
panic("unreachable")
} }
// Discard is an io.Writer on which all Write calls succeed // Discard is an io.Writer on which all Write calls succeed
......
...@@ -43,7 +43,6 @@ func (r *Rand) ExpFloat64() float64 { ...@@ -43,7 +43,6 @@ func (r *Rand) ExpFloat64() float64 {
return x return x
} }
} }
panic("unreachable")
} }
var ke = [256]uint32{ var ke = [256]uint32{
......
...@@ -63,7 +63,6 @@ func (r *Rand) NormFloat64() float64 { ...@@ -63,7 +63,6 @@ func (r *Rand) NormFloat64() float64 {
return x return x
} }
} }
panic("unreachable")
} }
var kn = [128]uint32{ var kn = [128]uint32{
......
...@@ -265,7 +265,6 @@ func (r *Reader) NextPart() (*Part, error) { ...@@ -265,7 +265,6 @@ func (r *Reader) NextPart() (*Part, error) {
return nil, fmt.Errorf("multipart: unexpected line in Next(): %q", line) return nil, fmt.Errorf("multipart: unexpected line in Next(): %q", line)
} }
panic("unreachable")
} }
// isFinalBoundary returns whether line is the final boundary line // isFinalBoundary returns whether line is the final boundary line
......
...@@ -280,7 +280,6 @@ func dialTimeoutRace(net, addr string, timeout time.Duration) (Conn, error) { ...@@ -280,7 +280,6 @@ func dialTimeoutRace(net, addr string, timeout time.Duration) (Conn, error) {
case p := <-ch: case p := <-ch:
return p.Conn, p.error return p.Conn, p.error
} }
panic("unreachable")
} }
type stringAddr struct { type stringAddr struct {
......
...@@ -51,7 +51,6 @@ func pedanticReadAll(r io.Reader) (b []byte, err error) { ...@@ -51,7 +51,6 @@ func pedanticReadAll(r io.Reader) (b []byte, err error) {
return b, err return b, err
} }
} }
panic("unreachable")
} }
func TestClient(t *testing.T) { func TestClient(t *testing.T) {
......
...@@ -267,5 +267,4 @@ func Serve(l net.Listener, handler http.Handler) error { ...@@ -267,5 +267,4 @@ func Serve(l net.Listener, handler http.Handler) error {
c := newChild(rw, handler) c := newChild(rw, handler)
go c.serve() go c.serve()
} }
panic("unreachable")
} }
...@@ -1337,7 +1337,6 @@ func (srv *Server) Serve(l net.Listener) error { ...@@ -1337,7 +1337,6 @@ func (srv *Server) Serve(l net.Listener) error {
} }
go c.serve() go c.serve()
} }
panic("not reached")
} }
// ListenAndServe listens on the TCP network address addr // ListenAndServe listens on the TCP network address addr
......
...@@ -349,7 +349,6 @@ func (t *Transport) getIdleConn(cm *connectMethod) (pconn *persistConn) { ...@@ -349,7 +349,6 @@ func (t *Transport) getIdleConn(cm *connectMethod) (pconn *persistConn) {
return return
} }
} }
panic("unreachable")
} }
func (t *Transport) setReqConn(r *Request, pc *persistConn) { func (t *Transport) setReqConn(r *Request, pc *persistConn) {
......
...@@ -399,12 +399,10 @@ func (WriteFailCodec) WriteRequest(*Request, interface{}) error { ...@@ -399,12 +399,10 @@ func (WriteFailCodec) WriteRequest(*Request, interface{}) error {
func (WriteFailCodec) ReadResponseHeader(*Response) error { func (WriteFailCodec) ReadResponseHeader(*Response) error {
select {} select {}
panic("unreachable")
} }
func (WriteFailCodec) ReadResponseBody(interface{}) error { func (WriteFailCodec) ReadResponseBody(interface{}) error {
select {} select {}
panic("unreachable")
} }
func (WriteFailCodec) Close() error { func (WriteFailCodec) Close() error {
......
...@@ -489,7 +489,6 @@ func (r *Reader) ReadMIMEHeader() (MIMEHeader, error) { ...@@ -489,7 +489,6 @@ func (r *Reader) ReadMIMEHeader() (MIMEHeader, error) {
return m, err return m, err
} }
} }
panic("unreachable")
} }
// CanonicalMIMEHeaderKey returns the canonical format of the // CanonicalMIMEHeaderKey returns the canonical format of the
......
...@@ -198,7 +198,6 @@ func (f *File) write(b []byte) (n int, err error) { ...@@ -198,7 +198,6 @@ func (f *File) write(b []byte) (n int, err error) {
return n, err return n, err
} }
panic("not reached")
} }
// pwrite writes len(b) bytes to the File starting at byte offset off. // pwrite writes len(b) bytes to the File starting at byte offset off.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment