diff --git a/src/librustc/ty/layout.rs b/src/librustc/ty/layout.rs index 3ad316f8f6d..b0631598554 100644 --- a/src/librustc/ty/layout.rs +++ b/src/librustc/ty/layout.rs @@ -12,7 +12,7 @@ use std::iter; use std::mem; use std::ops::Bound; -use hir; +use crate::hir; use crate::ich::StableHashingContext; use rustc_data_structures::indexed_vec::{IndexVec, Idx}; use rustc_data_structures::stable_hasher::{HashStable, StableHasher, @@ -1892,25 +1892,27 @@ impl<'a, 'tcx, C> TyLayoutMethods<'tcx, C> for Ty<'tcx> _ => { let mut data_variant = match this.variants { - Variants::NicheFilling { dataful_variant, .. } => { - // Only the niche in this is always initialized, - // so only check for a pointer at its offset. - // - // If the niche is a pointer, it's either valid - // (according to its type), or null (which the - // niche field's scalar validity range encodes). - // This allows using `dereferenceable_or_null` - // for e.g., `Option<&T>`, and this will continue - // to work as long as we don't start using more - // niches than just null (e.g., the first page - // of the address space, or unaligned pointers). - if this.fields.offset(0) == offset { - Some(this.for_variant(cx, dataful_variant)) - } else { - None - } - } - _ => Some(this) + // Within the discriminant field, only the niche itself is + // always initialized, so we only check for a pointer at its + // offset. + // + // If the niche is a pointer, it's either valid (according + // to its type), or null (which the niche field's scalar + // validity range encodes). This allows using + // `dereferenceable_or_null` for e.g., `Option<&T>`, and + // this will continue to work as long as we don't start + // using more niches than just null (e.g., the first page of + // the address space, or unaligned pointers). + Variants::Multiple { + discr_kind: DiscriminantKind::Niche { + dataful_variant, + .. + }, + discr_index, + .. + } if this.fields.offset(discr_index) == offset => + Some(this.for_variant(cx, dataful_variant)), + _ => Some(this), }; if let Some(variant) = data_variant { @@ -1931,9 +1933,8 @@ impl<'a, 'tcx, C> TyLayoutMethods<'tcx, C> for Ty<'tcx> result = field.ok() .and_then(|field| { if ptr_end <= field_start + field.size { - let off = offset - field_start; // We found the right field, look inside it. - Self::pointee_info_at(field, cx, off, param_env) + field.pointee_info_at(cx, offset - field_start, param_env) } else { None } diff --git a/src/librustc_codegen_llvm/abi.rs b/src/librustc_codegen_llvm/abi.rs index a59f756570f..1be07367914 100644 --- a/src/librustc_codegen_llvm/abi.rs +++ b/src/librustc_codegen_llvm/abi.rs @@ -2,17 +2,11 @@ use crate::llvm::{self, AttributePlace}; use crate::builder::Builder; use crate::context::CodegenCx; use crate::type_::Type; -use crate::type_of::{LayoutLlvmExt, PointerKind}; use crate::value::Value; +use crate::type_of::{LayoutLlvmExt}; use rustc_codegen_ssa::MemFlags; use rustc_codegen_ssa::mir::place::PlaceRef; use rustc_codegen_ssa::mir::operand::OperandValue; -<<<<<<< HEAD -======= -use type_::Type; -use type_of::{LayoutLlvmExt}; -use value::Value; ->>>>>>> Remove old pointee_info_at body. use rustc_target::abi::call::ArgType; use rustc_codegen_ssa::traits::*; diff --git a/src/librustc_codegen_llvm/context.rs b/src/librustc_codegen_llvm/context.rs index 55b28682725..7cf78a41feb 100644 --- a/src/librustc_codegen_llvm/context.rs +++ b/src/librustc_codegen_llvm/context.rs @@ -8,7 +8,6 @@ use rustc::hir; use crate::monomorphize::partitioning::CodegenUnit; use crate::type_::Type; -use crate::type_of::PointeeInfo; use rustc_codegen_ssa::traits::*; use rustc_data_structures::base_n; diff --git a/src/librustc_codegen_llvm/type_of.rs b/src/librustc_codegen_llvm/type_of.rs index fd15fdf2176..3f717754e32 100644 --- a/src/librustc_codegen_llvm/type_of.rs +++ b/src/librustc_codegen_llvm/type_of.rs @@ -1,9 +1,6 @@ use crate::abi::{FnType, FnTypeExt}; use crate::common::*; use crate::type_::Type; -use rustc::hir; -use abi::{FnType, FnTypeExt}; -use common::*; use rustc::ty::{self, Ty, TypeFoldable}; use rustc::ty::layout::{self, Align, LayoutOf, PointeeInfo, Size, TyLayout}; use rustc_target::abi::{FloatTy, TyLayoutMethods};