Repository: rust
Issue: `unreachable_code` detection and/or lint seems broken
Labels: A-lints,T-compiler,C-bug,L-unreachable_code

<!--
Thank you for filing a bug report! 🐛 Please provide a short summary of the bug,
along with any information you feel relevant to replicating the bug.
-->

I tried this code:
[playground](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=f5bc8f50be3a8ae2504b21c58ee5e36a)
```rust
fn foo(s:&str) {
    println!("{}",s);
}
fn main() {
    panic!("foo");
    #[allow(unreachable_code)]
    { // Warning points to this block
        foo("oh hi");
        foo("Hello, world!");
    }
    //No warnings if you comment these out:
    #[allow(unreachable_code)]
    foo("Hello, world!");
}
```

I expected to see this happen: no warnings

Instead, this happened: seeing unreachable code warning while the lint to allow it implies that it shouldn't warn!
```rust
 Compiling playground v0.0.1 (/playground)
warning: unreachable statement
  --> src/main.rs:7:5
   |
5  |       panic!("foo");
   |       ------------- any code following this expression is unreachable
6  |       #[allow(unreachable_code)]
7  | /     { // Warning points to this block
8  | |         foo("oh hi");
9  | |         foo("Hello, world!");
10 | |     }
   | |_____^ unreachable statement
   |
   = note: `#[warn(unreachable_code)]` on by default

warning: `playground` (bin "playground") generated 1 warning
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.73s
```

<details>

Now look what happens if nothing else follows:
[playground](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=88878553b5e47c411bed34655d6fcd94)
```rust
fn foo(s:&str) {
    println!("{}",s);
}
fn main() {
    panic!("foo");
    #[allow(unreachable_code)]
    { // Warning points to this block
        foo("oh hi");
        foo("Hello, world!");
    }
    //No warnings if you comment these out:
    //#[allow(unreachable_code)]
    //foo("Hello, world!");
}
```
output:
```rust
   Compiling playground v0.0.1 (/playground)
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.61s
     Running `target/debug/playground`
```
that's right, no warnings!
But since the warning was for the block above, why would changing the next statements affect it?!

Am I missing something? or something seems very broken.

If I put a comma after the block, same issue:
[playground](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=246e3fec2f399ced208ec30bb9ccd57e)
```rust
fn foo(s: &str) {
    println!("{}", s);
}
fn main() {
    panic!("foo");
    #[allow(unreachable_code)]
    {
        // Warning points to this block
        foo("oh hi");
        foo("Hello, world!");
    }; //remove this comma to fix it
}
```
output:
```rust
Compiling playground v0.0.1 (/playground)
warning: unreachable statement
  --> src/main.rs:7:5
   |
5  |       panic!("foo");
   |       ------------- any code following this expression is unreachable
6  |       #[allow(unreachable_code)]
7  | /     {
8  | |         // Warning points to this block
9  | |         foo("oh hi");
10 | |         foo("Hello, world!");
11 | |     }; //remove this comma to fix it
   | |______^ unreachable statement
   |
   = note: `#[warn(unreachable_code)]` on by default

warning: `playground` (bin "playground") generated 1 warning
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.62s
```
Remove the comma and no warnings again. But maybe this kinda makes sense with the comma, unclear.

</details>

### 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`:
lastest nightly or stable on playground, or even `rustc 1.78.0-nightly (9b00956e5 2024-04-29) (gentoo)`, or latest nightly on gentoo:
```
$ rustv
rustc 1.81.0-nightly (684b3553f 2024-06-20)
binary: rustc
commit-hash: 684b3553f70148ded97a80371c2405984d4f6aa7
commit-date: 2024-06-20
host: x86_64-unknown-linux-gnu
release: 1.81.0-nightly
LLVM version: 18.1.7
cargo 1.81.0-nightly (3ed207e41 2024-06-18)
release: 1.81.0-nightly
commit-hash: 3ed207e416fb2f678a40cc79c02dcf4f936a21ce
commit-date: 2024-06-18
host: x86_64-unknown-linux-gnu
libgit2: 1.8.1 (sys:0.19.0 vendored)
libcurl: 8.6.0-DEV (sys:0.4.72+curl-8.6.0 vendored ssl:OpenSSL/1.1.1w)
ssl: OpenSSL 1.1.1w  11 Sep 2023
os: Gentoo Linux 2.15.0 [64-bit]
```