Skip to content

Commit 1486b7f

Browse files
authored
Rollup merge of rust-lang#64641 - cuviper:extern-rust-ctypes, r=estebank
Exempt extern "Rust" from improper_ctypes It should be fine for Rust ABIs to involve any Rust type. Fixes rust-lang#64593.
2 parents 6254d7a + 9f374da commit 1486b7f

File tree

4 files changed

+17
-3
lines changed

4 files changed

+17
-3
lines changed

src/liballoc/alloc.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ pub(crate) unsafe fn box_free<T: ?Sized>(ptr: Unique<T>) {
240240
#[stable(feature = "global_alloc", since = "1.28.0")]
241241
#[rustc_allocator_nounwind]
242242
pub fn handle_alloc_error(layout: Layout) -> ! {
243-
#[allow(improper_ctypes)]
243+
#[cfg_attr(bootstrap, allow(improper_ctypes))]
244244
extern "Rust" {
245245
#[lang = "oom"]
246246
fn oom_impl(layout: Layout) -> !;

src/libcore/panicking.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ pub fn panic_fmt(fmt: fmt::Arguments<'_>, file_line_col: &(&'static str, u32, u3
7171
}
7272

7373
// NOTE This function never crosses the FFI boundary; it's a Rust-to-Rust call
74-
#[allow(improper_ctypes)] // PanicInfo contains a trait object which is not FFI safe
74+
#[cfg_attr(boostrap_stdarch_ignore_this, allow(improper_ctypes))]
7575
extern "Rust" {
7676
#[lang = "panic_impl"]
7777
fn panic_impl(pi: &PanicInfo<'_>) -> !;

src/librustc_lint/types.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -975,7 +975,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ImproperCTypes {
975975
fn check_foreign_item(&mut self, cx: &LateContext<'_, '_>, it: &hir::ForeignItem) {
976976
let mut vis = ImproperCTypesVisitor { cx };
977977
let abi = cx.tcx.hir().get_foreign_abi(it.hir_id);
978-
if abi != Abi::RustIntrinsic && abi != Abi::PlatformIntrinsic {
978+
if let Abi::Rust | Abi::RustCall | Abi::RustIntrinsic | Abi::PlatformIntrinsic = abi {
979+
// Don't worry about types in internal ABIs.
980+
} else {
979981
match it.node {
980982
hir::ForeignItemKind::Fn(ref decl, _, _) => {
981983
vis.check_foreign_fn(it.hir_id, decl);

src/test/ui/issues/issue-64593.rs

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// check-pass
2+
#![deny(improper_ctypes)]
3+
4+
pub struct Error(std::num::NonZeroU32);
5+
6+
extern "Rust" {
7+
fn foo(dest: &mut [u8]) -> Result<(), Error>;
8+
}
9+
10+
fn main() {
11+
let _ = unsafe { foo(&mut []) };
12+
}

0 commit comments

Comments
 (0)