Skip to content

unused_lifetimes yeets unsafe binders #141758

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
matthiaskrgr opened this issue May 30, 2025 · 0 comments · Fixed by #141781
Closed

unused_lifetimes yeets unsafe binders #141758

matthiaskrgr opened this issue May 30, 2025 · 0 comments · Fixed by #141781
Labels
A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` C-bug Category: This is a bug. D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. F-unsafe_binders `#![feature(unsafe_binders)]` L-unused_lifetimes Lint: unused_lifetimes T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@matthiaskrgr
Copy link
Member

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 😆

@matthiaskrgr matthiaskrgr added the C-bug Category: This is a bug. label May 30, 2025
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label May 30, 2025
@matthiaskrgr matthiaskrgr added A-diagnostics Area: Messages for errors, warnings, and lints L-unused_lifetimes Lint: unused_lifetimes F-unsafe_binders `#![feature(unsafe_binders)]` and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels May 30, 2025
@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label May 30, 2025
@fmease fmease added A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. and removed A-diagnostics Area: Messages for errors, warnings, and lints labels May 30, 2025
workingjubilee added a commit to workingjubilee/rustc that referenced this issue May 30, 2025
…mes, r=compiler-errors

Fix spans for unsafe binders

closes rust-lang#141758

r? `@compiler-errors`
@bors bors closed this as completed in 955ebfc May 31, 2025
rust-timer added a commit that referenced this issue May 31, 2025
Rollup merge of #141781 - matthewjasper:unused-unsafe-lifetimes, r=compiler-errors

Fix spans for unsafe binders

closes #141758

r? ``@compiler-errors``
github-actions bot pushed a commit to rust-lang/miri that referenced this issue May 31, 2025
…mpiler-errors

Fix spans for unsafe binders

closes rust-lang/rust#141758

r? ``@compiler-errors``
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` C-bug Category: This is a bug. D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. F-unsafe_binders `#![feature(unsafe_binders)]` L-unused_lifetimes Lint: unused_lifetimes T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants