Skip to content

Commit 22a10e1

Browse files
lint: treat binders in improper_ctypes instead of ICE
This replaces the in the improper_ctypes lint with a proper diagnostic. Previously, using an binder inside an block caused an internal compiler error. Now the lint emits an FFI-safe diagnostic explaining that binders are not yet supported in FFI. Includes a new UI test to ensure the behavior stays stable.
1 parent ba86c04 commit 22a10e1

File tree

3 files changed

+34
-2
lines changed

3 files changed

+34
-2
lines changed

compiler/rustc_lint/src/types/improper_ctypes.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -669,7 +669,16 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
669669
FfiSafe
670670
}
671671

672-
ty::UnsafeBinder(_) => todo!("FIXME(unsafe_binder)"),
672+
ty::UnsafeBinder(binder) => {
673+
let ty = binder.skip_binder(); // extract the inner type
674+
675+
FfiUnsafe {
676+
ty,
677+
reason: "types containing `unsafe` binders are not yet fully supported in FFI"
678+
.into(),
679+
help: None,
680+
}
681+
}
673682

674683
ty::Param(..)
675684
| ty::Alias(ty::Projection | ty::Inherent | ty::Free, ..)
@@ -1016,7 +1025,6 @@ impl<'tcx> LateLintPass<'tcx> for ImproperCTypesLint {
10161025
| hir::ItemKind::ExternCrate(..) => {}
10171026
}
10181027
}
1019-
10201028
fn check_field_def(&mut self, cx: &LateContext<'tcx>, field: &'tcx hir::FieldDef<'tcx>) {
10211029
self.check_type_for_external_abi_fnptr(
10221030
cx,
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 `&()`, which is not FFI-safe
8+
}
9+
10+
fn main() {}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error: `extern` block uses type `&()`, 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: types containing `unsafe` binders are not yet fully supported in FFI
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

0 commit comments

Comments
 (0)