<div class="highlight highlight-source-rust notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="let i: u8 = -1"><pre class="notranslate"><span class="pl-k">let</span> i<span class="pl-kos">:</span> <span class="pl-smi">u8</span> = -<span class="pl-c1">1</span></pre></div>
<p dir="auto">Replacing -1 by 256 gives the following warning:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content=" literal out of range for its type"><pre class="notranslate"><code class="notranslate"> literal out of range for its type
</code></pre></div>
<p dir="auto">This could also apply to the code above. Unfortunately even an explicit cast to u8 doesn't remove the second warning.</p>
<p dir="auto">Note that clang has a related warning:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="warning: implicit conversion changes signedness: 'int' to 'unsigned int' [-Wsign-conversion]
        unsigned int i = -1;
                     ~   ^~"><pre class="notranslate"><code class="notranslate">warning: implicit conversion changes signedness: 'int' to 'unsigned int' [-Wsign-conversion]
        unsigned int i = -1;
                     ~   ^~
</code></pre></div>
<p dir="auto">Generic code should produce the same code as their monomorphic counterparts. However, a lot of additional <code class="notranslate">nop</code> are produced on generic code. For example:</p>
<div class="highlight highlight-source-rust notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="#[inline(never)]
fn doit_not_generic(a: f32) -&gt; f32 {
    let mut a = a;
    do 1000000000.times {
        a = a * a;
    }

    a
}

#[inline(never)]
fn doit&lt;N: Mul&lt;N, N&gt;&gt;(a: N) -&gt; N {
    let mut a = a;
    do 1000000000.times {
        a = a * a;
    }

    a
}"><pre class="notranslate"><span class="pl-c1">#<span class="pl-kos">[</span>inline<span class="pl-kos">(</span>never<span class="pl-kos">)</span><span class="pl-kos">]</span></span>
<span class="pl-k">fn</span> <span class="pl-en">doit_not_generic</span><span class="pl-kos">(</span><span class="pl-s1">a</span><span class="pl-kos">:</span> <span class="pl-smi">f32</span><span class="pl-kos">)</span> -&gt; <span class="pl-smi">f32</span> <span class="pl-kos">{</span>
    <span class="pl-k">let</span> <span class="pl-k">mut</span> a = a<span class="pl-kos">;</span>
    do <span class="pl-c1">1000000000</span><span class="pl-kos">.</span><span class="pl-c1">times</span><span class="pl-kos"></span> <span class="pl-kos">{</span>
        a = a <span class="pl-c1">*</span> a<span class="pl-kos">;</span>
    <span class="pl-kos">}</span>

    a
<span class="pl-kos">}</span>

