Commit 2b534f28 authored by Brad Fitzpatrick's avatar Brad Fitzpatrick

Revert "cmd/vet: lostcancel: suppress the check in the main.main function"

This reverts CL 148758 (commit 5e17ce22)

Reason for revert: breaks the build.

Change-Id: I6ed15b7b8f6b74d84edab9402ddf7ae87a0d0387
Reviewed-on: https://go-review.googlesource.com/c/148817Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: default avatarDaniel Martí <mvdan@mvdan.cc>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent 5e17ce22
...@@ -104,11 +104,6 @@ func checkLostCancel(f *File, node ast.Node) { ...@@ -104,11 +104,6 @@ func checkLostCancel(f *File, node ast.Node) {
var sig *types.Signature var sig *types.Signature
switch node := node.(type) { switch node := node.(type) {
case *ast.FuncDecl: 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] obj := f.pkg.defs[node.Name]
if obj == nil { if obj == nil {
return // type error (e.g. duplicate function declaration) return // type error (e.g. duplicate function declaration)
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
package main package testdata
import ( import (
"context" "context"
...@@ -33,12 +33,6 @@ func _() { ...@@ -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" 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 _() { func _() {
ctx, cancel := context.WithCancel() ctx, cancel := context.WithCancel()
defer cancel() // ok defer cancel() // ok
......
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