title: Unable to create a local function because "can't capture dynamic environment in a fn item"
body: <p>Is there any way to create a local function like this Python code?</p>
  
  
  
  <pre><code>def h():
      final = []
      def a():
          for i in range(5):
              final.append(i)
          a()
          return final
  </code></pre>
  
  <p>I tried it, but failed:</p>
  
  <pre><code>fn h() -&gt; Vec&lt;i32&gt; {
      let mut ff = vec![];
      fn a() {
          for i in 0..5 {
              ff.push(i)
          }
      };
      a();
      ff
  }
  </code></pre>
  
  <pre class="lang-none prettyprint-override"><code> error[E0434]: can't capture dynamic environment in a fn item; use the || { ... } closure form instead
   --&gt; src/main.rs:5:13
    |
  5 |             ff.push(i)
    |             ^^
  </code></pre>