title: Why is Rust's .expect() called expect?
body: <p>Rust's <code>.expect()</code> is one of the most surprising names in the Result/Option space. While <code>unwrap</code> makes sense -- get a value from a <code>Result</code> by &quot;unwrapping&quot; it -- <code>expect</code> is surprisingly counterintuitive (to me).</p>
  <p>Since so much of Rust is inspired by conventions from functional programming languages, I have been assuming that this is another example of &quot;strange homage to obscurity,&quot; but when I asked the Duck it couldn't find an answer for me.</p>
  <p>So, I give up. Why is <code>.expect()</code> the name for Rust's <code>.unwrap_or_panic_with_this_message()</code> function? Is this a reference to a feature in yet another functional language? Is it back-handed shade (or a complement) to Tcl? The result of too many late nights and too much Espresso at Mozilla?</p>
  <p>What is the etymology of this plucky (but fierce!) little member of the standard library?</p>
  <p><strong>Edit:</strong></p>
  <p>Great news, everyone! After more than a year, we now have both an &quot;explanation&quot; in @GManNickG's tremendously well-researched and documented answer, below, and a &quot;mental model&quot; provided by @Peng's comment and link:</p>
  <p><a href="https://doc.rust-lang.org/std/error/index.html#common-message-styles" rel="nofollow noreferrer">https://doc.rust-lang.org/std/error/index.html#common-message-styles</a></p>
  <p>In short, it is now recommended that diagnostics for <code>expect()</code> should be written as &quot;expect...should&quot; or maybe &quot;expect...should have&quot;. This makes more sense in the diagnostic output (see the link for examples) but also makes the source code scan better:</p>
  <pre><code>foo.expect(&quot;something bad happened&quot;)    // NO!
  
  foo.expect(&quot;gollywumpus should be current&quot;) // YES!
  </code></pre>