title: What is the intended way to match an interior mutable enum?
body: <p>These are the ways I could come up with to try matching a reference counted, interior mutable enum: </p>
  
  <pre><code>#![allow(unused)]
  
  use std::cell::RefCell;
  use std::rc::Rc;
  
  #[derive(Debug, Clone, PartialEq)]
  struct Bar {
      some_bar: Vec&lt;f64&gt;,
  }
  #[derive(Debug, Clone, PartialEq)]
  struct Baz {
      some_baz: i32,
  }
  
  #[derive(Debug, Clone, PartialEq)]
  enum Foo {
      Bar(Bar),
      Baz(Baz),
  }
  
  fn is_baz(foo_ref: Rc&lt;RefCell&lt;Foo&gt;&gt;) -&gt; bool {
      match foo_ref {
          Foo::Bar(_) =&gt; false,
          Foo::Baz(_) =&gt; true,
      }
  }
  
  fn is_baz_borrow(foo_ref: Rc&lt;RefCell&lt;Foo&gt;&gt;) -&gt; bool {
      match foo_ref.borrow() {
          Foo::Bar(_) =&gt; false,
          Foo::Baz(_) =&gt; true,
      }
  }
  
  fn is_baz_deref(foo_ref: Rc&lt;RefCell&lt;Foo&gt;&gt;) -&gt; bool {
      match *foo_ref {
          Foo::Bar(_) =&gt; false,
          Foo::Baz(_) =&gt; true,
      }
  }
  
  fn is_baz_get_mut(foo_ref: Rc&lt;RefCell&lt;Foo&gt;&gt;) -&gt; bool {
      match foo_ref.get_mut() {
          Foo::Bar(_) =&gt; false,
          Foo::Baz(_) =&gt; true,
      }
  }
  
  fn is_baz_as_ref(foo_ref: Rc&lt;RefCell&lt;Foo&gt;&gt;) -&gt; bool {
      match foo_ref.as_ref() {
          Foo::Bar(_) =&gt; false,
          Foo::Baz(_) =&gt; true,
      }
  }
  
  fn is_baz_as_ref_borrow(foo_ref: Rc&lt;RefCell&lt;Foo&gt;&gt;) -&gt; bool {
      match foo_ref.as_ref().borrow() {
          Foo::Bar(_) =&gt; false,
          Foo::Baz(_) =&gt; true,
      }
  }
  
  fn is_baz_get_mut_mut(mut foo_ref: Rc&lt;RefCell&lt;Foo&gt;&gt;) -&gt; bool {
      match foo_ref.get_mut() {
          Foo::Bar(_) =&gt; false,
          Foo::Baz(_) =&gt; true,
      }
  }
  
  fn main() {
      let foo = Foo::Bar(Bar {
          some_bar: vec![1.1, 999.0],
      });
      let foo_ref = Rc::new(RefCell::new(foo));
  
      // none of these work
      assert!(is_baz(foo_ref.clone()));
      assert!(is_baz_borrow(foo_ref.clone()));
      assert!(is_baz_deref(foo_ref.clone()));
      assert!(is_baz_get_mut(foo_ref.clone()));
      assert!(is_baz_as_ref(foo_ref.clone()));
      assert!(is_baz_as_ref_borrow(foo_ref.clone()));
  
      // this works
      assert!(is_baz_get_mut_mut(foo_ref.clone()));
  }
  </code></pre>
  
  <p><a href="https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=a76f1425c0c551f1daa70b408f955222" rel="nofollow noreferrer">Playground</a></p>
  
  <p>However most ways create an mismatched types error like</p>
  
  <pre class="lang-none prettyprint-override"><code>error[E0308]: mismatched types
    --&gt; src/main.rs:24:9
     |
  24 |         Foo::Baz(_) =&gt; true
     |         ^^^^^^^^^^^ expected struct `std::rc::Rc`, found enum `Foo`
     |
     = note: expected type `std::rc::Rc&lt;std::cell::RefCell&lt;Foo&gt;&gt;`
                found type `Foo`
  </code></pre>
  
  <p>or </p>
  
  <pre class="lang-none prettyprint-override"><code>error[E0308]: mismatched types
    --&gt; src/main.rs:30:9
     |
  30 |         Foo::Bar(_) =&gt; false,
     |         ^^^^^^^^^^^ expected struct `std::cell::Ref`, found enum `Foo`
     |
     = note: expected type `std::cell::Ref&lt;'_, Foo, &gt;`
                found type `Foo`
  </code></pre>
  
  <p>The only way that worked is this:</p>
  
  <pre class="lang-rust prettyprint-override"><code>match foo_ref.get_mut() {
      Foo::Bar(_) =&gt; false,
      Foo::Baz(_) =&gt; true
  }
  </code></pre>
  
  <p>Is this the intended way? Even for read only access?</p>