Regression test for let x = offset_of!(..) else { .. } span

This commit is contained in:
Zalathar 2026-02-07 23:16:12 +11:00
parent 06cafcbe08
commit fb5a4dca32
2 changed files with 36 additions and 0 deletions

View file

@ -0,0 +1,19 @@
#![crate_type = "rlib"]
//@ edition: 2024
//@ check-pass
// Using `offset_of` in the RHS of a let-else statement should not produce
// malformed spans or a blank diagnostic snippet.
//
// Regression test for <https://github.com/rust-lang/rust/pull/152284>.
fn init_to_offset_of() {
use std::mem::offset_of;
struct Foo { field: u32 }
if let x = offset_of!(Foo, field) {}
//~^ WARN irrefutable `if let` pattern
let x = offset_of!(Foo, field) else { return; };
//~^ WARN irrefutable `let...else` pattern
}

View file

@ -0,0 +1,17 @@
warning: irrefutable `if let` pattern
--> $DIR/let-offset-of.rs:14:8
|
LL | if let x = offset_of!(Foo, field) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: this pattern will always match, so the `if let` is useless
= help: consider replacing the `if let` with a `let`
= note: `#[warn(irrefutable_let_patterns)]` on by default
warning: irrefutable `let...else` pattern
|
= note: this pattern will always match, so the `else` clause is useless
= help: consider removing the `else` clause
warning: 2 warnings emitted