<p dir="auto">Using rev 1278:a7e14835e46b of golang.org/x/tools the <code class="notranslate">stringer</code> command generate a source file<br>
(t_string.go) which fails to compile due to the following error:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="./t_string.go:18: cannot use _T_index[i - T(1)] (type uint16) as type uint8 in assignment"><pre class="notranslate"><code class="notranslate">./t_string.go:18: cannot use _T_index[i - T(1)] (type uint16) as type uint8 in assignment
</code></pre></div>
<p dir="auto"><a href="http://play.golang.org/p/71KjyXwt4Z" rel="nofollow">p.go</a></p>
<div class="highlight highlight-source-go notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="package p

// NOTE: Using rev 1278:a7e14835e46b of golang.org/x/tools the stringer command
// generate a source file which fails to compile due to the following error:
//    cannot use _T_index[i - T(1)] (type uint16) as type uint8 in assignment

//go:generate stringer -type T

type T uint8

const (
    Taaaaaaaaaaaaaaaaaaaaaaaaaaa T = iota
    Tbbbbbbbbbbbbbbbbbbbbbbbbbbb
    Tccccccccccccccccccccccccccc
    Tddddddddddddddddddddddddddd
    Teeeeeeeeeeeeeeeeeeeeeeeeeee
    Tfffffffffffffffffffffffffff
    Tggggggggggggggggggggggggggg
    Thhhhhhhhhhhhhhhhhhhhhhhhhhh
    Tiiiiiiiiiiiiiiiiiiiiiiiiiii
    Tjjjjjjjjjjjjjjjjjjjjjjjjjjj
)"><pre class="notranslate"><span class="pl-k">package</span> p

<span class="pl-c">// NOTE: Using rev 1278:a7e14835e46b of golang.org/x/tools the stringer command</span>
<span class="pl-c">// generate a source file which fails to compile due to the following error:</span>
<span class="pl-c">//    cannot use _T_index[i - T(1)] (type uint16) as type uint8 in assignment</span>

<span class="pl-c">//go:generate stringer -type T</span>

<span class="pl-k">type</span> <span class="pl-smi">T</span> <span class="pl-smi">uint8</span>

<span class="pl-k">const</span> (
    <span class="pl-s1">Taaaaaaaaaaaaaaaaaaaaaaaaaaa</span> <span class="pl-smi">T</span> <span class="pl-c1">=</span> <span class="pl-s1">iota</span>
    <span class="pl-s1">Tbbbbbbbbbbbbbbbbbbbbbbbbbbb</span>
    <span class="pl-s1">Tccccccccccccccccccccccccccc</span>
    <span class="pl-s1">Tddddddddddddddddddddddddddd</span>
    <span class="pl-s1">Teeeeeeeeeeeeeeeeeeeeeeeeeee</span>
    <span class="pl-s1">Tfffffffffffffffffffffffffff</span>
    <span class="pl-s1">Tggggggggggggggggggggggggggg</span>
    <span class="pl-s1">Thhhhhhhhhhhhhhhhhhhhhhhhhhh</span>
    <span class="pl-s1">Tiiiiiiiiiiiiiiiiiiiiiiiiiii</span>
    <span class="pl-s1">Tjjjjjjjjjjjjjjjjjjjjjjjjjjj</span>
)</pre></div>
<p dir="auto"><a href="http://play.golang.org/p/AXdDHgkhDR" rel="nofollow">t_string.go</a></p>
<div class="highlight highlight-source-go notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="// generated by stringer -type T; DO NOT EDIT

package p

import &quot;fmt&quot;

const _T_name = &quot;TaaaaaaaaaaaaaaaaaaaaaaaaaaaTbbbbbbbbbbbbbbbbbbbbbbbbbbbTcccccccccccccccccccccccccccTdddddddddddddddddddddddddddTeeeeeeeeeeeeeeeeeeeeeeeeeeeTfffffffffffffffffffffffffffTgggggggggggggggggggggggggggThhhhhhhhhhhhhhhhhhhhhhhhhhhTiiiiiiiiiiiiiiiiiiiiiiiiiiiTjjjjjjjjjjjjjjjjjjjjjjjjjjj&quot;

var _T_index = [...]uint16{28, 56, 84, 112, 140, 168, 196, 224, 252, 280}

