diff --git a/src/librustc_lint/types.rs b/src/librustc_lint/types.rs index b20bf432614..b490c06403d 100644 --- a/src/librustc_lint/types.rs +++ b/src/librustc_lint/types.rs @@ -627,7 +627,7 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> { if def.repr.transparent() { // Can assume that only one field is not a ZST, so only check // that field's type for FFI-safety. - if let Some(field) = variant.transparent_newtype_field(self.cx.tcx, self.cx.param_env) { + if let Some(field) = variant.transparent_newtype_field(self.cx.tcx) { self.check_field_type_for_ffi(cache, field, substs) } else { bug!("malformed transparent type"); diff --git a/src/librustc_middle/ty/mod.rs b/src/librustc_middle/ty/mod.rs index 30643165ce9..b4e3e6ab5ab 100644 --- a/src/librustc_middle/ty/mod.rs +++ b/src/librustc_middle/ty/mod.rs @@ -1810,21 +1810,9 @@ impl<'tcx> VariantDef { /// `repr(transparent)` structs can have a single non-ZST field, this function returns that /// field. - pub fn transparent_newtype_field( - &self, - tcx: TyCtxt<'tcx>, - param_env: ParamEnv<'tcx>, - ) -> Option<&FieldDef> { + pub fn transparent_newtype_field(&self, tcx: TyCtxt<'tcx>) -> Option<&FieldDef> { for field in &self.fields { let field_ty = field.ty(tcx, InternalSubsts::identity_for_item(tcx, self.def_id)); - - // `normalize_erasing_regions` will fail for projections that contain generic - // parameters, so check these before normalizing. - if field_ty.has_projections() && field_ty.needs_subst() { - return Some(field); - } - - let field_ty = tcx.normalize_erasing_regions(param_env, field_ty); if !field_ty.is_zst(tcx, self.def_id) { return Some(field); } diff --git a/src/test/ui/lint/lint-ctypes-73249-4.rs b/src/test/ui/lint/lint-ctypes-73249-4.rs new file mode 100644 index 00000000000..6c72bd691b1 --- /dev/null +++ b/src/test/ui/lint/lint-ctypes-73249-4.rs @@ -0,0 +1,24 @@ +// check-pass +#![deny(improper_ctypes)] + +use std::marker::PhantomData; + +trait Foo { + type Assoc; +} + +impl Foo for () { + type Assoc = PhantomData<()>; +} + +#[repr(transparent)] +struct Wow where T: Foo> { + x: ::Assoc, + v: u32, +} + +extern "C" { + fn test(v: Wow<()>); +} + +fn main() {}