Skip to content

Commit 13720e7

Browse files
committed
chore: make tidy happy
1 parent 853d70d commit 13720e7

File tree

4 files changed

+30
-34
lines changed

4 files changed

+30
-34
lines changed

compiler/rustc_lint/messages.ftl

+3-3
Original file line numberDiff line numberDiff line change
@@ -411,13 +411,13 @@ lint_improper_ctypes_ptr_validity_reason =
411411
lint_improper_ctypes_sized_ptr_to_unsafe_type =
412412
this reference (`{$ty}`) is ABI-compatible with a C pointer, but `{$inner_ty}` itself does not have a C layout
413413
414-
lint_improper_ctypes_struct_dueto = this struct/enum/union (`{$ty}`) is FFI-unsafe due to a `{$inner_ty}` field
415414
lint_improper_ctypes_slice_help = consider using a raw pointer to the slice's first element (and a length) instead
416-
417415
lint_improper_ctypes_slice_reason = slices have no C equivalent
418-
lint_improper_ctypes_str_help = consider using `*const u8` and a length instead
419416
417+
lint_improper_ctypes_str_help = consider using `*const u8` and a length instead
420418
lint_improper_ctypes_str_reason = string slices have no C equivalent
419+
420+
lint_improper_ctypes_struct_dueto = this struct/enum/union (`{$ty}`) is FFI-unsafe due to a `{$inner_ty}` field
421421
lint_improper_ctypes_struct_fieldless_help = consider adding a member to this struct
422422
423423
lint_improper_ctypes_struct_fieldless_reason = this struct has no fields

compiler/rustc_lint/src/types/improper_ctypes.rs