<span class="pl-c1">#<span class="pl-kos">[</span>inline<span class="pl-kos">(</span>never<span class="pl-kos">)</span><span class="pl-kos">]</span></span>
<span class="pl-k">fn</span> <span class="pl-en">doit</span><span class="pl-kos">&lt;</span><span class="pl-smi">N</span><span class="pl-kos">:</span> <span class="pl-smi">Mul</span><span class="pl-kos">&lt;</span><span class="pl-smi">N</span><span class="pl-kos">,</span> <span class="pl-smi">N</span><span class="pl-kos">&gt;</span><span class="pl-kos">&gt;</span><span class="pl-kos">(</span><span class="pl-s1">a</span><span class="pl-kos">:</span> <span class="pl-smi">N</span><span class="pl-kos">)</span> -&gt; <span class="pl-smi">N</span> <span class="pl-kos">{</span>
    <span class="pl-k">let</span> <span class="pl-k">mut</span> a = a<span class="pl-kos">;</span>
    do <span class="pl-c1">1000000000</span><span class="pl-kos">.</span><span class="pl-c1">times</span><span class="pl-kos"></span> <span class="pl-kos">{</span>
        a = a <span class="pl-c1">*</span> a<span class="pl-kos">;</span>
    <span class="pl-kos">}</span>

    a
<span class="pl-kos">}</span></pre></div>
<p dir="auto">When called with an <code class="notranslate">f32</code>, produced asm for <code class="notranslate">doit</code> has a lot of <code class="notranslate">nop</code> before the multiplication:</p>
<div class="highlight highlight-source-assembly notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="00000000004025e0 &lt;_ZN9doit_437216_38a5b7ada5228707_0$x2e0E&gt;:
  4025e0:   64 48 3b 24 25 70 00    cmp    %fs:0x70,%rsp
  4025e7:   00 00
  4025e9:   77 1a                   ja     402605 &lt;_ZN9doit_437216_38a5b7ada5228707_0$x2e0E+0x25&gt;
  4025eb:   49 ba 08 00 00 00 00    movabs $0x8,%r10
  4025f2:   00 00 00
  4025f5:   49 bb 00 00 00 00 00    movabs $0x0,%r11
  4025fc:   00 00 00
  4025ff:   e8 28 00 00 00          callq  40262c &lt;__morestack&gt;
  402604:   c3                      retq
  402605:   55                      push   %rbp
  402606:   48 89 e5                mov    %rsp,%rbp
  402609:   f3 0f 10 05 23 01 00    movss  0x123(%rip),%xmm0        # 402734 &lt;_IO_stdin_used+0x14&gt;
  402610:   00
  402611:   48 c7 c0 00 36 65 c4    mov    $0xffffffffc4653600,%rax
  402618:   90                      nop
  402619:   90                      nop
  40261a:   90                      nop
  40261b:   90                      nop
  40261c:   90                      nop
  40261d:   90                      nop
  40261e:   90                      nop
  40261f:   90                      nop
  402620:   f3 0f 59 c0             mulss  %xmm0,%xmm0
  402624:   48 ff c0                inc    %rax
  402627:   75 f7                   jne    402620 &lt;_ZN9doit_437216_38a5b7ada5228707_0$x2e0E+0x40&gt;
  402629:   5d                      pop    %rbp
  40262a:   c3                      retq
  40262b:   90                      nop "><pre class="notranslate"><span class="pl-en">00000000004025e0 &lt;_ZN9doit_437216_38a5b7ada5228707_0</span><span class="pl-c1">$</span><span class="pl-en">x2e0E&gt;:</span>
