Source file src/cmd/vendor/golang.org/x/tools/go/analysis/passes/defers/doc.go

     1  // Copyright 2023 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  // Package defers defines an Analyzer that checks for common mistakes in defer
     6  // statements.
     7  //
     8  // # Analyzer defers
     9  //
    10  // defers: report common mistakes in defer statements
    11  //
    12  // The defers analyzer reports a diagnostic when a defer statement would
    13  // result in a non-deferred call to time.Since, as experience has shown
    14  // that this is nearly always a mistake.
    15  //
    16  // For example:
    17  //
    18  //	start := time.Now()
    19  //	...
    20  //	defer recordLatency(time.Since(start)) // error: call to time.Since is not deferred
    21  //
    22  // The correct code is:
    23  //
    24  //	defer func() { recordLatency(time.Since(start)) }()
    25  package defers
    26  

View as plain text