Repository: rust
Issue: 30% performance hit due to changing of the code in the non evaluating match arm 
Labels: I-slow,C-bug,C-discussion

I tried this code: related to #110764 

```rust
#![feature(test)]
extern crate test;
use test::Bencher;

use std::{self, hint::black_box};
#[derive(Debug)]
struct Error {
    message: String,
}
type Result<T> = std::result::Result<T, Error>;

struct Deserializer<'a> {
    bytes: &'a [u8],
    idx: usize,
}

impl<'a> Deserializer<'a> {
    pub fn deserialize_bytes<const N: usize>(&mut self) -> Result<[u8; N]> {
        match self.bytes.get(self.idx..self.idx + N) {
            Some(v) => {
                self.idx += N;
                Ok(v.try_into().unwrap()) // this shall not panic since slice method succeeded
            }
            None => {
                // ****** WE KNOW THIS ARM IS NEVER MATCHED BUT CHANGING IRRELEVANT HERE AFFECTS BENCHMARKS ******
                let e = Error {
                    message: "".to_string(),                            // (A)    test test_playground ... bench:         702 ns/iter (+/- 76)
                    // message: format!("{}", "a".repeat(usize::MAX)),  // (B)    test test_playground ... bench:         977 ns/iter (+/- 112)
                };

                // uncommenting print                                   // (A=on) test test_playground ... bench:       1,347 ns/iter (+/- 58)
                // uncommenting print                                   // (B=on) test test_playground ... bench:         972 ns/iter (+/- 104)
                // println!("Does not appear in terminal");                  
                Err(e)
            }
        }
    }
    pub fn new(bytes: &'a [u8]) -> Self {
        Self { bytes, idx: 0 }
    }
}

fn workload(buf: &[u8]) -> Result<()> {
    let mut des = black_box(Deserializer::new(buf));
    for _ in 0..400 {
        let r = black_box(des.deserialize_bytes::<2>());
        match r {
            Err(e) => {
                panic!("failed {}", e.message);
            }
            _ => {}
        }
    }
    Ok(())
}
#[bench]
fn test_playground(b: &mut Bencher) {
    let buf: [u8; 1024] = [0; 1024];
    b.iter(|| workload(&buf));
}

```

I expected to see this happen:

I expected to not see performance degradation of the function by making changes to the match arm which is never evaluated.

Instead, this happened: 

Changing the string of the error message of adding println! command in the march arm that will never be evaluated significantly affects performance of the function, I have achieved identical results on stable version of rust and using criterion instead of std bench, but included result here from the nightly so that it is easy to replicate for someone else.

I am certain that match arm is not evaluated because  the workload is set to panic but it succeeds nevertheless. 

### Meta
<!--
If you're using the stable version of the compiler, you should also check if the
bug also exists in the beta or nightly versions.
-->

`rustc --version --verbose`:
```
rustc 1.71.0-nightly (8bdcc62cb 2023-04-20)
binary: rustc
commit-hash: 8bdcc62cb0362869f0e7b43a6ae4f96b953d3cbc
commit-date: 2023-04-20
host: x86_64-apple-darwin
release: 1.71.0-nightly
LLVM version: 16.0.2
```

<!--
Include a backtrace in the code block by setting `RUST_BACKTRACE=1` in your
environment. E.g. `RUST_BACKTRACE=1 cargo build`.
-->
<details><summary>Backtrace</summary>
<p>

```
<backtrace>
```

</p>
</details>