1
Fork 0

lint/ty: move fns to avoid abstraction violation

This commit moves `transparent_newtype_field` and `is_zst` to
`LateContext` where they are used, rather than being on the `VariantDef`
and `TyS` types.

Signed-off-by: David Wood <david@davidtw.co>
This commit is contained in:
David Wood 2020-08-03 11:08:03 +01:00
parent 85fbf49ce0
commit 0f2bd56b29
No known key found for this signature in database
GPG key ID: 2592E76C87381FD9
4 changed files with 27 additions and 25 deletions

View file

@ -2005,7 +2005,7 @@ pub struct VariantDef {
flags: VariantFlags,
}
impl<'tcx> VariantDef {
impl VariantDef {
/// Creates a new `VariantDef`.
///
/// `variant_did` is the `DefId` that identifies the enum variant (if this `VariantDef`
@ -2071,19 +2071,6 @@ impl<'tcx> VariantDef {
pub fn is_recovered(&self) -> bool {
self.flags.intersects(VariantFlags::IS_RECOVERED)
}
/// `repr(transparent)` structs can have a single non-ZST field, this function returns that
/// field.
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));
if !field_ty.is_zst(tcx, self.def_id) {
return Some(field);
}
}
None
}
}
#[derive(Copy, Clone, Debug, PartialEq, Eq, TyEncodable, TyDecodable, HashStable)]

View file

@ -2280,9 +2280,4 @@ impl<'tcx> TyS<'tcx> {
}
}
}
/// Is this a zero-sized type?
pub fn is_zst(&'tcx self, tcx: TyCtxt<'tcx>, did: DefId) -> bool {
tcx.layout_of(tcx.param_env(did).and(self)).map(|layout| layout.is_zst()).unwrap_or(false)
}
}