Skip to content

Commit b5031dd

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 b5031dd

File tree

3 files changed

+46
-2
lines changed

3 files changed

+46
-2
lines changed

compiler/rustc_lint/src/types/improper_ctypes.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -669,7 +669,17 @@ 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+
let _vars = binder.bound_vars(); // get bound vars if needed
675+
676+
FfiUnsafe {
677+
ty,
678+
reason: "types containing `unsafe` binders are not yet fully supported in FFI"
679+
.into(),
680+
help: None,
681+
}
682+
}
673683

674684
ty::Param(..)
675685
| ty::Alias(ty::Projection | ty::Inherent | ty::Free, ..)
@@ -1016,7 +1026,6 @@ impl<'tcx> LateLintPass<'tcx> for ImproperCTypesLint {
10161026
| hir::ItemKind::ExternCrate(..) => {}
10171027
}
10181028
}
1019-
10201029
fn check_field_def(&mut self, cx: &LateContext<'tcx>, field: &'tcx hir::FieldDef<'tcx>) {
10211030
self.check_type_for_external_abi_fnptr(
10221031
cx,
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// build-fail
2+
#![feature(unsafe_binders)]
3+
//~^ WARN the feature `unsafe_binders` is incomplete
4+
#![deny(improper_ctypes)]
5+
6+
extern "C" {
7+
fn exit_2(x: unsafe<'a> &'a ());
8+
//~^ ERROR `extern` block uses type `&()`, which is not FFI-safe
9+
}
10+
11+
fn main() {}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
warning: the feature `unsafe_binders` is incomplete and may not be safe to use and/or cause compiler crashes
2+
--> $DIR/unsafe-binder-basic.rs:2:12
3+
|
4+
LL | #![feature(unsafe_binders)]
5+
| ^^^^^^^^^^^^^^
6+
|
7+
= note: see issue #130516 <https://github.com/rust-lang/rust/issues/130516> for more information
8+
= note: `#[warn(incomplete_features)]` on by default
9+
10+
error: `extern` block uses type `&()`, which is not FFI-safe
11+
--> $DIR/unsafe-binder-basic.rs:7:18
12+
|
13+
LL | fn exit_2(x: unsafe<'a> &'a ());
14+
| ^^^^^^^^^^^^^^^^^ not FFI-safe
15+
|
16+
= note: types containing `unsafe` binders are not yet fully supported in FFI
17+
note: the lint level is defined here
18+
--> $DIR/unsafe-binder-basic.rs:4:9
19+
|
20+
LL | #![deny(improper_ctypes)]
21+
| ^^^^^^^^^^^^^^^
22+
23+
error: aborting due to 1 previous error; 1 warning emitted
24+

0 commit comments

Comments
 (0)