+7-13
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ impl CTypesVisitorState {
410410
fn value_may_be_unchecked(self) -> bool {
411411
// function declarations are assumed to be rust-caller, non-rust-callee
412412
// function definitions are assumed to be maybe-not-rust-caller, rust-callee
413-
// FnPtrs are... well, nothing's certain about anything. (TODO need more flags in enum?)
413+
// FnPtrs are... well, nothing's certain about anything. (FIXME need more flags in enum?)
414414
// Same with statics.
415415
if self.is_in_static() {
416416
true
@@ -771,7 +771,7 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
771771

772772
if def.variants().is_empty() {
773773
// Empty enums are implicitely handled as the never type:
774-
// TODO think about the FFI-safety of functions that use that
774+
// FIXME think about the FFI-safety of functions that use that
775775
return FfiSafe;
776776
}
777777
// Check for a repr() attribute to specify the size of the
@@ -821,7 +821,7 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
821821
.iter()
822822
.map(|variant| {
823823
self.visit_variant_fields(state, ty, def, variant, args)
824-
// TODO: check that enums allow any (up to all) variants to be phantoms?
824+
// FIXME: check that enums allow any (up to all) variants to be phantoms?
825825
// (previous code says no, but I don't know why? the problem with phantoms is that they're ZSTs, right?)
826826
.forbid_phantom()
827827
})
@@ -1117,10 +1117,7 @@ struct ImproperCTypesLint<'c, 'tcx> {
11171117
}
11181118

11191119
impl<'c, 'tcx> ImproperCTypesLint<'c, 'tcx> {
1120-
fn check_arg_for_power_alignment(
1121-
&mut self,
1122-
ty: Ty<'tcx>,
1123-
) -> bool {
1120+
fn check_arg_for_power_alignment(&mut self, ty: Ty<'tcx>) -> bool {
11241121
// Structs (under repr(C)) follow the power alignment rule if:
11251122
// - the first field of the struct is a floating-point type that
11261123
// is greater than 4-bytes, or
@@ -1150,10 +1147,7 @@ impl<'c, 'tcx> ImproperCTypesLint<'c, 'tcx> {
11501147
return false;
11511148
}
11521149

1153-
fn check_struct_for_power_alignment(
1154-
&mut self,
1155-
item: &'tcx hir::Item<'tcx>,
1156-
) {
1150+
fn check_struct_for_power_alignment(&mut self, item: &'tcx hir::Item<'tcx>) {
11571151
let tcx = self.cx.tcx;
11581152
let adt_def = tcx.adt_def(item.owner_id.to_def_id());
11591153
if adt_def.repr().c()
@@ -1237,7 +1231,7 @@ impl<'c, 'tcx> ImproperCTypesLint<'c, 'tcx> {
12371231
(span, ffi_res)
12381232
})
12391233
// even in function *definitions*, `FnPtr`s are always function declarations ...right?
1240-
// (TODO: we can't do that yet because one of rustc's crates can't compile if we do)
1234+
// (FIXME: we can't do that yet because one of rustc's crates can't compile if we do)
12411235
.for_each(|(span, ffi_res)| self.process_ffi_result(span, ffi_res, fn_mode));
12421236
//.drain();
12431237
}
@@ -1435,7 +1429,7 @@ impl<'tcx> LateLintPass<'tcx> for ImproperCTypesDefinitions {
14351429
// Structs are checked based on if they follow the power alignment
14361430
// rule (under repr(C)).
14371431
hir::ItemKind::Struct(..) => {
1438-
ImproperCTypesLint{cx}.check_struct_for_power_alignment(item);
1432+
ImproperCTypesLint { cx }.check_struct_for_power_alignment(item);
14391433
}
14401434
// See `check_field_def`..
14411435
hir::ItemKind::Union(..) | hir::ItemKind::Enum(..) => {}

tests/ui/lint/lint-ctypes.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,13 @@ extern "C" {
9494
pub fn transparent_str(p: TransparentStr); //~ ERROR: uses type `&str`
9595
pub fn transparent_fn(p: TransparentBoxFn);
9696
pub fn raw_array(arr: [u8; 8]); //~ ERROR: uses type `[u8; 8]`
97-
pub fn multi_errors_per_arg(f: for<'a> extern "C" fn(a:char, b:&dyn Debug, c: Box<TwoBadTypes<'a>>));
98-
//~^ ERROR: uses type `char`
99-
//~^^ ERROR: uses type `&dyn Debug`
97+
pub fn multi_errors_per_arg(
98+
f: for<'a> extern "C" fn(a:char, b:&dyn Debug, c: Box<TwoBadTypes<'a>>)
99+
);
100+
//~^^ ERROR: uses type `char`
101+
//~^^^ ERROR: uses type `&dyn Debug`
100102
// (possible FIXME: the in-struct `char` field doesn't get a warning due ^^)
101-
//~^^^^ ERROR: uses type `&[u8]`
103+
//~^^^^^ ERROR: uses type `&[u8]`
102104

103105
pub fn struct_unsized_ptr_no_metadata(p: &UnsizedStructBecauseForeign);
104106
pub fn struct_unsized_ptr_has_metadata(p: &UnsizedStructBecauseDyn); //~ ERROR uses type `&UnsizedStructBecauseDyn`

tests/ui/lint/lint-ctypes.stderr

+14-14
Original file line numberDiff line numberDiff line change
@@ -201,29 +201,29 @@ LL | pub fn raw_array(arr: [u8; 8]);
201201
= note: passing raw arrays by value is not FFI-safe
202202

203203
error: `extern` block uses type `char`, which is not FFI-safe
204-
--> $DIR/lint-ctypes.rs:97:36
204+
--> $DIR/lint-ctypes.rs:98:12
205205
|
206-
LL | pub fn multi_errors_per_arg(f: for<'a> extern "C" fn(a:char, b:&dyn Debug, c: Box<TwoBadTypes<'a>>));
207-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe
206+
LL | f: for<'a> extern "C" fn(a:char, b:&dyn Debug, c: Box<TwoBadTypes<'a>>)
207+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe
208208
|
209209
= note: the function pointer to `for<'a, 'b> extern "C" fn(char, &'a (dyn Debug + 'a), Box<TwoBadTypes<'b>>)` is FFI-unsafe due to `char`
210210
= help: consider using `u32` or `libc::wchar_t` instead
211211
= note: the `char` type has no C equivalent
212212

213213
error: `extern` block uses type `&dyn Debug`, which is not FFI-safe
214-
--> $DIR/lint-ctypes.rs:97:36
214+
--> $DIR/lint-ctypes.rs:98:12
215215
|
216-
LL | pub fn multi_errors_per_arg(f: for<'a> extern "C" fn(a:char, b:&dyn Debug, c: Box<TwoBadTypes<'a>>));
217-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe
216+
LL | f: for<'a> extern "C" fn(a:char, b:&dyn Debug, c: Box<TwoBadTypes<'a>>)
217+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe
218218
|
219219
= note: the function pointer to `for<'a, 'b> extern "C" fn(char, &'a (dyn Debug + 'a), Box<TwoBadTypes<'b>>)` is FFI-unsafe due to `&dyn Debug`
220220
= note: this reference to an unsized type contains metadata, which makes it incompatible with a C pointer
221221

222222
error: `extern` block uses type `&[u8]`, which is not FFI-safe
223-
--> $DIR/lint-ctypes.rs:97:36
223+
--> $DIR/lint-ctypes.rs:98:12
224224
|
225-
LL | pub fn multi_errors_per_arg(f: for<'a> extern "C" fn(a:char, b:&dyn Debug, c: Box<TwoBadTypes<'a>>));
226-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe
225+
LL | f: for<'a> extern "C" fn(a:char, b:&dyn Debug, c: Box<TwoBadTypes<'a>>)
226+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe
227227
|
228228
= note: the function pointer to `for<'a, 'b> extern "C" fn(char, &'a (dyn Debug + 'a), Box<TwoBadTypes<'b>>)` is FFI-unsafe due to `Box<TwoBadTypes<'_>>`
229229
= note: this reference (`Box<TwoBadTypes<'_>>`) is ABI-compatible with a C pointer, but `TwoBadTypes<'_>` itself does not have a C layout
@@ -237,15 +237,15 @@ LL | pub struct TwoBadTypes<'a> {
237237
= note: this reference to an unsized type contains metadata, which makes it incompatible with a C pointer
238238

