Skip to content

Commit 8a3edb1

Browse files
Update tests for extern block linting
1 parent c4a8d7f commit 8a3edb1

File tree

285 files changed

+1008
-945
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

285 files changed

+1008
-945
lines changed

compiler/rustc_error_codes/src/error_codes/E0044.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ You cannot use type or const parameters on foreign items.
33
Example of erroneous code:
44

55
```compile_fail,E0044
6-
extern { fn some_func<T>(x: T); }
6+
extern "C" { fn some_func<T>(x: T); }
77
```
88

99
To fix this, replace the generic parameter with the specializations that you
1010
need:
1111

1212
```
13-
extern { fn some_func_i32(x: i32); }
14-
extern { fn some_func_i64(x: i64); }
13+
extern "C" { fn some_func_i32(x: i32); }
14+
extern "C" { fn some_func_i64(x: i64); }
1515
```

compiler/rustc_error_codes/src/error_codes/E0130.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ A pattern was declared as an argument in a foreign function declaration.
33
Erroneous code example:
44

55
```compile_fail,E0130
6-
extern {
6+
extern "C" {
77
fn foo((a, b): (u32, u32)); // error: patterns aren't allowed in foreign
88
// function declarations
99
}
@@ -17,15 +17,15 @@ struct SomeStruct {
1717
b: u32,
1818
}
1919
20-
extern {
20+
extern "C" {
2121
fn foo(s: SomeStruct); // ok!
2222
}
2323
```
2424

2525
Or:
2626

2727
```
28-
extern {
28+
extern "C" {
2929
fn foo(a: (u32, u32)); // ok!
3030
}
3131
```

compiler/rustc_error_codes/src/error_codes/E0454.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ A link name was given with an empty name.
33
Erroneous code example:
44

55
```compile_fail,E0454
6-
#[link(name = "")] extern {}
6+
#[link(name = "")] extern "C" {}
77
// error: `#[link(name = "")]` given with empty name
88
```
99

1010
The rust compiler cannot link to an external library if you don't give it its
1111
name. Example:
1212

1313
```no_run
14-
#[link(name = "some_lib")] extern {} // ok!
14+
#[link(name = "some_lib")] extern "C" {} // ok!
1515
```

compiler/rustc_error_codes/src/error_codes/E0455.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ as frameworks are specific to that operating system.
44
Erroneous code example:
55

66
```ignore (should-compile_fail-but-cannot-doctest-conditionally-without-macos)
7-
#[link(name = "FooCoreServices", kind = "framework")] extern {}
7+
#[link(name = "FooCoreServices", kind = "framework")] extern "C" {}
88
// OS used to compile is Linux for example
99
```
1010

1111
To solve this error you can use conditional compilation:
1212

1313
```
1414
#[cfg_attr(target="macos", link(name = "FooCoreServices", kind = "framework"))]
15-
extern {}
15+
extern "C" {}
1616
```
1717

1818
Learn more in the [Conditional Compilation][conditional-compilation] section

compiler/rustc_error_codes/src/error_codes/E0458.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ An unknown "kind" was specified for a link attribute.
33
Erroneous code example:
44

55
```compile_fail,E0458
6-
#[link(kind = "wonderful_unicorn")] extern {}
6+
#[link(kind = "wonderful_unicorn")] extern "C" {}
77
// error: unknown kind: `wonderful_unicorn`
88
```
99

compiler/rustc_error_codes/src/error_codes/E0459.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ A link was used without a name parameter.
33
Erroneous code example:
44

55
```compile_fail,E0459
6-
#[link(kind = "dylib")] extern {}
6+
#[link(kind = "dylib")] extern "C" {}
77
// error: `#[link(...)]` specified without `name = "foo"`
88
```
99

1010
Please add the name parameter to allow the rust compiler to find the library
1111
you want. Example:
1212

1313
```no_run
14-
#[link(kind = "dylib", name = "some_lib")] extern {} // ok!
14+
#[link(kind = "dylib", name = "some_lib")] extern "C" {} // ok!
1515
```

compiler/rustc_error_codes/src/error_codes/E0617.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Attempted to pass an invalid type of variable into a variadic function.
33
Erroneous code example:
44

55
```compile_fail,E0617
6-
extern {
6+
extern "C" {
77
fn printf(c: *const i8, ...);
88
}
99
@@ -21,7 +21,7 @@ to import from `std::os::raw`).
2121
In this case, `c_double` has the same size as `f64` so we can use it directly:
2222

2323
```no_run
24-
# extern {
24+
# extern "C" {
2525
# fn printf(c: *const i8, ...);
2626
# }
2727
unsafe {

compiler/rustc_error_codes/src/error_codes/E0724.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ the function inside of an `extern` block.
1818
```
1919
#![feature(ffi_returns_twice)]
2020
21-
extern {
21+
extern "C" {
2222
#[ffi_returns_twice] // ok!
2323
pub fn foo();
2424
}

compiler/rustc_llvm/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ pub fn initialize_available_targets() {
3838
($cfg:meta, $($method:ident),*) => { {
3939
#[cfg($cfg)]
4040
fn init() {
41-
extern {
41+
extern "C" {
4242
$(fn $method();)*
4343
}
4444
unsafe {

library/core/src/sync/atomic.rs

+2-2
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
///

library/std/src/ffi/c_str.rs

+7-7
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
///

src/doc/unstable-book/src/language-features/link-args.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ usage would be:
1515
#![feature(link_args)]
1616
1717
#[link_args = "-foo -bar -baz"]
18-
extern {}
18+
extern "C" {}
1919
# fn main() {}
2020
```
2121

src/test/codegen/call-llvm-intrinsics.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ impl Drop for A {
1313
}
1414
}
1515

16-
extern {
16+
extern "C" {
1717
#[link_name = "llvm.sqrt.f32"]
1818
fn sqrt(x: f32) -> f32;
1919
}

src/test/codegen/dealloc-no-unwind.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ struct A;
88

99
impl Drop for A {
1010
fn drop(&mut self) {
11-
extern { fn foo(); }
11+
extern "C" { fn foo(); }
1212
unsafe { foo(); }
1313
}
1414
}

src/test/codegen/debug-column.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ fn main() {
1818
}
1919
}
2020

21-
extern {
21+
extern "C" {
2222
fn giraffe();
2323
fn turtle();
2424
}

src/test/codegen/ffi-const.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
pub fn bar() { unsafe { foo() } }
66

7-
extern {
7+
extern "C" {
88
// CHECK-LABEL: declare void @foo()
99
// CHECK-SAME: [[ATTRS:#[0-9]+]]
1010
// CHECK-DAG: attributes [[ATTRS]] = { {{.*}}readnone{{.*}} }

src/test/codegen/ffi-out-of-bounds-loads.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ struct S {
1111
f3: i32,
1212
}
1313

14-
extern {
14+
extern "C" {
1515
fn foo(s: S);
1616
}
1717

src/test/codegen/ffi-pure.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
pub fn bar() { unsafe { foo() } }
66

7-
extern {
7+
extern "C" {
88
// CHECK-LABEL: declare void @foo()
99
// CHECK-SAME: [[ATTRS:#[0-9]+]]
1010
// CHECK-DAG: attributes [[ATTRS]] = { {{.*}}readonly{{.*}} }

src/test/codegen/ffi-returns-twice.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
pub fn bar() { unsafe { foo() } }
66

7-
extern {
7+
extern "C" {
88
// CHECK-LABEL: declare void @foo()
99
// CHECK-SAME: [[ATTRS:#[0-9]+]]
1010
// CHECK-DAG: attributes [[ATTRS]] = { {{.*}}returns_twice{{.*}} }

src/test/codegen/riscv-abi/call-llvm-intrinsics.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ impl Drop for A {
1313
}
1414
}
1515

16-
extern {
16+
extern "C" {
1717
#[link_name = "llvm.sqrt.f32"]
1818
fn sqrt(x: f32) -> f32;
1919
}

src/test/codegen/unwind-extern-imports.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#![crate_type = "lib"]
55
#![feature(unwind_attributes)]
66

7-
extern {
7+
extern "C" {
88
// CHECK: Function Attrs:{{.*}}nounwind
99
// CHECK-NEXT: declare void @extern_fn
1010
fn extern_fn();

0 commit comments

Comments
 (0)