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

Lines changed: 3 additions & 3 deletions
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

Lines changed: 3 additions & 3 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

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

0 commit comments

Comments
 (0)