239239
error: `extern` block uses type `&UnsizedStructBecauseDyn`, which is not FFI-safe
240-
--> $DIR/lint-ctypes.rs:104:47
240+
--> $DIR/lint-ctypes.rs:106:47
241241
|
242242
LL | pub fn struct_unsized_ptr_has_metadata(p: &UnsizedStructBecauseDyn);
243243
| ^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe
244244
|
245245
= note: this reference to an unsized type contains metadata, which makes it incompatible with a C pointer
246246

247247
error: `extern` block uses type `Option<UnsafeCell<extern "C" fn()>>`, which is not FFI-safe
248-
--> $DIR/lint-ctypes.rs:106:26
248+
--> $DIR/lint-ctypes.rs:108:26
249249
|
250250
LL | pub fn no_niche_a(a: Option<UnsafeCell<extern "C" fn()>>);
251251
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe
@@ -254,7 +254,7 @@ LL | pub fn no_niche_a(a: Option<UnsafeCell<extern "C" fn()>>);
254254
= note: enum has no representation hint
255255

256256
error: `extern` block uses type `Option<UnsafeCell<&i32>>`, which is not FFI-safe
257-
--> $DIR/lint-ctypes.rs:108:26
257+
--> $DIR/lint-ctypes.rs:110:26
258258
|
259259
LL | pub fn no_niche_b(b: Option<UnsafeCell<&i32>>);
260260
| ^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe
@@ -263,15 +263,15 @@ LL | pub fn no_niche_b(b: Option<UnsafeCell<&i32>>);
263263
= note: enum has no representation hint
264264

265265
error: `extern` block uses type `u128`, which is not FFI-safe
266-
--> $DIR/lint-ctypes.rs:111:34
266+
--> $DIR/lint-ctypes.rs:113:34
267267
|
268268
LL | pub static static_u128_type: u128;
269269
| ^^^^ not FFI-safe
270270
|
271271
= note: 128-bit integers don't currently have a known stable ABI
272272

273273
error: `extern` block uses type `u128`, which is not FFI-safe
274-
--> $DIR/lint-ctypes.rs:112:40
274+
--> $DIR/lint-ctypes.rs:114:40
275275
|
276276
LL | pub static static_u128_array_type: [u128; 16];
277277
| ^^^^^^^^^^ not FFI-safe

0 commit comments

Comments
 (0)