Skip to content

cmd/vet: check for misused of append onto new, non-empty slice #6840

Closed as not planned
@bradfitz

Description

@bradfitz
Request from coworkers:

Govet or lint could warn about appends to slices which were made with a length (but not
a capacity) and had no intervening mutations:

   s := make([]Foo, len(m))   // accidental length; user meant capacity: make([]Foo, 0, len(m))
   for k, v := range m {
      ....
      s = append(s, foo)
   }

Metadata

Metadata

Assignees

No one assigned

    Labels

    AnalysisIssues related to static analysis (vet, x/tools/go/analysis)NeedsDecisionFeedback is required from experts, contributors, and/or the community before a change can be made.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions