Skip to content

Commit

Permalink
Rollup merge of #64641 - cuviper:extern-rust-ctypes, r=estebank
Browse files Browse the repository at this point in the history
Exempt extern "Rust" from improper_ctypes

It should be fine for Rust ABIs to involve any Rust type.

Fixes #64593.
  • Loading branch information
Centril committed Sep 21, 2019
2 parents 6254d7a + 9f374da commit 1486b7f
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/liballoc/alloc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ pub(crate) unsafe fn box_free<T: ?Sized>(ptr: Unique<T>) {
#[stable(feature = "global_alloc", since = "1.28.0")]
#[rustc_allocator_nounwind]
pub fn handle_alloc_error(layout: Layout) -> ! {
#[allow(improper_ctypes)]
#[cfg_attr(bootstrap, allow(improper_ctypes))]
extern "Rust" {
#[lang = "oom"]
fn oom_impl(layout: Layout) -> !;
Expand Down
2 changes: 1 addition & 1 deletion src/libcore/panicking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ pub fn panic_fmt(fmt: fmt::Arguments<'_>, file_line_col: &(&'static str, u32, u3
}

// NOTE This function never crosses the FFI boundary; it's a Rust-to-Rust call
#[allow(improper_ctypes)] // PanicInfo contains a trait object which is not FFI safe
#[cfg_attr(boostrap_stdarch_ignore_this, allow(improper_ctypes))]
extern "Rust" {
#[lang = "panic_impl"]
fn panic_impl(pi: &PanicInfo<'_>) -> !;
Expand Down
4 changes: 3 additions & 1 deletion src/librustc_lint/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -975,7 +975,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ImproperCTypes {
fn check_foreign_item(&mut self, cx: &LateContext<'_, '_>, it: &hir::ForeignItem) {
let mut vis = ImproperCTypesVisitor { cx };
let abi = cx.tcx.hir().get_foreign_abi(it.hir_id);
if abi != Abi::RustIntrinsic && abi != Abi::PlatformIntrinsic {
if let Abi::Rust | Abi::RustCall | Abi::RustIntrinsic | Abi::PlatformIntrinsic = abi {
// Don't worry about types in internal ABIs.
} else {
match it.node {
hir::ForeignItemKind::Fn(ref decl, _, _) => {
vis.check_foreign_fn(it.hir_id, decl);
Expand Down
12 changes: 12 additions & 0 deletions src/test/ui/issues/issue-64593.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// check-pass
#![deny(improper_ctypes)]

pub struct Error(std::num::NonZeroU32);

extern "Rust" {
fn foo(dest: &mut [u8]) -> Result<(), Error>;
}

fn main() {
let _ = unsafe { foo(&mut []) };
}

0 comments on commit 1486b7f

Please sign in to comment.