func (i T) String() string {
    if i &gt;= T(len(_T_index)) {
        return fmt.Sprintf(&quot;T(%d)&quot;, i)
    }
    hi := _T_index[i]
    lo := uint8(0)
    if i &gt; 0 {
        lo = _T_index[i-1]
    }
    return _T_name[lo:hi]
}"><pre class="notranslate"><span class="pl-c">// generated by stringer -type T; DO NOT EDIT</span>

<span class="pl-k">package</span> p

<span class="pl-k">import</span> <span class="pl-s">"fmt"</span>

<span class="pl-k">const</span> <span class="pl-s1">_T_name</span> <span class="pl-c1">=</span> <span class="pl-s">"TaaaaaaaaaaaaaaaaaaaaaaaaaaaTbbbbbbbbbbbbbbbbbbbbbbbbbbbTcccccccccccccccccccccccccccTdddddddddddddddddddddddddddTeeeeeeeeeeeeeeeeeeeeeeeeeeeTfffffffffffffffffffffffffffTgggggggggggggggggggggggggggThhhhhhhhhhhhhhhhhhhhhhhhhhhTiiiiiiiiiiiiiiiiiiiiiiiiiiiTjjjjjjjjjjjjjjjjjjjjjjjjjjj"</span>

<span class="pl-k">var</span> <span class="pl-s1">_T_index</span> <span class="pl-c1">=</span> [<span class="pl-c1">...</span>]<span class="pl-smi">uint16</span>{<span class="pl-c1">28</span>, <span class="pl-c1">56</span>, <span class="pl-c1">84</span>, <span class="pl-c1">112</span>, <span class="pl-c1">140</span>, <span class="pl-c1">168</span>, <span class="pl-c1">196</span>, <span class="pl-c1">224</span>, <span class="pl-c1">252</span>, <span class="pl-c1">280</span>}

<span class="pl-k">func</span> (<span class="pl-s1">i</span> <span class="pl-smi">T</span>) <span class="pl-en">String</span>() <span class="pl-smi">string</span> {
    <span class="pl-k">if</span> <span class="pl-s1">i</span> <span class="pl-c1">&gt;=</span> <span class="pl-en">T</span>(<span class="pl-en">len</span>(<span class="pl-s1">_T_index</span>)) {
        <span class="pl-k">return</span> <span class="pl-s1">fmt</span>.<span class="pl-en">Sprintf</span>(<span class="pl-s">"T(%d)"</span>, <span class="pl-s1">i</span>)
    }
    <span class="pl-s1">hi</span> <span class="pl-c1">:=</span> <span class="pl-s1">_T_index</span>[<span class="pl-s1">i</span>]
    <span class="pl-s1">lo</span> <span class="pl-c1">:=</span> <span class="pl-en">uint8</span>(<span class="pl-c1">0</span>)
    <span class="pl-k">if</span> <span class="pl-s1">i</span> <span class="pl-c1">&gt;</span> <span class="pl-c1">0</span> {
        <span class="pl-s1">lo</span> <span class="pl-c1">=</span> <span class="pl-s1">_T_index</span>[<span class="pl-s1">i</span><span class="pl-c1">-</span><span class="pl-c1">1</span>]
    }
    <span class="pl-k">return</span> <span class="pl-s1">_T_name</span>[<span class="pl-s1">lo</span>:<span class="pl-s1">hi</span>]
}</pre></div>
<p dir="auto">A pattern that I'm coming up on reasonably frequently in my code is the following:</p>
<div class="highlight highlight-source-go notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="if _, ok := myMap[key]; ok {
    // do some stuff
}"><pre class="notranslate"><span class="pl-k">if</span> <span class="pl-s1">_</span>, <span class="pl-s1">ok</span> <span class="pl-c1">:=</span> <span class="pl-s1">myMap</span>[<span class="pl-s1">key</span>]; <span class="pl-s1">ok</span> {
    <span class="pl-c">// do some stuff</span>
}</pre></div>
<p dir="auto">It seems to me like there would be some (albeit small) gains to be had in the compiler detecting this particular case of discarding the value result of map-lookup in favor of only returning the boolean, and avoid doing the pointer arithmetic necessary to find that value.</p>