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