Rollup merge of #75099 - davidtwco:is-zst-abstraction-violation, r=eddyb
lint/ty: move fns to avoid abstraction violation This PR moves `transparent_newtype_field` and `is_zst` to `LateContext` where they are used, rather than being on the `VariantDef` and `TyS` types, hopefully addressing @eddyb's concern [from this comment](https://github.com/rust-lang/rust/pull/74340#discussion_r456534910).
This commit is contained in:
commit
aa25f9ebd8
4 changed files with 27 additions and 25 deletions
|
@ -1999,7 +1999,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`
|
||||
|
@ -2065,19 +2065,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)]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue