Closed
Description
Probably the most amusing bug I will encounter today :)
I tried this code:
#![feature(unsafe_binders)]
#![allow(incomplete_features)]
#![warn(unused_lifetimes)]
use std::unsafe_binder::unwrap_binder;
#[derive(Copy, Clone)]
pub struct S([usize; 8]);
// Regression test for <https://github.com/rust-lang/rust/issues/141418>.
pub fn by_value(x: unsafe<'a> S) -> usize {
unsafe { (|| unwrap_binder!(x).0[0])() }
}
fn main() {}
I expected to see this happen: explanation
Instead, this happened: explanation
Meta
rustc --version --verbose
:
rustc 1.89.0-nightly (1bbd62e54 2025-05-29)
binary: rustc
commit-hash: 1bbd62e547ba5cc08ccb44c27def3d33195d2dd5
commit-date: 2025-05-29
host: x86_64-unknown-linux-gnu
release: 1.89.0-nightly
LLVM version: 20.1.5
cargo check:
warning: lifetime parameter `'a` never used
--> src/main.rs:11:27
|
11 | pub fn by_value(x: unsafe<'a> S) -> usize {
| -------^^--- help: elide the unused lifetime
|
note: the lint level is defined here
--> src/main.rs:3:9
|
3 | #![warn(unused_lifetimes)]
| ^^^^^^^^^^^^^^^^
cargo fix
The following errors were reported:
error: expected type, found `)`
--> src/main.rs:11:20
|
11 | pub fn by_value(x: ) -> usize {
| ^ expected type
error[E0425]: cannot find value `x` in this scope
--> src/main.rs:12:33
|
8 | pub struct S([usize; 8]);
| ------------------------- similarly named tuple struct `S` defined here
...
12 | unsafe { (|| unwrap_binder!(x).0[0])() }
| ^ help: a tuple struct with a similar name exists: `S`
error: aborting due to 2 previous errors
it removes the entire unsafe<'a> S
😆
Metadata
Metadata
Assignees
Labels
Area: Lints (warnings about flaws in source code) such as unused_mut.Area: Suggestions generated by the compiler applied by `cargo fix`Category: This is a bug.Diagnostics: A structured suggestion resulting in incorrect code.`#![feature(unsafe_binders)]`Lint: unused_lifetimesRelevant to the compiler team, which will review and decide on the PR/issue.