Skip to content

Commit a224f38

Browse files
committed
Auto merge of #134064 - jieyouxu:revert-131669, r=ChrisDenton
Revert #131669 due to ICEs Revert [lint: change help for pointers to dyn types in FFI #131669](#131669) due to ICE reports: - <#134059> (real-world) - <#134060> (fuzzing) Closes #134060. The revert criteria I used to assess whether to post this revert was: 1. It's not trivial to fix-forward. (1) The implementation itself is tricky due to `tcx.is_sized` query not being very trivial. (2) It will need more extensive test coverage for different ty kinds. 2. It is impacting real-world crates, i.e. #134059. 3. `improper_ctypes_definitions` is a warn-by-default lint. This revert is without prejudice to relanding the changes. The changes can be re-landed with those cases addressed and stronger test coverage. A rough regression test corresponding to the fuzzed example reported in #134060 is added to check that the revert worked, it is not sufficient for the lint test coverage when the lint improvements are to be relanded. Please feel free to improve the test in the reland. r? `@workingjubilee` (or compiler) cc `@niacdoial` (PR author)
2 parents f6cb952 + 38bfd88 commit a224f38

17 files changed

+208
-490
lines changed

compiler/rustc_lint/messages.ftl

+2-11
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,7 @@ lint_improper_ctypes_128bit = 128-bit integers don't currently have a known stab
359359
lint_improper_ctypes_array_help = consider passing a pointer to the array
360360
361361
lint_improper_ctypes_array_reason = passing raw arrays by value is not FFI-safe
362+
lint_improper_ctypes_box = box cannot be represented as a single pointer
362363
363364
lint_improper_ctypes_char_help = consider using `u32` or `libc::wchar_t` instead
364365
@@ -376,9 +377,7 @@ lint_improper_ctypes_enum_repr_help =
376377
lint_improper_ctypes_enum_repr_reason = enum has no representation hint
377378
lint_improper_ctypes_fnptr_help = consider using an `extern fn(...) -> ...` function pointer instead
378379
379-
lint_improper_ctypes_fnptr_indirect_reason = the function pointer to `{$ty}` is FFI-unsafe due to `{$inner_ty}`
380380
lint_improper_ctypes_fnptr_reason = this function pointer has Rust-specific calling convention
381-
382381
lint_improper_ctypes_non_exhaustive = this enum is non-exhaustive
383382
lint_improper_ctypes_non_exhaustive_variant = this enum has non-exhaustive variants
384383
@@ -389,11 +388,7 @@ lint_improper_ctypes_opaque = opaque types have no C equivalent
389388
lint_improper_ctypes_pat_help = consider using the base type instead
390389
391390
lint_improper_ctypes_pat_reason = pattern types have no C equivalent
392-
393-
lint_improper_ctypes_sized_ptr_to_unsafe_type =
394-
this reference (`{$ty}`) is ABI-compatible with a C pointer, but `{$inner_ty}` itself does not have a C layout
395-
396-
lint_improper_ctypes_slice_help = consider using a raw pointer to the slice's first element (and a length) instead
391+
lint_improper_ctypes_slice_help = consider using a raw pointer instead
397392
398393
lint_improper_ctypes_slice_reason = slices have no C equivalent
399394
lint_improper_ctypes_str_help = consider using `*const u8` and a length instead
@@ -419,10 +414,6 @@ lint_improper_ctypes_union_layout_help = consider adding a `#[repr(C)]` or `#[re
419414
lint_improper_ctypes_union_layout_reason = this union has unspecified layout
420415
lint_improper_ctypes_union_non_exhaustive = this union is non-exhaustive
421416
422-
lint_improper_ctypes_unsized_box = this box for an unsized type contains metadata, which makes it incompatible with a C pointer
423-
lint_improper_ctypes_unsized_ptr = this pointer to an unsized type contains metadata, which makes it incompatible with a C pointer
424-
lint_improper_ctypes_unsized_ref = this reference to an unsized type contains metadata, which makes it incompatible with a C pointer
425-
426417
lint_incomplete_include =
427418
include macro expected single expression in source
428419

compiler/rustc_lint/src/lints.rs

+9-36
Original file line numberDiff line numberDiff line change
@@ -1851,44 +1851,13 @@ pub(crate) struct UnpredictableFunctionPointerComparisonsSuggestion<'a> {
18511851
pub right: Span,
18521852
}
18531853

1854-
pub(crate) struct ImproperCTypesLayer<'a> {
1855-
pub ty: Ty<'a>,
1856-
pub inner_ty: Option<Ty<'a>>,
1857-
pub note: DiagMessage,
1858-
pub span_note: Option<Span>,
1859-
pub help: Option<DiagMessage>,
1860-
}
1861-
1862-
impl<'a> Subdiagnostic for ImproperCTypesLayer<'a> {
1863-
fn add_to_diag_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>(
1864-
self,
1865-
diag: &mut Diag<'_, G>,
1866-
f: &F,
1867-
) {
1868-
diag.arg("ty", self.ty);
1869-
if let Some(ty) = self.inner_ty {
1870-
diag.arg("inner_ty", ty);
1871-
}
1872-
1873-
if let Some(help) = self.help {
1874-
let msg = f(diag, help.into());
1875-
diag.help(msg);
1876-
}
1877-
1878-
let msg = f(diag, self.note.into());
1879-
diag.note(msg);
1880-
if let Some(note) = self.span_note {
1881-
let msg = f(diag, fluent::lint_note.into());
1882-
diag.span_note(note, msg);
1883-
};
1884-
}
1885-
}
1886-
18871854
pub(crate) struct ImproperCTypes<'a> {
18881855
pub ty: Ty<'a>,
18891856
pub desc: &'a str,
18901857
pub label: Span,
1891-
pub reasons: Vec<ImproperCTypesLayer<'a>>,
1858+
pub help: Option<DiagMessage>,
1859+
pub note: DiagMessage,
1860+
pub span_note: Option<Span>,
18921861
}
18931862

18941863
// Used because of the complexity of Option<DiagMessage>, DiagMessage, and Option<Span>
@@ -1898,8 +1867,12 @@ impl<'a> LintDiagnostic<'a, ()> for ImproperCTypes<'_> {
18981867
diag.arg("ty", self.ty);
18991868
diag.arg("desc", self.desc);
19001869
diag.span_label(self.label, fluent::lint_label);
1901-
for reason in self.reasons.into_iter() {
1902-
diag.subdiagnostic(reason);
1870+
if let Some(help) = self.help {
1871+
diag.help(help);
1872+
}
1873+
diag.note(self.note);
1874+
if let Some(note) = self.span_note {
1875+
diag.span_note(note, fluent::lint_note);
19031876
}
19041877
}
19051878
}

0 commit comments

Comments
 (0)