Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions compiler/rustc_lint/src/types/improper_ctypes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ declare_lint! {
/// to resolve it.
IMPROPER_CTYPES,
Warn,
"proper use of libc types in foreign modules"
"proper use of libc types in foreign modules",
report_in_external_macro
}

declare_lint! {
Expand All @@ -74,7 +75,8 @@ declare_lint! {
/// on how to resolve it.
IMPROPER_CTYPES_DEFINITIONS,
Warn,
"proper use of libc types in foreign item definitions"
"proper use of libc types in foreign item definitions",
report_in_external_macro
}

declare_lint! {
Expand Down
6 changes: 6 additions & 0 deletions tests/ui/lint/improper-ctypes/auxiliary/cross_crate_macro.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#[macro_export]
macro_rules! make_extern_fn {
() => {
extern "C" fn bad(p: ::std::string::String) {}
};
}
12 changes: 12 additions & 0 deletions tests/ui/lint/improper-ctypes/external-macro.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// issue-link: https://github.com/rust-lang/rust/issues/160862
// The improper_ctypes lint should fire even when the extern fn comes from a cross-crate macro.

//@ aux-build: cross_crate_macro.rs
//@ check-pass

extern crate cross_crate_macro;

cross_crate_macro::make_extern_fn!();
//~^ WARN `extern` fn uses type `String`, which is not FFI-safe

fn main() {}
13 changes: 13 additions & 0 deletions tests/ui/lint/improper-ctypes/external-macro.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
warning: `extern` fn uses type `String`, which is not FFI-safe
--> $DIR/external-macro.rs:9:1
|
LL | cross_crate_macro::make_extern_fn!();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe
|
= help: consider adding a `#[repr(C)]` or `#[repr(transparent)]` attribute to this struct
= note: this struct has unspecified layout
= note: `#[warn(improper_ctypes_definitions)]` on by default
= note: this warning originates in the macro `cross_crate_macro::make_extern_fn` (in Nightly builds, run with -Z macro-backtrace for more info)

warning: 1 warning emitted

Loading