title: Parameter type may not live long enough
body: <p>I have a simple program where I am trying to implement a polymorphic account type:</p>
  
  <pre><code>enum AccountType {
      INVALID,
      TYPE1,
      TYPE2,
  }
  
  trait Account {
      fn get_name(&amp;self) -&gt; String;
      fn get_type(&amp;self) -&gt; AccountType;
  }
  
  struct Accounts {
      accounts: Vec&lt;Box&lt;Account&gt;&gt;,
  }
  
  impl Accounts {
      fn new() -&gt; Accounts {
          let accs: Vec&lt;Box&lt;Account&gt;&gt; = Vec::new();
          Accounts { accounts: accs }
      }
  
      fn add_account&lt;A: Account&gt;(&amp;self, account: A) {
          self.accounts.push(Box::new(account));
      }
  }
  
  fn main() {
      let accounts = Accounts::new();
  }
  </code></pre>
  
  <p>(<a href="https://play.rust-lang.org/?gist=2c29133bb6a525d955d35bff96a5feea&amp;version=stable" rel="nofollow noreferrer">Rust Playground</a>)</p>
  
  <p>When I compile it, I see the following error:</p>
  
  <pre class="lang-none prettyprint-override"><code>error[E0310]: the parameter type `A` may not live long enough
    --&gt; src/main.rs:23:28
     |
  22 |     fn add_account&lt;A: Account&gt;(&amp;self, account: A) {
     |                    -- help: consider adding an explicit lifetime bound `A: 'static`...
  23 |         self.accounts.push(Box::new(account));
     |                            ^^^^^^^^^^^^^^^^^
     |
  note: ...so that the type `A` will meet its required lifetime bounds
    --&gt; src/main.rs:23:28
     |
  23 |         self.accounts.push(Box::new(account));
     |                            ^^^^^^^^^^^^^^^^^
  </code></pre>
  
  <p>I have tried adding lifetimes to the type but could not find the right way to do it. Please let me know if this is not the right way to do polymorphism in Rust.</p>