@@ -436,7 +436,6 @@ impl<'tcx> FfiResult<'tcx> {
436436 /// For instance, if we have a repr(C) struct in a function's argument, FFI unsafeties inside the struct
437437 /// are to be blamed on the struct and not the members.
438438 /// This is where we use this wrapper, to tell "all FFI-unsafeties in there are caused by this `ty`"
439- #[ expect( unused) ]
440439 fn with_overrides ( mut self , override_cause_ty : Option < Ty < ' tcx > > ) -> FfiResult < ' tcx > {
441440 use FfiResult :: * ;
442441
@@ -982,7 +981,9 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
982981 all_phantom &= match self . visit_type ( state. get_next ( ty) , field_ty) {
983982 FfiSafe => false ,
984983 FfiPhantom ( ..) => true ,
985- r @ FfiUnsafe { .. } => return r,
984+ r @ FfiUnsafe { .. } => {
985+ return r. wrap_all ( ty, fluent:: lint_improper_ctypes_struct_dueto, None ) ;
986+ }
986987 }
987988 }
988989
@@ -1033,7 +1034,7 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
10331034 ) ;
10341035 }
10351036
1036- if def. non_enum_variant ( ) . fields . is_empty ( ) {
1037+ let ffires = if def. non_enum_variant ( ) . fields . is_empty ( ) {
10371038 FfiResult :: new_with_reason (
10381039 ty,
10391040 if def. is_struct ( ) {
@@ -1049,7 +1050,15 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
10491050 )
10501051 } else {
10511052 self . visit_variant_fields ( state, ty, def, def. non_enum_variant ( ) , args)
1052- }
1053+ } ;
1054+
1055+ // Here, if there is something wrong, then the "fault" comes from inside the struct itself.
1056+ // Even if we add more details to the lint, the initial line must specify that
1057+ // the FFI-unsafety is because of the struct
1058+ // Plus, if the struct is from another crate, then there's not much that can be done anyways
1059+ //
1060+ // So, we override the "cause type" of the lint.
1061+ ffires. with_overrides ( Some ( ty) )
10531062 }
10541063
10551064 fn visit_enum (
@@ -1096,10 +1105,13 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
10961105 }
10971106 } ) ;
10981107 if let ControlFlow :: Break ( result) = ret {
1099- return result;
1108+ // this enum is visited in the middle of another lint,
1109+ // so we override the "cause type" of the lint
1110+ // (for more detail, see comment in ``visit_struct_union`` before its call to ``result.with_overrides``)
1111+ result. with_overrides ( Some ( ty) )
1112+ } else {
1113+ FfiSafe
11001114 }
1101-
1102- FfiSafe
11031115 }
11041116
11051117 /// Checks if the given type is "ffi-safe" (has a stable, well-defined
0 commit comments