mirror of
https://github.com/golang/go
synced 2024-11-23 01:40:03 -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:
parent
ffde4970d0
commit
0bc7e79afd
@ -286,7 +286,7 @@ func downloadPackage(p *Package) error {
|
|||||||
}
|
}
|
||||||
// Some version control tools require the parent of the target to exist.
|
// Some version control tools require the parent of the target to exist.
|
||||||
parent, _ := filepath.Split(root)
|
parent, _ := filepath.Split(root)
|
||||||
if err := os.MkdirAll(parent, 0777); err != nil {
|
if err = os.MkdirAll(parent, 0777); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err = vcs.create(root, repo); err != nil {
|
if err = vcs.create(root, repo); err != nil {
|
||||||
|
@ -441,11 +441,11 @@ func marshalBody(out *forkableWriter, value reflect.Value, params fieldParameter
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
var params fieldParameters
|
var fp fieldParameters
|
||||||
for i := 0; i < v.Len(); i++ {
|
for i := 0; i < v.Len(); i++ {
|
||||||
var pre *forkableWriter
|
var pre *forkableWriter
|
||||||
pre, out = out.fork()
|
pre, out = out.fork()
|
||||||
err = marshalField(pre, v.Index(i), params)
|
err = marshalField(pre, v.Index(i), fp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -575,21 +575,21 @@ func (enc *Encoder) encOpFor(rt reflect.Type, inProgress map[reflect.Type]*encOp
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
// Slices have a header; we decode it to find the underlying array.
|
// 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) {
|
op = func(i *encInstr, state *encoderState, p unsafe.Pointer) {
|
||||||
slice := (*reflect.SliceHeader)(p)
|
slice := (*reflect.SliceHeader)(p)
|
||||||
if !state.sendZero && slice.Len == 0 {
|
if !state.sendZero && slice.Len == 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
state.update(i)
|
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:
|
case reflect.Array:
|
||||||
// True arrays have size in the type.
|
// 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) {
|
op = func(i *encInstr, state *encoderState, p unsafe.Pointer) {
|
||||||
state.update(i)
|
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:
|
case reflect.Map:
|
||||||
keyOp, keyIndir := enc.encOpFor(t.Key(), inProgress)
|
keyOp, keyIndir := enc.encOpFor(t.Key(), inProgress)
|
||||||
|
@ -811,8 +811,8 @@ func (p *pp) printArg(arg interface{}, verb rune, plus, goSyntax bool, depth int
|
|||||||
p.fmt.plus = oldPlus
|
p.fmt.plus = oldPlus
|
||||||
p.fmt.sharp = oldSharp
|
p.fmt.sharp = oldSharp
|
||||||
// If the type is not simple, it might have methods.
|
// If the type is not simple, it might have methods.
|
||||||
if wasString, handled := p.handleMethods(verb, plus, goSyntax, depth); handled {
|
if isString, handled := p.handleMethods(verb, plus, goSyntax, depth); handled {
|
||||||
return wasString
|
return isString
|
||||||
}
|
}
|
||||||
// Need to use reflection
|
// Need to use reflection
|
||||||
return p.printReflectValue(reflect.ValueOf(arg), verb, plus, goSyntax, depth)
|
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() {
|
if value.CanInterface() {
|
||||||
p.arg = value.Interface()
|
p.arg = value.Interface()
|
||||||
}
|
}
|
||||||
if wasString, handled := p.handleMethods(verb, plus, goSyntax, depth); handled {
|
if isString, handled := p.handleMethods(verb, plus, goSyntax, depth); handled {
|
||||||
return wasString
|
return isString
|
||||||
}
|
}
|
||||||
|
|
||||||
return p.printReflectValue(value, verb, plus, goSyntax, depth)
|
return p.printReflectValue(value, verb, plus, goSyntax, depth)
|
||||||
|
@ -781,7 +781,7 @@ func (s *ss) convertFloat(str string, n int) float64 {
|
|||||||
}
|
}
|
||||||
s.error(err)
|
s.error(err)
|
||||||
}
|
}
|
||||||
n, err := strconv.Atoi(str[p+1:])
|
m, err := strconv.Atoi(str[p+1:])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// Put full string into error.
|
// Put full string into error.
|
||||||
if e, ok := err.(*strconv.NumError); ok {
|
if e, ok := err.(*strconv.NumError); ok {
|
||||||
@ -789,7 +789,7 @@ func (s *ss) convertFloat(str string, n int) float64 {
|
|||||||
}
|
}
|
||||||
s.error(err)
|
s.error(err)
|
||||||
}
|
}
|
||||||
return math.Ldexp(f, n)
|
return math.Ldexp(f, m)
|
||||||
}
|
}
|
||||||
f, err := strconv.ParseFloat(str, n)
|
f, err := strconv.ParseFloat(str, n)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -858,8 +858,7 @@ func (s *ss) quotedString() string {
|
|||||||
// In a legal backslash escape, no matter how long, only the character
|
// In a legal backslash escape, no matter how long, only the character
|
||||||
// immediately after the escape can itself be a backslash or quote.
|
// immediately after the escape can itself be a backslash or quote.
|
||||||
// Thus we only need to protect the first character after the backslash.
|
// Thus we only need to protect the first character after the backslash.
|
||||||
r := s.mustReadRune()
|
s.buf.WriteRune(s.mustReadRune())
|
||||||
s.buf.WriteRune(r)
|
|
||||||
} else if r == '"' {
|
} else if r == '"' {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
@ -381,7 +381,6 @@ func TestDialer(t *testing.T) {
|
|||||||
defer ln.Close()
|
defer ln.Close()
|
||||||
ch := make(chan error, 1)
|
ch := make(chan error, 1)
|
||||||
go func() {
|
go func() {
|
||||||
var err error
|
|
||||||
c, err := ln.Accept()
|
c, err := ln.Accept()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ch <- fmt.Errorf("Accept failed: %v", err)
|
ch <- fmt.Errorf("Accept failed: %v", err)
|
||||||
|
@ -212,7 +212,6 @@ func TestUnixgramConnLocalAndRemoteNames(t *testing.T) {
|
|||||||
|
|
||||||
var la *UnixAddr
|
var la *UnixAddr
|
||||||
if laddr != "" {
|
if laddr != "" {
|
||||||
var err error
|
|
||||||
if la, err = ResolveUnixAddr("unixgram", laddr); err != nil {
|
if la, err = ResolveUnixAddr("unixgram", laddr); err != nil {
|
||||||
t.Fatalf("ResolveUnixAddr failed: %v", err)
|
t.Fatalf("ResolveUnixAddr failed: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -91,7 +91,7 @@ func TestRemoveAll(t *testing.T) {
|
|||||||
if err = RemoveAll(path); err != nil {
|
if err = RemoveAll(path); err != nil {
|
||||||
t.Fatalf("RemoveAll %q (first): %s", path, err)
|
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)
|
t.Fatalf("Lstat %q succeeded after RemoveAll (first)", path)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -153,7 +153,7 @@ func TestRemoveAll(t *testing.T) {
|
|||||||
Chmod(dpath, 0777)
|
Chmod(dpath, 0777)
|
||||||
|
|
||||||
for _, s := range []string{fpath, path + "/zzz"} {
|
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)
|
t.Fatalf("Lstat %q succeeded after partial RemoveAll", s)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -161,7 +161,7 @@ func TestRemoveAll(t *testing.T) {
|
|||||||
if err = RemoveAll(path); err != nil {
|
if err = RemoveAll(path); err != nil {
|
||||||
t.Fatalf("RemoveAll %q after partial RemoveAll: %s", path, err)
|
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)
|
t.Fatalf("Lstat %q succeeded after RemoveAll (final)", path)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -532,10 +532,9 @@ func Sendmsg(fd int, p, oob []byte, to Sockaddr, flags int) (err error) {
|
|||||||
var ptr uintptr
|
var ptr uintptr
|
||||||
var salen _Socklen
|
var salen _Socklen
|
||||||
if to != nil {
|
if to != nil {
|
||||||
var err error
|
|
||||||
ptr, salen, err = to.sockaddr()
|
ptr, salen, err = to.sockaddr()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var msg Msghdr
|
var msg Msghdr
|
||||||
|
@ -780,7 +780,7 @@ func parse(layout, value string, defaultLocation, local *Location) (Time, error)
|
|||||||
// Special case: do we have a fractional second but no
|
// Special case: do we have a fractional second but no
|
||||||
// fractional second in the format?
|
// fractional second in the format?
|
||||||
if len(value) >= 2 && value[0] == '.' && isDigit(value, 1) {
|
if len(value) >= 2 && value[0] == '.' && isDigit(value, 1) {
|
||||||
_, std, _ := nextStdChunk(layout)
|
_, std, _ = nextStdChunk(layout)
|
||||||
std &= stdMask
|
std &= stdMask
|
||||||
if std == stdFracSecond0 || std == stdFracSecond9 {
|
if std == stdFracSecond0 || std == stdFracSecond9 {
|
||||||
// Fractional second in the layout; proceed normally
|
// Fractional second in the layout; proceed normally
|
||||||
|
Loading…
Reference in New Issue
Block a user