<span class="pl-en">  4025e0:   </span><span class="pl-c1">64</span><span class="pl-en"> </span><span class="pl-c1">48</span><span class="pl-en"> 3b </span><span class="pl-c1">24</span><span class="pl-en"> </span><span class="pl-c1">25</span><span class="pl-en"> </span><span class="pl-c1">70</span><span class="pl-en"> </span><span class="pl-c1">00</span><span class="pl-en">    </span><span class="pl-k">cmp</span><span class="pl-en">    %</span><span class="pl-v">fs</span><span class="pl-en">:</span><span class="pl-c1">0x70</span><span class="pl-s1">,</span><span class="pl-en">%</span><span class="pl-v">rsp</span>
<span class="pl-en">  4025e7:   </span><span class="pl-c1">00</span><span class="pl-en"> </span><span class="pl-c1">00</span>
<span class="pl-en">  4025e9:   </span><span class="pl-c1">77</span><span class="pl-en"> 1a                   </span><span class="pl-k">ja</span><span class="pl-en">     </span><span class="pl-c1">402605</span><span class="pl-en"> &lt;_ZN9doit_437216_38a5b7ada5228707_0</span><span class="pl-c1">$</span><span class="pl-en">x2e0E</span><span class="pl-s1">+</span><span class="pl-c1">0x25</span><span class="pl-en">&gt;</span>
<span class="pl-en">  4025eb:   </span><span class="pl-c1">49</span><span class="pl-en"> ba </span><span class="pl-c1">08</span><span class="pl-en"> </span><span class="pl-c1">00</span><span class="pl-en"> </span><span class="pl-c1">00</span><span class="pl-en"> </span><span class="pl-c1">00</span><span class="pl-en"> </span><span class="pl-c1">00</span><span class="pl-en">    movabs</span> <span class="pl-c1">$</span><span class="pl-c1">0x8</span><span class="pl-s1">,</span><span class="pl-en">%</span><span class="pl-v">r10</span>
<span class="pl-en">  4025f2:   </span><span class="pl-c1">00</span><span class="pl-en"> </span><span class="pl-c1">00</span><span class="pl-en"> </span><span class="pl-c1">00</span>
<span class="pl-en">  4025f5:   </span><span class="pl-c1">49</span><span class="pl-en"> bb </span><span class="pl-c1">00</span><span class="pl-en"> </span><span class="pl-c1">00</span><span class="pl-en"> </span><span class="pl-c1">00</span><span class="pl-en"> </span><span class="pl-c1">00</span><span class="pl-en"> </span><span class="pl-c1">00</span><span class="pl-en">    movabs</span> <span class="pl-c1">$</span><span class="pl-c1">0x0</span><span class="pl-s1">,</span><span class="pl-en">%</span><span class="pl-v">r11</span>
<span class="pl-en">  4025fc:   </span><span class="pl-c1">00</span><span class="pl-en"> </span><span class="pl-c1">00</span><span class="pl-en"> </span><span class="pl-c1">00</span>
<span class="pl-en">  4025ff:   e8 </span><span class="pl-c1">28</span><span class="pl-en"> </span><span class="pl-c1">00</span><span class="pl-en"> </span><span class="pl-c1">00</span><span class="pl-en"> </span><span class="pl-c1">00</span><span class="pl-en">          callq  40262c &lt;__morestack&gt;</span>
<span class="pl-en">  </span><span class="pl-c1">402604</span><span class="pl-en">:   c3                      retq</span>
<span class="pl-en">  </span><span class="pl-c1">402605</span><span class="pl-en">:   </span><span class="pl-c1">55</span><span class="pl-en">                      </span><span class="pl-k">push</span><span class="pl-en">   %</span><span class="pl-v">rbp</span>
<span class="pl-en">  </span><span class="pl-c1">402606</span><span class="pl-en">:   </span><span class="pl-c1">48</span><span class="pl-en"> </span><span class="pl-c1">89</span><span class="pl-en"> e5                </span><span class="pl-k">mov</span><span class="pl-en">    %</span><span class="pl-v">rsp</span><span class="pl-s1">,</span><span class="pl-en">%</span><span class="pl-v">rbp</span>
<span class="pl-en">  </span><span class="pl-c1">402609</span><span class="pl-en">:   f3 0f </span><span class="pl-c1">10</span><span class="pl-en"> </span><span class="pl-c1">05</span><span class="pl-en"> </span><span class="pl-c1">23</span><span class="pl-en"> </span><span class="pl-c1">01</span><span class="pl-en"> </span><span class="pl-c1">00</span><span class="pl-en">    </span><span class="pl-k">movss</span><span class="pl-en">  </span><span class="pl-c1">0x123</span><span class="pl-en">(%</span><span class="pl-v">rip</span><span class="pl-en">)</span><span class="pl-s1">,</span><span class="pl-en">%</span><span class="pl-v">xmm0</span><span class="pl-en">        # </span><span class="pl-c1">402734</span><span class="pl-en"> &lt;_IO_stdin_used</span><span class="pl-s1">+</span><span class="pl-c1">0x14</span><span class="pl-en">&gt;</span>
<span class="pl-en">  </span><span class="pl-c1">402610</span><span class="pl-en">:   </span><span class="pl-c1">00</span>
<span class="pl-en">  </span><span class="pl-c1">402611</span><span class="pl-en">:   </span><span class="pl-c1">48</span><span class="pl-en"> c7 c0 </span><span class="pl-c1">00</span><span class="pl-en"> </span><span class="pl-c1">36</span><span class="pl-en"> </span><span class="pl-c1">65</span><span class="pl-en"> c4    </span><span class="pl-k">mov</span>    <span class="pl-c1">$</span><span class="pl-c1">0xffffffffc4653600</span><span class="pl-s1">,</span><span class="pl-en">%</span><span class="pl-v">rax</span>
<span class="pl-en">  </span><span class="pl-c1">402618</span><span class="pl-en">:   </span><span class="pl-c1">90</span><span class="pl-en">                      </span><span class="pl-k">nop</span>
<span class="pl-en">  </span><span class="pl-c1">402619</span><span class="pl-en">:   </span><span class="pl-c1">90</span><span class="pl-en">                      </span><span class="pl-k">nop</span>
<span class="pl-en">  40261a:   </span><span class="pl-c1">90</span><span class="pl-en">                      </span><span class="pl-k">nop</span>
<span class="pl-en">  40261b:   </span><span class="pl-c1">90</span><span class="pl-en">                      </span><span class="pl-k">nop</span>
<span class="pl-en">  40261c:   </span><span class="pl-c1">90</span><span class="pl-en">                      </span><span class="pl-k">nop</span>
<span class="pl-en">  40261d:   </span><span class="pl-c1">90</span><span class="pl-en">                      </span><span class="pl-k">nop</span>
<span class="pl-en">  40261e:   </span><span class="pl-c1">90</span><span class="pl-en">                      </span><span class="pl-k">nop</span>
<span class="pl-en">  40261f:   </span><span class="pl-c1">90</span><span class="pl-en">                      </span><span class="pl-k">nop</span>
<span class="pl-en">  </span><span class="pl-c1">402620</span><span class="pl-en">:   f3 0f </span><span class="pl-c1">59</span><span class="pl-en"> c0             </span><span class="pl-k">mulss</span><span class="pl-en">  %</span><span class="pl-v">xmm0</span><span class="pl-s1">,</span><span class="pl-en">%</span><span class="pl-v">xmm0</span>
<span class="pl-en">  </span><span class="pl-c1">402624</span><span class="pl-en">:   </span><span class="pl-c1">48</span><span class="pl-en"> ff c0                </span><span class="pl-k">inc</span><span class="pl-en">    %</span><span class="pl-v">rax</span>
<span class="pl-en">  </span><span class="pl-c1">402627</span><span class="pl-en">:   </span><span class="pl-c1">75</span><span class="pl-en"> f7                   </span><span class="pl-k">jne</span><span class="pl-en">    </span><span class="pl-c1">402620</span><span class="pl-en"> &lt;_ZN9doit_437216_38a5b7ada5228707_0</span><span class="pl-c1">$</span><span class="pl-en">x2e0E</span><span class="pl-s1">+</span><span class="pl-c1">0x40</span><span class="pl-en">&gt;</span>
<span class="pl-en">  </span><span class="pl-c1">402629</span><span class="pl-en">:   5d                      </span><span class="pl-k">pop</span><span class="pl-en">    %</span><span class="pl-v">rbp</span>
<span class="pl-en">  40262a:   c3                      retq</span>
<span class="pl-en">  40262b:   </span><span class="pl-c1">90</span><span class="pl-en">                      </span><span class="pl-k">nop</span><span class="pl-en"> </span></pre></div>
<p dir="auto">Produced asm for <code class="notranslate">doit_not_generic</code> is nop-free before the multiplication:</p>
<div class="highlight highlight-source-assembly notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="0000000000401380 &lt;_ZN16doit_not_generic16_38a5b7ada5228707_0$x2e0E&gt;:
  401380:   64 48 3b 24 25 70 00    cmp    %fs:0x70,%rsp
  401387:   00 00
  401389:   77 1a                   ja     4013a5 &lt;_ZN16doit_not_generic16_38a5b7ada5228707_0$x2e0E+0x25&gt;
  40138b:   49 ba 08 00 00 00 00    movabs $0x8,%r10
  401392:   00 00 00
  401395:   49 bb 00 00 00 00 00    movabs $0x0,%r11
  40139c:   00 00 00
  40139f:   e8 88 12 00 00          callq  40262c &lt;__morestack&gt;
  4013a4:   c3                      retq
  4013a5:   55                      push   %rbp
  4013a6:   48 89 e5                mov    %rsp,%rbp
  4013a9:   48 c7 c0 00 36 65 c4    mov    $0xffffffffc4653600,%rax
  4013b0:   f3 0f 59 c0             mulss  %xmm0,%xmm0
  4013b4:   48 ff c0                inc    %rax
  4013b7:   75 f7                   jne    4013b0 &lt;_ZN16doit_not_generic16_38a5b7ada5228707_0$x2e0E+0x30&gt;
  4013b9:   5d                      pop    %rbp
  4013ba:   c3                      retq
  4013bb:   90                      nop
  4013bc:   90                      nop
  4013bd:   90                      nop
  4013be:   90                      nop
  4013bf:   90                      nop"><pre class="notranslate"><span class="pl-c1">0000000000401380</span><span class="pl-en"> &lt;_ZN16doit_not_generic16_38a5b7ada5228707_0</span><span class="pl-c1">$</span><span class="pl-en">x2e0E&gt;:</span>
<span class="pl-en">  </span><span class="pl-c1">401380</span><span class="pl-en">:   </span><span class="pl-c1">64</span><span class="pl-en"> </span><span class="pl-c1">48</span><span class="pl-en"> 3b </span><span class="pl-c1">24</span><span class="pl-en"> </span><span class="pl-c1">25</span><span class="pl-en"> </span><span class="pl-c1">70</span><span class="pl-en"> </span><span class="pl-c1">00</span><span class="pl-en">    </span><span class="pl-k">cmp</span><span class="pl-en">    %</span><span class="pl-v">fs</span><span class="pl-en">:</span><span class="pl-c1">0x70</span><span class="pl-s1">,</span><span class="pl-en">%</span><span class="pl-v">rsp</span>
<span class="pl-en">  </span><span class="pl-c1">401387</span><span class="pl-en">:   </span><span class="pl-c1">00</span><span class="pl-en"> </span><span class="pl-c1">00</span>
<span class="pl-en">  </span><span class="pl-c1">401389</span><span class="pl-en">:   </span><span class="pl-c1">77</span><span class="pl-en"> 1a                   </span><span class="pl-k">ja</span><span class="pl-en">     4013a5 &lt;_ZN16doit_not_generic16_38a5b7ada5228707_0</span><span class="pl-c1">$</span><span class="pl-en">x2e0E</span><span class="pl-s1">+</span><span class="pl-c1">0x25</span><span class="pl-en">&gt;</span>
<span class="pl-en">  40138b:   </span><span class="pl-c1">49</span><span class="pl-en"> ba </span><span class="pl-c1">08</span><span class="pl-en"> </span><span class="pl-c1">00</span><span class="pl-en"> </span><span class="pl-c1">00</span><span class="pl-en"> </span><span class="pl-c1">00</span><span class="pl-en"> </span><span class="pl-c1">00</span><span class="pl-en">    movabs</span> <span class="pl-c1">$</span><span class="pl-c1">0x8</span><span class="pl-s1">,</span><span class="pl-en">%</span><span class="pl-v">r10</span>
<span class="pl-en">  </span><span class="pl-c1">401392</span><span class="pl-en">:   </span><span class="pl-c1">00</span><span class="pl-en"> </span><span class="pl-c1">00</span><span class="pl-en"> </span><span class="pl-c1">00</span>
<span class="pl-en">  </span><span class="pl-c1">401395</span><span class="pl-en">:   </span><span class="pl-c1">49</span><span class="pl-en"> bb </span><span class="pl-c1">00</span><span class="pl-en"> </span><span class="pl-c1">00</span><span class="pl-en"> </span><span class="pl-c1">00</span><span class="pl-en"> </span><span class="pl-c1">00</span><span class="pl-en"> </span><span class="pl-c1">00</span><span class="pl-en">    movabs</span> <span class="pl-c1">$</span><span class="pl-c1">0x0</span><span class="pl-s1">,</span><span class="pl-en">%</span><span class="pl-v">r11</span>
<span class="pl-en">  40139c:   </span><span class="pl-c1">00</span><span class="pl-en"> </span><span class="pl-c1">00</span><span class="pl-en"> </span><span class="pl-c1">00</span>
<span class="pl-en">  40139f:   e8 </span><span class="pl-c1">88</span><span class="pl-en"> </span><span class="pl-c1">12</span><span class="pl-en"> </span><span class="pl-c1">00</span><span class="pl-en"> </span><span class="pl-c1">00</span><span class="pl-en">          callq  40262c &lt;__morestack&gt;</span>
<span class="pl-en">  4013a4:   c3                      retq</span>
<span class="pl-en">  4013a5:   </span><span class="pl-c1">55</span><span class="pl-en">                      </span><span class="pl-k">push</span><span class="pl-en">   %</span><span class="pl-v">rbp</span>
<span class="pl-en">  4013a6:   </span><span class="pl-c1">48</span><span class="pl-en"> </span><span class="pl-c1">89</span><span class="pl-en"> e5                </span><span class="pl-k">mov</span><span class="pl-en">    %</span><span class="pl-v">rsp</span><span class="pl-s1">,</span><span class="pl-en">%</span><span class="pl-v">rbp</span>
<span class="pl-en">  4013a9:   </span><span class="pl-c1">48</span><span class="pl-en"> c7 c0 </span><span class="pl-c1">00</span><span class="pl-en"> </span><span class="pl-c1">36</span><span class="pl-en"> </span><span class="pl-c1">65</span><span class="pl-en"> c4    </span><span class="pl-k">mov</span>    <span class="pl-c1">$</span><span class="pl-c1">0xffffffffc4653600</span><span class="pl-s1">,</span><span class="pl-en">%</span><span class="pl-v">rax</span>
<span class="pl-en">  4013b0:   f3 0f </span><span class="pl-c1">59</span><span class="pl-en"> c0             </span><span class="pl-k">mulss</span><span class="pl-en">  %</span><span class="pl-v">xmm0</span><span class="pl-s1">,</span><span class="pl-en">%</span><span class="pl-v">xmm0</span>
<span class="pl-en">  4013b4:   </span><span class="pl-c1">48</span><span class="pl-en"> ff c0                </span><span class="pl-k">inc</span><span class="pl-en">    %</span><span class="pl-v">rax</span>
<span class="pl-en">  4013b7:   </span><span class="pl-c1">75</span><span class="pl-en"> f7                   </span><span class="pl-k">jne</span><span class="pl-en">    4013b0 &lt;_ZN16doit_not_generic16_38a5b7ada5228707_0</span><span class="pl-c1">$</span><span class="pl-en">x2e0E</span><span class="pl-s1">+</span><span class="pl-c1">0x30</span><span class="pl-en">&gt;</span>
<span class="pl-en">  4013b9:   5d                      </span><span class="pl-k">pop</span><span class="pl-en">    %</span><span class="pl-v">rbp</span>
<span class="pl-en">  4013ba:   c3                      retq</span>
<span class="pl-en">  4013bb:   </span><span class="pl-c1">90</span><span class="pl-en">                      </span><span class="pl-k">nop</span>
<span class="pl-en">  4013bc:   </span><span class="pl-c1">90</span><span class="pl-en">                      </span><span class="pl-k">nop</span>
<span class="pl-en">  4013bd:   </span><span class="pl-c1">90</span><span class="pl-en">                      </span><span class="pl-k">nop</span>
<span class="pl-en">  4013be:   </span><span class="pl-c1">90</span><span class="pl-en">                      </span><span class="pl-k">nop</span>
<span class="pl-en">  4013bf:   </span><span class="pl-c1">90</span><span class="pl-en">                      </span><span class="pl-k">nop</span></pre></div>