Update tests for extern block linting
This commit is contained in:
parent
c4a8d7f86a
commit
8a3edb1d66
285 changed files with 1010 additions and 947 deletions
|
@ -3,13 +3,13 @@ You cannot use type or const parameters on foreign items.
|
|||
Example of erroneous code:
|
||||
|
||||
```compile_fail,E0044
|
||||
extern { fn some_func<T>(x: T); }
|
||||
extern "C" { fn some_func<T>(x: T); }
|
||||
```
|
||||
|
||||
To fix this, replace the generic parameter with the specializations that you
|
||||
need:
|
||||
|
||||
```
|
||||
extern { fn some_func_i32(x: i32); }
|
||||
extern { fn some_func_i64(x: i64); }
|
||||
extern "C" { fn some_func_i32(x: i32); }
|
||||
extern "C" { fn some_func_i64(x: i64); }
|
||||
```
|
||||
|
|
|
@ -3,7 +3,7 @@ A pattern was declared as an argument in a foreign function declaration.
|
|||
Erroneous code example:
|
||||
|
||||
```compile_fail,E0130
|
||||
extern {
|
||||
extern "C" {
|
||||
fn foo((a, b): (u32, u32)); // error: patterns aren't allowed in foreign
|
||||
// function declarations
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ struct SomeStruct {
|
|||
b: u32,
|
||||
}
|
||||
|
||||
extern {
|
||||
extern "C" {
|
||||
fn foo(s: SomeStruct); // ok!
|
||||
}
|
||||
```
|
||||
|
@ -25,7 +25,7 @@ extern {
|
|||
Or:
|
||||
|
||||
```
|
||||
extern {
|
||||
extern "C" {
|
||||
fn foo(a: (u32, u32)); // ok!
|
||||
}
|
||||
```
|
||||
|
|
|
@ -3,7 +3,7 @@ A link name was given with an empty name.
|
|||
Erroneous code example:
|
||||
|
||||
```compile_fail,E0454
|
||||
#[link(name = "")] extern {}
|
||||
#[link(name = "")] extern "C" {}
|
||||
// error: `#[link(name = "")]` given with empty name
|
||||
```
|
||||
|
||||
|
@ -11,5 +11,5 @@ The rust compiler cannot link to an external library if you don't give it its
|
|||
name. Example:
|
||||
|
||||
```no_run
|
||||
#[link(name = "some_lib")] extern {} // ok!
|
||||
#[link(name = "some_lib")] extern "C" {} // ok!
|
||||
```
|
||||
|
|
|
@ -4,7 +4,7 @@ as frameworks are specific to that operating system.
|
|||
Erroneous code example:
|
||||
|
||||
```ignore (should-compile_fail-but-cannot-doctest-conditionally-without-macos)
|
||||
#[link(name = "FooCoreServices", kind = "framework")] extern {}
|
||||
#[link(name = "FooCoreServices", kind = "framework")] extern "C" {}
|
||||
// OS used to compile is Linux for example
|
||||
```
|
||||
|
||||
|
@ -12,7 +12,7 @@ To solve this error you can use conditional compilation:
|
|||
|
||||
```
|
||||
#[cfg_attr(target="macos", link(name = "FooCoreServices", kind = "framework"))]
|
||||
extern {}
|
||||
extern "C" {}
|
||||
```
|
||||
|
||||
Learn more in the [Conditional Compilation][conditional-compilation] section
|
||||
|
|
|
@ -3,7 +3,7 @@ An unknown "kind" was specified for a link attribute.
|
|||
Erroneous code example:
|
||||
|
||||
```compile_fail,E0458
|
||||
#[link(kind = "wonderful_unicorn")] extern {}
|
||||
#[link(kind = "wonderful_unicorn")] extern "C" {}
|
||||
// error: unknown kind: `wonderful_unicorn`
|
||||
```
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@ A link was used without a name parameter.
|
|||
Erroneous code example:
|
||||
|
||||
```compile_fail,E0459
|
||||
#[link(kind = "dylib")] extern {}
|
||||
#[link(kind = "dylib")] extern "C" {}
|
||||
// error: `#[link(...)]` specified without `name = "foo"`
|
||||
```
|
||||
|
||||
|
@ -11,5 +11,5 @@ Please add the name parameter to allow the rust compiler to find the library
|
|||
you want. Example:
|
||||
|
||||
```no_run
|
||||
#[link(kind = "dylib", name = "some_lib")] extern {} // ok!
|
||||
#[link(kind = "dylib", name = "some_lib")] extern "C" {} // ok!
|
||||
```
|
||||
|
|
|
@ -3,7 +3,7 @@ Attempted to pass an invalid type of variable into a variadic function.
|
|||
Erroneous code example:
|
||||
|
||||
```compile_fail,E0617
|
||||
extern {
|
||||
extern "C" {
|
||||
fn printf(c: *const i8, ...);
|
||||
}
|
||||
|
||||
|
@ -21,7 +21,7 @@ to import from `std::os::raw`).
|
|||
In this case, `c_double` has the same size as `f64` so we can use it directly:
|
||||
|
||||
```no_run
|
||||
# extern {
|
||||
# extern "C" {
|
||||
# fn printf(c: *const i8, ...);
|
||||
# }
|
||||
unsafe {
|
||||
|
|
|
@ -18,7 +18,7 @@ the function inside of an `extern` block.
|
|||
```
|
||||
#![feature(ffi_returns_twice)]
|
||||
|
||||
extern {
|
||||
extern "C" {
|
||||
#[ffi_returns_twice] // ok!
|
||||
pub fn foo();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue