Skip to content

Commit 489e9c1

Browse files
authored
Unrolled build for #149730
Rollup merge of #149730 - SATVIKsynopsis:main, r=Kivooeo lint: emit proper diagnostic for unsafe binders in improper_ctypes instead of ICE Fixes #149719 This PR replaces the `todo!("FIXME(unsafe_binder)")` branch in the `improper_ctypes` lint with a proper diagnostic. Previously, using an unsafe binder inside an extern `"C"` block caused an internal compiler error. This fix now ensures that the compiler now emits a clear and stable error message explaining that types containing unsafe binders are not yet supported in FFI. A new UI test `(unsafe-binder-basic.rs)` is included to ensure this behavior remains stable and prevent regressions.
2 parents 018d269 + 0f4ec28 commit 489e9c1

File tree

4 files changed

+30
-1
lines changed

4 files changed

+30
-1
lines changed

compiler/rustc_lint/messages.ftl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,8 @@ lint_improper_ctypes_union_layout_help = consider adding a `#[repr(C)]` or `#[re
416416
lint_improper_ctypes_union_layout_reason = this union has unspecified layout
417417
lint_improper_ctypes_union_non_exhaustive = this union is non-exhaustive
418418
419+
lint_improper_ctypes_unsafe_binder = unsafe binders are incompatible with foreign function interfaces
420+
419421
lint_int_to_ptr_transmutes = transmuting an integer to a pointer creates a pointer without provenance
420422
.note = this is dangerous because dereferencing the resulting pointer is undefined behavior
421423
.note_exposed_provenance = exposed provenance semantics can be used to create a pointer based on some previously exposed provenance

compiler/rustc_lint/src/types/improper_ctypes.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -669,7 +669,9 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
669669
FfiSafe
670670
}
671671

672-
ty::UnsafeBinder(_) => todo!("FIXME(unsafe_binder)"),
672+
ty::UnsafeBinder(_) => {
673+
FfiUnsafe { ty, reason: fluent::lint_improper_ctypes_unsafe_binder, help: None }
674+
}
673675

674676
ty::Param(..)
675677
| ty::Alias(ty::Projection | ty::Inherent | ty::Free, ..)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#![feature(unsafe_binders)]
2+
#![expect(incomplete_features)]
3+
#![deny(improper_ctypes)]
4+
5+
extern "C" {
6+
fn exit_2(x: unsafe<'a> &'a ());
7+
//~^ ERROR `extern` block uses type `unsafe<'a> &'a ()`, which is not FFI-safe
8+
}
9+
10+
fn main() {}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
error: `extern` block uses type `unsafe<'a> &'a ()`, which is not FFI-safe
2+
--> $DIR/unsafe-binder-basic.rs:6:18
3+
|
4+
LL | fn exit_2(x: unsafe<'a> &'a ());
5+
| ^^^^^^^^^^^^^^^^^ not FFI-safe
6+
|
7+
= note: unsafe binders are incompatible with foreign function interfaces
8+
note: the lint level is defined here
9+
--> $DIR/unsafe-binder-basic.rs:3:9
10+
|
11+
LL | #![deny(improper_ctypes)]
12+
| ^^^^^^^^^^^^^^^
13+
14+
error: aborting due to 1 previous error
15+

0 commit comments

Comments
 (0)