Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
lint: prohibit fields with opaque types
Opaque types cannot be used in extern declarations, and normally cannot exist in fields - except with type aliases to `impl Trait` and projections which normalize to them. Signed-off-by: David Wood <david@davidtw.co>
- Loading branch information
Showing
7 changed files
with
141 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#![feature(type_alias_impl_trait)] | ||
#![deny(improper_ctypes)] | ||
|
||
pub trait Baz { } | ||
|
||
impl Baz for () { } | ||
|
||
type Qux = impl Baz; | ||
|
||
fn assign() -> Qux {} | ||
|
||
pub trait Foo { | ||
type Assoc: 'static; | ||
} | ||
|
||
impl Foo for () { | ||
type Assoc = Qux; | ||
} | ||
|
||
#[repr(transparent)] | ||
pub struct A<T: Foo> { | ||
x: &'static <T as Foo>::Assoc, | ||
} | ||
|
||
extern "C" { | ||
pub fn lint_me() -> A<()>; //~ ERROR: uses type `impl Baz` | ||
} | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
error: `extern` block uses type `impl Baz`, which is not FFI-safe | ||
--> $DIR/lint-ctypes-73249-2.rs:26:25 | ||
| | ||
LL | pub fn lint_me() -> A<()>; | ||
| ^^^^^ not FFI-safe | ||
| | ||
note: the lint level is defined here | ||
--> $DIR/lint-ctypes-73249-2.rs:2:9 | ||
| | ||
LL | #![deny(improper_ctypes)] | ||
| ^^^^^^^^^^^^^^^ | ||
= note: opaque types have no C equivalent | ||
|
||
error: aborting due to previous error | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#![feature(type_alias_impl_trait)] | ||
#![deny(improper_ctypes)] | ||
|
||
pub trait Baz { } | ||
|
||
impl Baz for u32 { } | ||
|
||
type Qux = impl Baz; | ||
|
||
fn assign() -> Qux { 3 } | ||
|
||
#[repr(C)] | ||
pub struct A { | ||
x: Qux, | ||
} | ||
|
||
extern "C" { | ||
pub fn lint_me() -> A; //~ ERROR: uses type `impl Baz` | ||
} | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
error: `extern` block uses type `impl Baz`, which is not FFI-safe | ||
--> $DIR/lint-ctypes-73249-3.rs:18:25 | ||
| | ||
LL | pub fn lint_me() -> A; | ||
| ^ not FFI-safe | ||
| | ||
note: the lint level is defined here | ||
--> $DIR/lint-ctypes-73249-3.rs:2:9 | ||
| | ||
LL | #![deny(improper_ctypes)] | ||
| ^^^^^^^^^^^^^^^ | ||
= note: opaque types have no C equivalent | ||
|
||
error: aborting due to previous error | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#![feature(type_alias_impl_trait)] | ||
#![deny(improper_ctypes)] | ||
|
||
pub trait Baz { } | ||
|
||
impl Baz for u32 { } | ||
|
||
type Qux = impl Baz; | ||
|
||
fn assign() -> Qux { 3 } | ||
|
||
#[repr(transparent)] | ||
pub struct A { | ||
x: Qux, | ||
} | ||
|
||
extern "C" { | ||
pub fn lint_me() -> A; //~ ERROR: uses type `impl Baz` | ||
} | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
error: `extern` block uses type `impl Baz`, which is not FFI-safe | ||
--> $DIR/lint-ctypes-73249-5.rs:18:25 | ||
| | ||
LL | pub fn lint_me() -> A; | ||
| ^ not FFI-safe | ||
| | ||
note: the lint level is defined here | ||
--> $DIR/lint-ctypes-73249-5.rs:2:9 | ||
| | ||
LL | #![deny(improper_ctypes)] | ||
| ^^^^^^^^^^^^^^^ | ||
= note: opaque types have no C equivalent | ||
|
||
error: aborting due to previous error | ||
|