Skip to content

Commit a730d88

Browse files
committed
ty: simplify transparent_newtype_field
This commit removes the normalization from `transparent_newtype_field` - turns out it wasn't necessary and that makes it a bunch simpler - particularly when handling projections. Signed-off-by: David Wood <david@davidtw.co>
1 parent 0cccaa0 commit a730d88

File tree

3 files changed

+26
-14
lines changed

3 files changed

+26
-14
lines changed

src/librustc_lint/types.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -627,7 +627,7 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
627627
if def.repr.transparent() {
628628
// Can assume that only one field is not a ZST, so only check
629629
// that field's type for FFI-safety.
630-
if let Some(field) = variant.transparent_newtype_field(self.cx.tcx, self.cx.param_env) {
630+
if let Some(field) = variant.transparent_newtype_field(self.cx.tcx) {
631631
self.check_field_type_for_ffi(cache, field, substs)
632632
} else {
633633
bug!("malformed transparent type");

src/librustc_middle/ty/mod.rs

+1-13
Original file line numberDiff line numberDiff line change
@@ -1810,21 +1810,9 @@ impl<'tcx> VariantDef {
18101810

18111811
/// `repr(transparent)` structs can have a single non-ZST field, this function returns that
18121812
/// field.
1813-
pub fn transparent_newtype_field(
1814-
&self,
1815-
tcx: TyCtxt<'tcx>,
1816-
param_env: ParamEnv<'tcx>,
1817-
) -> Option<&FieldDef> {
1813+
pub fn transparent_newtype_field(&self, tcx: TyCtxt<'tcx>) -> Option<&FieldDef> {
18181814
for field in &self.fields {
18191815
let field_ty = field.ty(tcx, InternalSubsts::identity_for_item(tcx, self.def_id));
1820-
1821-
// `normalize_erasing_regions` will fail for projections that contain generic
1822-
// parameters, so check these before normalizing.
1823-
if field_ty.has_projections() && field_ty.needs_subst() {
1824-
return Some(field);
1825-
}
1826-
1827-
let field_ty = tcx.normalize_erasing_regions(param_env, field_ty);
18281816
if !field_ty.is_zst(tcx, self.def_id) {
18291817
return Some(field);
18301818
}
+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// check-pass
2+
#![deny(improper_ctypes)]
3+
4+
use std::marker::PhantomData;
5+
6+
trait Foo {
7+
type Assoc;
8+
}
9+
10+
impl Foo for () {
11+
type Assoc = PhantomData<()>;
12+
}
13+
14+
#[repr(transparent)]
15+
struct Wow<T> where T: Foo<Assoc = PhantomData<T>> {
16+
x: <T as Foo>::Assoc,
17+
v: u32,
18+
}
19+
20+
extern "C" {
21+
fn test(v: Wow<()>);
22+
}
23+
24+
fn main() {}

0 commit comments

Comments
 (0)