mirror of https://github.com/golang/go.git
Revert "cmd/vet: lostcancel: suppress the check in the main.main function"
This reverts CL 148758 (commit 5e17ce22ec)
Reason for revert: breaks the build.
Change-Id: I6ed15b7b8f6b74d84edab9402ddf7ae87a0d0387
Reviewed-on: https://go-review.googlesource.com/c/148817
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
parent
5e17ce22ec
commit
2b534f28ce
|
|
@ -104,11 +104,6 @@ func checkLostCancel(f *File, node ast.Node) {
|
|||
var sig *types.Signature
|
||||
switch node := node.(type) {
|
||||
case *ast.FuncDecl:
|
||||
if node.Name.Name == "main" && node.Recv == nil && f.file.Name.Name == "main" {
|
||||
// Returning from main.main terminates the process,
|
||||
// so there's no need to cancel contexts.
|
||||
return
|
||||
}
|
||||
obj := f.pkg.defs[node.Name]
|
||||
if obj == nil {
|
||||
return // type error (e.g. duplicate function declaration)
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package main
|
||||
package testdata
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
|
@ -33,12 +33,6 @@ func _() {
|
|||
ctx, _ = context.WithDeadline() // ERROR "the cancel function returned by context.WithDeadline should be called, not discarded, to avoid a context leak"
|
||||
}
|
||||
|
||||
// Return from main is handled specially.
|
||||
// Since the program exits, there's no need to call cancel.
|
||||
func main() {
|
||||
var ctx, cancel = context.WithCancel()
|
||||
}
|
||||
|
||||
func _() {
|
||||
ctx, cancel := context.WithCancel()
|
||||
defer cancel() // ok
|
||||
|
|
|
|||
Loading…
Reference in New Issue