Skip to content

Commit 2b534f2

Browse files
committed
Revert "cmd/vet: lostcancel: suppress the check in the main.main function"
This reverts CL 148758 (commit 5e17ce2) 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>
1 parent 5e17ce2 commit 2b534f2

File tree

2 files changed

+1
-12
lines changed

2 files changed

+1
-12
lines changed

src/cmd/vet/lostcancel.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,6 @@ func checkLostCancel(f *File, node ast.Node) {
104104
var sig *types.Signature
105105
switch node := node.(type) {
106106
case *ast.FuncDecl:
107-
if node.Name.Name == "main" && node.Recv == nil && f.file.Name.Name == "main" {
108-
// Returning from main.main terminates the process,
109-
// so there's no need to cancel contexts.
110-
return
111-
}
112107
obj := f.pkg.defs[node.Name]
113108
if obj == nil {
114109
return // type error (e.g. duplicate function declaration)

src/cmd/vet/testdata/lostcancel.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5-
package main
5+
package testdata
66

77
import (
88
"context"
@@ -33,12 +33,6 @@ func _() {
3333
ctx, _ = context.WithDeadline() // ERROR "the cancel function returned by context.WithDeadline should be called, not discarded, to avoid a context leak"
3434
}
3535

36-
// Return from main is handled specially.
37-
// Since the program exits, there's no need to call cancel.
38-
func main() {
39-
var ctx, cancel = context.WithCancel()
40-
}
41-
4236
func _() {
4337
ctx, cancel := context.WithCancel()
4438
defer cancel() // ok

0 commit comments

Comments
 (0)