diff --git a/src/librustc/lint/builtin.rs b/src/librustc/lint/builtin.rs index 1af8e2f29ebd7..eeba5650e543a 100644 --- a/src/librustc/lint/builtin.rs +++ b/src/librustc/lint/builtin.rs @@ -426,6 +426,22 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> { representation annotation in foreign module, consider \ adding a #[repr(...)] attribute to the type"); } + + if let ty::ty_struct(..) = tty.sty { + let ty_fields = ty::ty_to_def_id(tty).map(|ty_id| { + ty::lookup_struct_fields(self.cx.tcx, ty_id) + }); + match ty_fields { + Some(ty_fields_really) => { + if ty_fields_really.is_empty() { + self.cx.span_lint(IMPROPER_CTYPES, sp, + "found unit struct in use in foreign \ + module, which is invalid in standard C"); + } + }, + _ => unreachable!("struct should have fields!") + } + } } _ => () }