Skip to content

Commit 765e959

Browse files
committed
Auto merge of rust-lang#76219 - Mark-Simulacrum:extern-require-abi, r=estebank
Add allow-by-default lint on implicit ABI in extern function pointers and items This adds a new lint, missing_abi, which lints on omitted ABIs on extern blocks, function declarations, and function pointers. It is currently not emitting the best possible diagnostics -- we need to track the span of "extern" at least or do some heuristic searching based on the available spans -- but seems good enough for an initial pass than can be expanded in future PRs. This is a pretty large PR, but mostly due to updating a large number of tests to include ABIs; I can split that into a separate PR if it would be helpful, but test updates are already in dedicated commits.
2 parents 2d7006e + 0c32ba1 commit 765e959

File tree

4 files changed

+11
-11
lines changed

4 files changed

+11
-11
lines changed

core/src/sync/atomic.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -809,7 +809,7 @@ impl AtomicBool {
809809
/// ```ignore (extern-declaration)
810810
/// # fn main() {
811811
/// use std::sync::atomic::AtomicBool;
812-
/// extern {
812+
/// extern "C" {
813813
/// fn my_atomic_op(arg: *mut bool);
814814
/// }
815815
///
@@ -2068,7 +2068,7 @@ macro_rules! atomic_int {
20682068
/// # fn main() {
20692069
#[doc = concat!($extra_feature, "use std::sync::atomic::", stringify!($atomic_type), ";")]
20702070
///
2071-
/// extern {
2071+
/// extern "C" {
20722072
#[doc = concat!(" fn my_atomic_op(arg: *mut ", stringify!($int_type), ");")]
20732073
/// }
20742074
///

std/src/ffi/c_str.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ use crate::sys;
8686
/// use std::ffi::CString;
8787
/// use std::os::raw::c_char;
8888
///
89-
/// extern {
89+
/// extern "C" {
9090
/// fn my_printer(s: *const c_char);
9191
/// }
9292
///
@@ -144,7 +144,7 @@ pub struct CString {
144144
/// use std::ffi::CStr;
145145
/// use std::os::raw::c_char;
146146
///
147-
/// extern { fn my_string() -> *const c_char; }
147+
/// extern "C" { fn my_string() -> *const c_char; }
148148
///
149149
/// unsafe {
150150
/// let slice = CStr::from_ptr(my_string());
@@ -159,7 +159,7 @@ pub struct CString {
159159
/// use std::os::raw::c_char;
160160
///
161161
/// fn work(data: &CStr) {
162-
/// extern { fn work_with(data: *const c_char); }
162+
/// extern "C" { fn work_with(data: *const c_char); }
163163
///
164164
/// unsafe { work_with(data.as_ptr()) }
165165
/// }
@@ -174,7 +174,7 @@ pub struct CString {
174174
/// use std::ffi::CStr;
175175
/// use std::os::raw::c_char;
176176
///
177-
/// extern { fn my_string() -> *const c_char; }
177+
/// extern "C" { fn my_string() -> *const c_char; }
178178
///
179179
/// fn my_string_safe() -> String {
180180
/// unsafe {
@@ -359,7 +359,7 @@ impl CString {
359359
/// use std::ffi::CString;
360360
/// use std::os::raw::c_char;
361361
///
362-
/// extern { fn puts(s: *const c_char); }
362+
/// extern "C" { fn puts(s: *const c_char); }
363363
///
364364
/// let to_print = CString::new("Hello!").expect("CString::new failed");
365365
/// unsafe {
@@ -465,7 +465,7 @@ impl CString {
465465
/// use std::ffi::CString;
466466
/// use std::os::raw::c_char;
467467
///
468-
/// extern {
468+
/// extern "C" {
469469
/// fn some_extern_function(s: *mut c_char);
470470
/// }
471471
///
@@ -1147,7 +1147,7 @@ impl CStr {
11471147
/// use std::ffi::CStr;
11481148
/// use std::os::raw::c_char;
11491149
///
1150-
/// extern {
1150+
/// extern "C" {
11511151
/// fn my_string() -> *const c_char;
11521152
/// }
11531153
///

std/src/keyword_docs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ mod enum_keyword {}
401401
///
402402
/// ```rust
403403
/// #[no_mangle]
404-
/// pub extern fn callable_from_c(x: i32) -> bool {
404+
/// pub extern "C" fn callable_from_c(x: i32) -> bool {
405405
/// x % 3 == 0
406406
/// }
407407
/// ```

std/src/sys/unix/weak.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use crate::sync::atomic::{self, AtomicUsize, Ordering};
2828

2929
macro_rules! weak {
3030
(fn $name:ident($($t:ty),*) -> $ret:ty) => (
31-
static $name: crate::sys::weak::Weak<unsafe extern fn($($t),*) -> $ret> =
31+
static $name: crate::sys::weak::Weak<unsafe extern "C" fn($($t),*) -> $ret> =
3232
crate::sys::weak::Weak::new(concat!(stringify!($name), '\0'));
3333
)
3434
}

0 commit comments

Comments
 (0)