From fb5a4dca328798ec30fa001aed16f19ceb32e000 Mon Sep 17 00:00:00 2001 From: Zalathar Date: Sat, 7 Feb 2026 23:16:12 +1100 Subject: [PATCH] Regression test for `let x = offset_of!(..) else { .. }` span --- tests/ui/span/let-offset-of.rs | 19 +++++++++++++++++++ tests/ui/span/let-offset-of.stderr | 17 +++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 tests/ui/span/let-offset-of.rs create mode 100644 tests/ui/span/let-offset-of.stderr diff --git a/tests/ui/span/let-offset-of.rs b/tests/ui/span/let-offset-of.rs new file mode 100644 index 000000000000..99b34a192847 --- /dev/null +++ b/tests/ui/span/let-offset-of.rs @@ -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 . + +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 +} diff --git a/tests/ui/span/let-offset-of.stderr b/tests/ui/span/let-offset-of.stderr new file mode 100644 index 000000000000..a0ef3fcc5ef5 --- /dev/null +++ b/tests/ui/span/let-offset-of.stderr @@ -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 +