Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions compiler/rustc_lint/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,8 @@ lint_improper_ctypes_union_layout_help = consider adding a `#[repr(C)]` or `#[re
lint_improper_ctypes_union_layout_reason = this union has unspecified layout
lint_improper_ctypes_union_non_exhaustive = this union is non-exhaustive
lint_improper_ctypes_unsafe_binder = unsafe binders are incompatible with foreign function interfaces
lint_int_to_ptr_transmutes = transmuting an integer to a pointer creates a pointer without provenance
.note = this is dangerous because dereferencing the resulting pointer is undefined behavior
.note_exposed_provenance = exposed provenance semantics can be used to create a pointer based on some previously exposed provenance
Expand Down
4 changes: 3 additions & 1 deletion compiler/rustc_lint/src/types/improper_ctypes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,9 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
FfiSafe
}

ty::UnsafeBinder(_) => todo!("FIXME(unsafe_binder)"),
ty::UnsafeBinder(_) => {
FfiUnsafe { ty, reason: fluent::lint_improper_ctypes_unsafe_binder, help: None }
}

ty::Param(..)
| ty::Alias(ty::Projection | ty::Inherent | ty::Free, ..)
Expand Down
10 changes: 10 additions & 0 deletions tests/ui/lint/improper-ctypes/unsafe-binder-basic.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#![feature(unsafe_binders)]
#![expect(incomplete_features)]
#![deny(improper_ctypes)]

extern "C" {
fn exit_2(x: unsafe<'a> &'a ());
//~^ ERROR `extern` block uses type `unsafe<'a> &'a ()`, which is not FFI-safe
}

fn main() {}
15 changes: 15 additions & 0 deletions tests/ui/lint/improper-ctypes/unsafe-binder-basic.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
error: `extern` block uses type `unsafe<'a> &'a ()`, which is not FFI-safe
--> $DIR/unsafe-binder-basic.rs:6:18
|
LL | fn exit_2(x: unsafe<'a> &'a ());
| ^^^^^^^^^^^^^^^^^ not FFI-safe
|
= note: unsafe binders are incompatible with foreign function interfaces
note: the lint level is defined here
--> $DIR/unsafe-binder-basic.rs:3:9
|
LL | #![deny(improper_ctypes)]
| ^^^^^^^^^^^^^^^

error: aborting due to 1 previous error

Loading