<p dir="auto">This code:</p>
<div class="highlight highlight-source-rust notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="trait Foo {}

impl Foo {
    fn foo(&amp;self) {}
}"><pre class="notranslate"><span class="pl-k">trait</span> <span class="pl-smi">Foo</span> <span class="pl-kos">{</span><span class="pl-kos">}</span>

<span class="pl-k">impl</span> <span class="pl-smi">Foo</span> <span class="pl-kos">{</span>
    <span class="pl-k">fn</span> <span class="pl-en">foo</span><span class="pl-kos">(</span><span class="pl-c1">&amp;</span><span class="pl-smi">self</span><span class="pl-kos">)</span> <span class="pl-kos">{</span><span class="pl-kos">}</span>
<span class="pl-kos">}</span></pre></div>
<p dir="auto">generates this error:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="impl-dst.rs:3:1: 5:2 error: duplicate definition of type or module `Foo`
impl-dst.rs:3 impl Foo {
impl-dst.rs:4     fn foo(&amp;self) {}
impl-dst.rs:5 }
impl-dst.rs:1:1: 1:13 note: first definition of type or module `Foo` here
impl-dst.rs:1 trait Foo {}
              ^~~~~~~~~~~~"><pre class="notranslate"><code class="notranslate">impl-dst.rs:3:1: 5:2 error: duplicate definition of type or module `Foo`
impl-dst.rs:3 impl Foo {
impl-dst.rs:4     fn foo(&amp;self) {}
impl-dst.rs:5 }
impl-dst.rs:1:1: 1:13 note: first definition of type or module `Foo` here
impl-dst.rs:1 trait Foo {}
              ^~~~~~~~~~~~
</code></pre></div>
<p dir="auto">I couldn't find any existing issue on this, but this is expected to work, right?</p>
<p dir="auto">Currently, statics <em>must</em> have a type annotation as doing global type inference to resolve the type is a bad idea. However, this leads to some annoying duplication, especially when defining a static struct instance. For example, from <code class="notranslate">extra::base64</code>:</p>
<div class="highlight highlight-source-rust notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="pub static STANDARD: Config =
    Config {char_set: Standard, pad: true, line_length: None};"><pre class="notranslate"><span class="pl-k">pub</span> <span class="pl-k">static</span> <span class="pl-v">STANDARD</span><span class="pl-kos">:</span> <span class="pl-smi">Config</span> =
    <span class="pl-smi">Config</span> <span class="pl-kos">{</span><span class="pl-c1">char_set</span><span class="pl-kos">:</span> <span class="pl-v">Standard</span><span class="pl-kos">,</span> <span class="pl-c1">pad</span><span class="pl-kos">:</span> <span class="pl-c1">true</span><span class="pl-kos">,</span> <span class="pl-c1">line_length</span><span class="pl-kos">:</span> <span class="pl-v">None</span><span class="pl-kos">}</span><span class="pl-kos">;</span></pre></div>
<p dir="auto">There's no ambiguity in the type of the RHS, but the LHS must repeat the type anyways.</p>
<p dir="auto">Would it be possible/reasonable to infer the type of statics from the RHS of the assignment where possible? Things like this would be work:</p>
<div class="highlight highlight-source-rust notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="pub static STANDARD =
    Config {char_set: Standard, pad: true, line_length: None};

pub static HELLO = &quot;hello, world!&quot;;

pub static HELLO_BYTES = bytes!(&quot;hello, world!&quot;);

pub static BAR = 18u8;"><pre class="notranslate"><span class="pl-k">pub</span> <span class="pl-k">static</span> <span class="pl-v">STANDARD</span> =
    <span class="pl-v">Config</span> <span class="pl-kos">{</span>char_set<span class="pl-kos">:</span> <span class="pl-smi">Standard</span><span class="pl-kos">,</span> pad<span class="pl-kos">:</span> true<span class="pl-kos">,</span> <span class="pl-smi">line_length</span><span class="pl-kos">:</span> <span class="pl-smi">None</span><span class="pl-kos">}</span><span class="pl-kos">;</span>

<span class="pl-k">pub</span> <span class="pl-k">static</span> <span class="pl-v">HELLO</span> = <span class="pl-s">"hello, world!"</span><span class="pl-kos">;</span>

<span class="pl-k">pub</span> <span class="pl-k">static</span> <span class="pl-v">HELLO_BYTES</span> = bytes!<span class="pl-kos">(</span><span class="pl-s">"hello, world!"</span><span class="pl-kos">)</span><span class="pl-kos">;</span>

<span class="pl-k">pub</span> <span class="pl-k">static</span> <span class="pl-v">BAR</span> = <span class="pl-c1">18u8</span><span class="pl-kos">;</span></pre></div>
<p dir="auto">but</p>
<div class="highlight highlight-source-rust notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="pub static BAZ = 10;"><pre class="notranslate"><span class="pl-k">pub</span> <span class="pl-k">static</span> <span class="pl-v">BAZ</span> = <span class="pl-c1">10</span><span class="pl-kos">;</span></pre></div>
<p dir="auto">would not since the type isn't specified (or maybe it would resolve to <code class="notranslate">int</code>?). Untyped integer literals and generic types containing them are actually the only things I can think of that would require a type annotation.</p>