1
0
mirror of https://github.com/golang/go synced 2024-11-22 22:30:02 -07:00

all: excise some warts found by vet -shadow

These are not erroneous, just poor or confusing.

R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/10448043
This commit is contained in:
Rob Pike 2013-06-20 16:14:40 -07:00
parent ffde4970d0
commit 0bc7e79afd
10 changed files with 19 additions and 23 deletions

View File

@ -286,7 +286,7 @@ func downloadPackage(p *Package) error {
}
// Some version control tools require the parent of the target to exist.
parent, _ := filepath.Split(root)
if err := os.MkdirAll(parent, 0777); err != nil {
if err = os.MkdirAll(parent, 0777); err != nil {
return err
}
if err = vcs.create(root, repo); err != nil {

View File

@ -441,11 +441,11 @@ func marshalBody(out *forkableWriter, value reflect.Value, params fieldParameter
return
}
var params fieldParameters
var fp fieldParameters
for i := 0; i < v.Len(); i++ {
var pre *forkableWriter
pre, out = out.fork()
err = marshalField(pre, v.Index(i), params)
err = marshalField(pre, v.Index(i), fp)
if err != nil {
return
}

View File

@ -575,21 +575,21 @@ func (enc *Encoder) encOpFor(rt reflect.Type, inProgress map[reflect.Type]*encOp
break
}
// Slices have a header; we decode it to find the underlying array.
elemOp, indir := enc.encOpFor(t.Elem(), inProgress)
elemOp, elemIndir := enc.encOpFor(t.Elem(), inProgress)
op = func(i *encInstr, state *encoderState, p unsafe.Pointer) {
slice := (*reflect.SliceHeader)(p)
if !state.sendZero && slice.Len == 0 {
return
}
state.update(i)
state.enc.encodeArray(state.b, unsafe.Pointer(slice.Data), *elemOp, t.Elem().Size(), indir, int(slice.Len))
state.enc.encodeArray(state.b, unsafe.Pointer(slice.Data), *elemOp, t.Elem().Size(), elemIndir, int(slice.Len))
}
case reflect.Array:
// True arrays have size in the type.
elemOp, indir := enc.encOpFor(t.Elem(), inProgress)
elemOp, elemIndir := enc.encOpFor(t.Elem(), inProgress)
op = func(i *encInstr, state *encoderState, p unsafe.Pointer) {
state.update(i)
state.enc.encodeArray(state.b, p, *elemOp, t.Elem().Size(), indir, t.Len())
state.enc.encodeArray(state.b, p, *elemOp, t.Elem().Size(), elemIndir, t.Len())
}
case reflect.Map:
keyOp, keyIndir := enc.encOpFor(t.Key(), inProgress)

View File

@ -811,8 +811,8 @@ func (p *pp) printArg(arg interface{}, verb rune, plus, goSyntax bool, depth int
p.fmt.plus = oldPlus
p.fmt.sharp = oldSharp
// If the type is not simple, it might have methods.
if wasString, handled := p.handleMethods(verb, plus, goSyntax, depth); handled {
return wasString
if isString, handled := p.handleMethods(verb, plus, goSyntax, depth); handled {
return isString
}
// Need to use reflection
return p.printReflectValue(reflect.ValueOf(arg), verb, plus, goSyntax, depth)
@ -849,8 +849,8 @@ func (p *pp) printValue(value reflect.Value, verb rune, plus, goSyntax bool, dep
if value.CanInterface() {
p.arg = value.Interface()
}
if wasString, handled := p.handleMethods(verb, plus, goSyntax, depth); handled {
return wasString
if isString, handled := p.handleMethods(verb, plus, goSyntax, depth); handled {
return isString
}
return p.printReflectValue(value, verb, plus, goSyntax, depth)

View File

@ -781,7 +781,7 @@ func (s *ss) convertFloat(str string, n int) float64 {
}
s.error(err)
}
n, err := strconv.Atoi(str[p+1:])
m, err := strconv.Atoi(str[p+1:])
if err != nil {
// Put full string into error.
if e, ok := err.(*strconv.NumError); ok {
@ -789,7 +789,7 @@ func (s *ss) convertFloat(str string, n int) float64 {
}
s.error(err)
}
return math.Ldexp(f, n)
return math.Ldexp(f, m)
}
f, err := strconv.ParseFloat(str, n)
if err != nil {
@ -858,8 +858,7 @@ func (s *ss) quotedString() string {
// In a legal backslash escape, no matter how long, only the character
// immediately after the escape can itself be a backslash or quote.
// Thus we only need to protect the first character after the backslash.
r := s.mustReadRune()
s.buf.WriteRune(r)
s.buf.WriteRune(s.mustReadRune())
} else if r == '"' {
break
}

View File

@ -381,7 +381,6 @@ func TestDialer(t *testing.T) {
defer ln.Close()
ch := make(chan error, 1)
go func() {
var err error
c, err := ln.Accept()
if err != nil {
ch <- fmt.Errorf("Accept failed: %v", err)

View File

@ -212,7 +212,6 @@ func TestUnixgramConnLocalAndRemoteNames(t *testing.T) {
var la *UnixAddr
if laddr != "" {
var err error
if la, err = ResolveUnixAddr("unixgram", laddr); err != nil {
t.Fatalf("ResolveUnixAddr failed: %v", err)
}

View File

@ -91,7 +91,7 @@ func TestRemoveAll(t *testing.T) {
if err = RemoveAll(path); err != nil {
t.Fatalf("RemoveAll %q (first): %s", path, err)
}
if _, err := Lstat(path); err == nil {
if _, err = Lstat(path); err == nil {
t.Fatalf("Lstat %q succeeded after RemoveAll (first)", path)
}
@ -153,7 +153,7 @@ func TestRemoveAll(t *testing.T) {
Chmod(dpath, 0777)
for _, s := range []string{fpath, path + "/zzz"} {
if _, err := Lstat(s); err == nil {
if _, err = Lstat(s); err == nil {
t.Fatalf("Lstat %q succeeded after partial RemoveAll", s)
}
}
@ -161,7 +161,7 @@ func TestRemoveAll(t *testing.T) {
if err = RemoveAll(path); err != nil {
t.Fatalf("RemoveAll %q after partial RemoveAll: %s", path, err)
}
if _, err := Lstat(path); err == nil {
if _, err = Lstat(path); err == nil {
t.Fatalf("Lstat %q succeeded after RemoveAll (final)", path)
}
}

View File

@ -532,10 +532,9 @@ func Sendmsg(fd int, p, oob []byte, to Sockaddr, flags int) (err error) {
var ptr uintptr
var salen _Socklen
if to != nil {
var err error
ptr, salen, err = to.sockaddr()
if err != nil {
return err
return
}
}
var msg Msghdr

View File

@ -780,7 +780,7 @@ func parse(layout, value string, defaultLocation, local *Location) (Time, error)
// Special case: do we have a fractional second but no
// fractional second in the format?
if len(value) >= 2 && value[0] == '.' && isDigit(value, 1) {
_, std, _ := nextStdChunk(layout)
_, std, _ = nextStdChunk(layout)
std &= stdMask
if std == stdFracSecond0 || std == stdFracSecond9 {
// Fractional second in the layout; proceed normally