Skip to content

Commit 1adc7b7

Browse files
lint: treat unsafe binders in improper_ctypes instead of ICE
This commit replaces the previous task for unsafe_binders with a proper diagnostic updates the wording for consistency and switches the message to the fluent error system. The diagnostic now reports the full unsafe binder type unsafe<a> &a () instead of just the inner &() matching the highlighted span. the ui test stderr has been updated accordingly.
1 parent 22a10e1 commit 1adc7b7

File tree

4 files changed

+8
-13
lines changed

4 files changed

+8
-13
lines changed

compiler/rustc_lint/messages.ftl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,6 @@ lint_implicit_unsafe_autorefs = implicit autoref creates a reference to the dere
360360
lint_improper_ctypes = `extern` {$desc} uses type `{$ty}`, which is not FFI-safe
361361
.label = not FFI-safe
362362
.note = the type is defined here
363-
364363
lint_improper_ctypes_array_help = consider passing a pointer to the array
365364
366365
lint_improper_ctypes_array_reason = passing raw arrays by value is not FFI-safe
@@ -416,6 +415,8 @@ lint_improper_ctypes_union_layout_help = consider adding a `#[repr(C)]` or `#[re
416415
lint_improper_ctypes_union_layout_reason = this union has unspecified layout
417416
lint_improper_ctypes_union_non_exhaustive = this union is non-exhaustive
418417
418+
lint_improper_ctypes_unsafe_binder = unsafe binders are incompatible with foreign function interfaces
419+
419420
lint_int_to_ptr_transmutes = transmuting an integer to a pointer creates a pointer without provenance
420421
.note = this is dangerous because dereferencing the resulting pointer is undefined behavior
421422
.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: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -669,15 +669,8 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
669669
FfiSafe
670670
}
671671

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-
}
672+
ty::UnsafeBinder(_binder) => {
673+
FfiUnsafe { ty, reason: fluent::lint_improper_ctypes_unsafe_binder, help: None }
681674
}
682675

683676
ty::Param(..)

tests/ui/lint/improper-ctypes/unsafe-binder-basic.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

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

1010
fn main() {}
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1-
error: `extern` block uses type `&()`, which is not FFI-safe
1+
error: `extern` block uses type `unsafe<'a> &'a ()`, which is not FFI-safe
22
--> $DIR/unsafe-binder-basic.rs:6:18
33
|
44
LL | fn exit_2(x: unsafe<'a> &'a ());
55
| ^^^^^^^^^^^^^^^^^ not FFI-safe
66
|
7-
= note: types containing `unsafe` binders are not yet fully supported in FFI
7+
= note: unsafe binders are incompatible with foreign function interfaces
88
note: the lint level is defined here
99
--> $DIR/unsafe-binder-basic.rs:3:9
1010
|
1111
LL | #![deny(improper_ctypes)]
1212
| ^^^^^^^^^^^^^^^
1313

1414
error: aborting due to 1 previous error
15+

0 commit comments

Comments
 (0)