Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update improper_ctypes warning to add info about extern "Rust" #75030

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/librustc_lint/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -989,6 +989,9 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
diag.help(help);
}
diag.note(note);
diag.note(
r#"if intentionally using the unstable Rust ABI, specify it with `extern "Rust"`"#,
);
if let ty::Adt(def, _) = ty.kind {
if let Some(sp) = self.cx.tcx.hir().span_if_local(def.did) {
diag.span_note(sp, "the type is defined here");
Expand Down
5 changes: 5 additions & 0 deletions src/test/ui/issues/issue-14309.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ LL | #![deny(improper_ctypes)]
| ^^^^^^^^^^^^^^^
= help: consider adding a `#[repr(C)]` or `#[repr(transparent)]` attribute to this struct
= note: this struct has unspecified layout
= note: if intentionally using the unstable Rust ABI, specify it with `extern "Rust"`
note: the type is defined here
--> $DIR/issue-14309.rs:4:1
|
Expand All @@ -27,6 +28,7 @@ LL | fn bar(x: B);
|
= help: consider adding a `#[repr(C)]` or `#[repr(transparent)]` attribute to this struct
= note: this struct has unspecified layout
= note: if intentionally using the unstable Rust ABI, specify it with `extern "Rust"`
note: the type is defined here
--> $DIR/issue-14309.rs:4:1
|
Expand All @@ -43,6 +45,7 @@ LL | fn qux(x: A2);
|
= help: consider adding a `#[repr(C)]` or `#[repr(transparent)]` attribute to this struct
= note: this struct has unspecified layout
= note: if intentionally using the unstable Rust ABI, specify it with `extern "Rust"`
note: the type is defined here
--> $DIR/issue-14309.rs:4:1
|
Expand All @@ -59,6 +62,7 @@ LL | fn quux(x: B2);
|
= help: consider adding a `#[repr(C)]` or `#[repr(transparent)]` attribute to this struct
= note: this struct has unspecified layout
= note: if intentionally using the unstable Rust ABI, specify it with `extern "Rust"`
note: the type is defined here
--> $DIR/issue-14309.rs:4:1
|
Expand All @@ -75,6 +79,7 @@ LL | fn fred(x: D);
|
= help: consider adding a `#[repr(C)]` or `#[repr(transparent)]` attribute to this struct
= note: this struct has unspecified layout
= note: if intentionally using the unstable Rust ABI, specify it with `extern "Rust"`
note: the type is defined here
--> $DIR/issue-14309.rs:4:1
|
Expand Down
1 change: 1 addition & 0 deletions src/test/ui/issues/issue-16250.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ LL | #![deny(warnings)]
= note: `#[deny(improper_ctypes)]` implied by `#[deny(warnings)]`
= help: consider adding a `#[repr(C)]` or `#[repr(transparent)]` attribute to this struct
= note: this struct has unspecified layout
= note: if intentionally using the unstable Rust ABI, specify it with `extern "Rust"`
note: the type is defined here
--> $DIR/issue-16250.rs:3:1
|
Expand Down
1 change: 1 addition & 0 deletions src/test/ui/lint/lint-ctypes-73249-2.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ note: the lint level is defined here
LL | #![deny(improper_ctypes)]
| ^^^^^^^^^^^^^^^
= note: opaque types have no C equivalent
= note: if intentionally using the unstable Rust ABI, specify it with `extern "Rust"`

error: aborting due to previous error

1 change: 1 addition & 0 deletions src/test/ui/lint/lint-ctypes-73249-3.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ note: the lint level is defined here
LL | #![deny(improper_ctypes)]
| ^^^^^^^^^^^^^^^
= note: opaque types have no C equivalent
= note: if intentionally using the unstable Rust ABI, specify it with `extern "Rust"`

error: aborting due to previous error

1 change: 1 addition & 0 deletions src/test/ui/lint/lint-ctypes-73249-5.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ note: the lint level is defined here
LL | #![deny(improper_ctypes)]
| ^^^^^^^^^^^^^^^
= note: opaque types have no C equivalent
= note: if intentionally using the unstable Rust ABI, specify it with `extern "Rust"`

error: aborting due to previous error

1 change: 1 addition & 0 deletions src/test/ui/lint/lint-ctypes-73251-1.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ note: the lint level is defined here
LL | #![deny(improper_ctypes)]
| ^^^^^^^^^^^^^^^
= note: opaque types have no C equivalent
= note: if intentionally using the unstable Rust ABI, specify it with `extern "Rust"`

error: aborting due to previous error

1 change: 1 addition & 0 deletions src/test/ui/lint/lint-ctypes-73251-2.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ note: the lint level is defined here
LL | #![deny(improper_ctypes)]
| ^^^^^^^^^^^^^^^
= note: opaque types have no C equivalent
= note: if intentionally using the unstable Rust ABI, specify it with `extern "Rust"`

error: aborting due to previous error

9 changes: 9 additions & 0 deletions src/test/ui/lint/lint-ctypes-enum.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ LL | #![deny(improper_ctypes)]
| ^^^^^^^^^^^^^^^
= help: consider adding a `#[repr(C)]`, `#[repr(transparent)]`, or integer `#[repr(...)]` attribute to this enum
= note: enum has no representation hint
= note: if intentionally using the unstable Rust ABI, specify it with `extern "Rust"`
note: the type is defined here
--> $DIR/lint-ctypes-enum.rs:9:1
|
Expand All @@ -25,6 +26,7 @@ LL | fn bf(x: B);
|
= help: consider adding a `#[repr(C)]`, `#[repr(transparent)]`, or integer `#[repr(...)]` attribute to this enum
= note: enum has no representation hint
= note: if intentionally using the unstable Rust ABI, specify it with `extern "Rust"`
note: the type is defined here
--> $DIR/lint-ctypes-enum.rs:10:1
|
Expand All @@ -39,6 +41,7 @@ LL | fn tf(x: T);
|
= help: consider adding a `#[repr(C)]`, `#[repr(transparent)]`, or integer `#[repr(...)]` attribute to this enum
= note: enum has no representation hint
= note: if intentionally using the unstable Rust ABI, specify it with `extern "Rust"`
note: the type is defined here
--> $DIR/lint-ctypes-enum.rs:11:1
|
Expand All @@ -53,6 +56,7 @@ LL | fn unique(x: Option<std::ptr::Unique<u8>>);
|
= help: consider adding a `#[repr(C)]`, `#[repr(transparent)]`, or integer `#[repr(...)]` attribute to this enum
= note: enum has no representation hint
= note: if intentionally using the unstable Rust ABI, specify it with `extern "Rust"`

error: `extern` block uses type `u128`, which is not FFI-safe
--> $DIR/lint-ctypes-enum.rs:54:23
Expand All @@ -61,6 +65,7 @@ LL | fn nonzero_u128(x: Option<num::NonZeroU128>);
| ^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe
|
= note: 128-bit integers don't currently have a known stable ABI
= note: if intentionally using the unstable Rust ABI, specify it with `extern "Rust"`

error: `extern` block uses type `i128`, which is not FFI-safe
--> $DIR/lint-ctypes-enum.rs:61:23
Expand All @@ -69,6 +74,7 @@ LL | fn nonzero_i128(x: Option<num::NonZeroI128>);
| ^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe
|
= note: 128-bit integers don't currently have a known stable ABI
= note: if intentionally using the unstable Rust ABI, specify it with `extern "Rust"`

error: `extern` block uses type `std::option::Option<TransparentUnion<std::num::NonZeroU8>>`, which is not FFI-safe
--> $DIR/lint-ctypes-enum.rs:66:28
Expand All @@ -78,6 +84,7 @@ LL | fn transparent_union(x: Option<TransparentUnion<num::NonZeroU8>>);
|
= help: consider adding a `#[repr(C)]`, `#[repr(transparent)]`, or integer `#[repr(...)]` attribute to this enum
= note: enum has no representation hint
= note: if intentionally using the unstable Rust ABI, specify it with `extern "Rust"`

error: `extern` block uses type `std::option::Option<Rust<std::num::NonZeroU8>>`, which is not FFI-safe
--> $DIR/lint-ctypes-enum.rs:68:20
Expand All @@ -87,6 +94,7 @@ LL | fn repr_rust(x: Option<Rust<num::NonZeroU8>>);
|
= help: consider adding a `#[repr(C)]`, `#[repr(transparent)]`, or integer `#[repr(...)]` attribute to this enum
= note: enum has no representation hint
= note: if intentionally using the unstable Rust ABI, specify it with `extern "Rust"`

error: `extern` block uses type `std::result::Result<(), std::num::NonZeroI32>`, which is not FFI-safe
--> $DIR/lint-ctypes-enum.rs:69:20
Expand All @@ -96,6 +104,7 @@ LL | fn no_result(x: Result<(), num::NonZeroI32>);
|
= help: consider adding a `#[repr(C)]`, `#[repr(transparent)]`, or integer `#[repr(...)]` attribute to this enum
= note: enum has no representation hint
= note: if intentionally using the unstable Rust ABI, specify it with `extern "Rust"`

error: aborting due to 9 previous errors

17 changes: 17 additions & 0 deletions src/test/ui/lint/lint-ctypes-fn.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ LL | #![deny(improper_ctypes_definitions)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
= help: consider using a raw pointer instead
= note: slices have no C equivalent
= note: if intentionally using the unstable Rust ABI, specify it with `extern "Rust"`

error: `extern` fn uses type `str`, which is not FFI-safe
--> $DIR/lint-ctypes-fn.rs:70:31
Expand All @@ -20,6 +21,7 @@ LL | pub extern "C" fn str_type(p: &str) { }
|
= help: consider using `*const u8` and a length instead
= note: string slices have no C equivalent
= note: if intentionally using the unstable Rust ABI, specify it with `extern "Rust"`

error: `extern` fn uses type `char`, which is not FFI-safe
--> $DIR/lint-ctypes-fn.rs:77:32
Expand All @@ -29,6 +31,7 @@ LL | pub extern "C" fn char_type(p: char) { }
|
= help: consider using `u32` or `libc::wchar_t` instead
= note: the `char` type has no C equivalent
= note: if intentionally using the unstable Rust ABI, specify it with `extern "Rust"`

error: `extern` fn uses type `i128`, which is not FFI-safe
--> $DIR/lint-ctypes-fn.rs:80:32
Expand All @@ -37,6 +40,7 @@ LL | pub extern "C" fn i128_type(p: i128) { }
| ^^^^ not FFI-safe
|
= note: 128-bit integers don't currently have a known stable ABI
= note: if intentionally using the unstable Rust ABI, specify it with `extern "Rust"`

error: `extern` fn uses type `u128`, which is not FFI-safe
--> $DIR/lint-ctypes-fn.rs:83:32
Expand All @@ -45,6 +49,7 @@ LL | pub extern "C" fn u128_type(p: u128) { }
| ^^^^ not FFI-safe
|
= note: 128-bit integers don't currently have a known stable ABI
= note: if intentionally using the unstable Rust ABI, specify it with `extern "Rust"`

error: `extern` fn uses type `(i32, i32)`, which is not FFI-safe
--> $DIR/lint-ctypes-fn.rs:86:33
Expand All @@ -54,6 +59,7 @@ LL | pub extern "C" fn tuple_type(p: (i32, i32)) { }
|
= help: consider using a struct instead
= note: tuples have unspecified layout
= note: if intentionally using the unstable Rust ABI, specify it with `extern "Rust"`

error: `extern` fn uses type `(i32, i32)`, which is not FFI-safe
--> $DIR/lint-ctypes-fn.rs:89:34
Expand All @@ -63,6 +69,7 @@ LL | pub extern "C" fn tuple_type2(p: I32Pair) { }
|
= help: consider using a struct instead
= note: tuples have unspecified layout
= note: if intentionally using the unstable Rust ABI, specify it with `extern "Rust"`

error: `extern` fn uses type `ZeroSize`, which is not FFI-safe
--> $DIR/lint-ctypes-fn.rs:92:32
Expand All @@ -72,6 +79,7 @@ LL | pub extern "C" fn zero_size(p: ZeroSize) { }
|
= help: consider adding a member to this struct
= note: this struct has no fields
= note: if intentionally using the unstable Rust ABI, specify it with `extern "Rust"`
note: the type is defined here
--> $DIR/lint-ctypes-fn.rs:26:1
|
Expand All @@ -85,6 +93,7 @@ LL | pub extern "C" fn zero_size_phantom(p: ZeroSizeWithPhantomData) { }
| ^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe
|
= note: composed only of `PhantomData`
= note: if intentionally using the unstable Rust ABI, specify it with `extern "Rust"`
note: the type is defined here
--> $DIR/lint-ctypes-fn.rs:61:1
|
Expand All @@ -98,6 +107,7 @@ LL | pub extern "C" fn zero_size_phantom_toplevel() -> PhantomData<bool> {
| ^^^^^^^^^^^^^^^^^ not FFI-safe
|
= note: composed only of `PhantomData`
= note: if intentionally using the unstable Rust ABI, specify it with `extern "Rust"`

error: `extern` fn uses type `fn()`, which is not FFI-safe
--> $DIR/lint-ctypes-fn.rs:103:30
Expand All @@ -107,6 +117,7 @@ LL | pub extern "C" fn fn_type(p: RustFn) { }
|
= help: consider using an `extern fn(...) -> ...` function pointer instead
= note: this function pointer has Rust-specific calling convention
= note: if intentionally using the unstable Rust ABI, specify it with `extern "Rust"`

error: `extern` fn uses type `fn()`, which is not FFI-safe
--> $DIR/lint-ctypes-fn.rs:106:31
Expand All @@ -116,6 +127,7 @@ LL | pub extern "C" fn fn_type2(p: fn()) { }
|
= help: consider using an `extern fn(...) -> ...` function pointer instead
= note: this function pointer has Rust-specific calling convention
= note: if intentionally using the unstable Rust ABI, specify it with `extern "Rust"`

error: `extern` fn uses type `i128`, which is not FFI-safe
--> $DIR/lint-ctypes-fn.rs:111:39
Expand All @@ -124,6 +136,7 @@ LL | pub extern "C" fn transparent_i128(p: TransparentI128) { }
| ^^^^^^^^^^^^^^^ not FFI-safe
|
= note: 128-bit integers don't currently have a known stable ABI
= note: if intentionally using the unstable Rust ABI, specify it with `extern "Rust"`

error: `extern` fn uses type `str`, which is not FFI-safe
--> $DIR/lint-ctypes-fn.rs:114:38
Expand All @@ -133,6 +146,7 @@ LL | pub extern "C" fn transparent_str(p: TransparentStr) { }
|
= help: consider using `*const u8` and a length instead
= note: string slices have no C equivalent
= note: if intentionally using the unstable Rust ABI, specify it with `extern "Rust"`

error: `extern` fn uses type `std::marker::PhantomData<bool>`, which is not FFI-safe
--> $DIR/lint-ctypes-fn.rs:160:43
Expand All @@ -141,6 +155,7 @@ LL | pub extern "C" fn unused_generic2<T>() -> PhantomData<bool> {
| ^^^^^^^^^^^^^^^^^ not FFI-safe
|
= note: composed only of `PhantomData`
= note: if intentionally using the unstable Rust ABI, specify it with `extern "Rust"`

error: `extern` fn uses type `std::vec::Vec<T>`, which is not FFI-safe
--> $DIR/lint-ctypes-fn.rs:173:39
Expand All @@ -150,6 +165,7 @@ LL | pub extern "C" fn used_generic4<T>(x: Vec<T>) { }
|
= help: consider adding a `#[repr(C)]` or `#[repr(transparent)]` attribute to this struct
= note: this struct has unspecified layout
= note: if intentionally using the unstable Rust ABI, specify it with `extern "Rust"`

error: `extern` fn uses type `std::vec::Vec<T>`, which is not FFI-safe
--> $DIR/lint-ctypes-fn.rs:176:41
Expand All @@ -159,6 +175,7 @@ LL | pub extern "C" fn used_generic5<T>() -> Vec<T> {
|
= help: consider adding a `#[repr(C)]` or `#[repr(transparent)]` attribute to this struct
= note: this struct has unspecified layout
= note: if intentionally using the unstable Rust ABI, specify it with `extern "Rust"`

error: aborting due to 17 previous errors

Loading