title: How to return a reference into a Rc<RefCell<>> function argument?
body: <p>This is a minimal reproducible error that is taken from an interpreter I'm writing. As I understand, I should be able to return a reference to a field of a struct in a RefCell, since the RefCell has a sufficient lifetime. However, the compiler is telling me I cannot return a reference to a value owned by the current function, which is baffling to me frankly.</p>
  <pre class="lang-rust prettyprint-override"><code>use std::cell::RefCell;
  use std::collections::HashMap;
  use std::rc::Rc;
  
  #[derive(Debug)]
  enum Value {
      Number,
      String,
  }
  
  struct Object {
      pub properties: HashMap&lt;String, Value&gt;,
  }
  
  impl Object {
      pub fn get_property(&amp;mut self, name: &amp;str) -&gt; Option&lt;&amp;mut Value&gt; {
          self.properties.get_mut(name)
      }
  }
  
  fn get_property(global_object_rcc: Rc&lt;RefCell&lt;Object&gt;&gt;, name: &amp;str) -&gt; Option&lt;&amp;mut Value&gt; {
      // Rust cannot verify that this Rc isn't the last Rc that just got moved into this function?
      global_object_rcc.borrow_mut().get_property(name)
  }
  
  fn main() {
      // Construct global object
      let mut global_object = Object {
          properties: HashMap::new(),
      };
  
      // Give it a property
      global_object
          .properties
          .insert(&quot;Test&quot;.to_owned(), Value::Number);
  
      // Put it in a Rc&lt;RefCell&gt; (rcc) for sharing
      let global_object_rcc = Rc::new(RefCell::new(global_object));
  
      // Get a reference to its property, should be valid because the reference only needs to live
      // as long as the global_object
      let property = get_property(global_object_rcc, &quot;Test&quot;);
  
      dbg!(&amp;property);
  }
  </code></pre>
  <p>Here is the error message I get:</p>
  <pre><code>error[E0515]: cannot return value referencing temporary value
    --&gt; src\main.rs:23:5
     |
  23 |     global_object_rcc.borrow_mut().get_property(name)
     |     ------------------------------^^^^^^^^^^^^^^^^^^^
     |     |
     |     returns a value referencing data owned by the current function
     |     temporary value created here
  </code></pre>