From 2b534f28ce4b7d9bd1fb09ab1bfcbf36f720bc01 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Fri, 9 Nov 2018 17:27:39 +0000 Subject: [PATCH] Revert "cmd/vet: lostcancel: suppress the check in the main.main function" MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit This reverts CL 148758 (commit 5e17ce22ece18571597ef9a214cdfcd461894e9c) Reason for revert: breaks the build. Change-Id: I6ed15b7b8f6b74d84edab9402ddf7ae87a0d0387 Reviewed-on: https://go-review.googlesource.com/c/148817 Reviewed-by: Brad Fitzpatrick Reviewed-by: Daniel Martí Run-TryBot: Brad Fitzpatrick TryBot-Result: Gobot Gobot --- src/cmd/vet/lostcancel.go | 5 ----- src/cmd/vet/testdata/lostcancel.go | 8 +------- 2 files changed, 1 insertion(+), 12 deletions(-) diff --git a/src/cmd/vet/lostcancel.go b/src/cmd/vet/lostcancel.go index 496e87a5e0..ee0342035f 100644 --- a/src/cmd/vet/lostcancel.go +++ b/src/cmd/vet/lostcancel.go @@ -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) diff --git a/src/cmd/vet/testdata/lostcancel.go b/src/cmd/vet/testdata/lostcancel.go index 408bed5122..b7549c0051 100644 --- a/src/cmd/vet/testdata/lostcancel.go +++ b/src/cmd/vet/testdata/lostcancel.go @@ -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 -- 2.50.0