Skip to content

Commit 9af374a

Browse files
committed
Auto merge of rust-lang#47915 - eddyb:layout-of, r=nikomatsakis
rustc: prefer ParamEnvAnd and LayoutCx over tuples for LayoutOf. This PR provides `tcx.layout_of(param_env.and(ty))` as the idiomatic replacement for the existing `(tcx, param_env).layout_of(ty)` and removes fragile (coherence-wise) layout-related tuple impls. r? @nikomatsakis
2 parents 3d292b7 + 9c3dc7e commit 9af374a

File tree

8 files changed

+107
-84
lines changed

8 files changed

+107
-84
lines changed

src/librustc/lint/context.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,7 @@ impl<'a, 'tcx> LayoutOf<Ty<'tcx>> for &'a LateContext<'a, 'tcx> {
631631
type TyLayout = Result<TyLayout<'tcx>, LayoutError<'tcx>>;
632632

633633
fn layout_of(self, ty: Ty<'tcx>) -> Self::TyLayout {
634-
(self.tcx, self.param_env.reveal_all()).layout_of(ty)
634+
self.tcx.layout_of(self.param_env.and(ty))
635635
}
636636
}
637637

src/librustc/ty/layout.rs

+99-72
Large diffs are not rendered by default.

src/librustc_const_eval/eval.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ use rustc::hir::map::blocks::FnLikeNode;
1717
use rustc::hir::def::{Def, CtorKind};
1818
use rustc::hir::def_id::DefId;
1919
use rustc::ty::{self, Ty, TyCtxt};
20-
use rustc::ty::layout::LayoutOf;
2120
use rustc::ty::util::IntTypeExt;
2221
use rustc::ty::subst::{Substs, Subst};
2322
use rustc::util::common::ErrorReported;
@@ -313,7 +312,7 @@ fn eval_const_expr_partial<'a, 'tcx>(cx: &ConstContext<'a, 'tcx>,
313312
if tcx.fn_sig(def_id).abi() == Abi::RustIntrinsic {
314313
let layout_of = |ty: Ty<'tcx>| {
315314
let ty = tcx.erase_regions(&ty);
316-
(tcx.at(e.span), cx.param_env).layout_of(ty).map_err(|err| {
315+
tcx.at(e.span).layout_of(cx.param_env.and(ty)).map_err(|err| {
317316
ConstEvalErr { span: e.span, kind: LayoutError(err) }
318317
})
319318
};

src/librustc_lint/types.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -437,8 +437,8 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
437437
// repr(transparent) types are allowed to have arbitrary ZSTs, not just
438438
// PhantomData -- skip checking all ZST fields
439439
if def.repr.transparent() {
440-
let is_zst = (cx, cx.param_env(field.did))
441-
.layout_of(field_ty)
440+
let is_zst = cx
441+
.layout_of(cx.param_env(field.did).and(field_ty))
442442
.map(|layout| layout.is_zst())
443443
.unwrap_or(false);
444444
if is_zst {

src/librustc_mir/interpret/eval_context.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ impl<'a, 'tcx, M: Machine<'tcx>> LayoutOf<Ty<'tcx>> for &'a EvalContext<'a, 'tcx
172172
type TyLayout = EvalResult<'tcx, TyLayout<'tcx>>;
173173

174174
fn layout_of(self, ty: Ty<'tcx>) -> Self::TyLayout {
175-
(self.tcx, self.param_env).layout_of(ty)
175+
self.tcx.layout_of(self.param_env.and(ty))
176176
.map_err(|layout| EvalErrorKind::Layout(layout).into())
177177
}
178178
}

src/librustc_mir/transform/inline.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ use rustc_data_structures::indexed_vec::{Idx, IndexVec};
1919
use rustc::mir::*;
2020
use rustc::mir::visit::*;
2121
use rustc::ty::{self, Instance, Ty, TyCtxt, TypeFoldable};
22-
use rustc::ty::layout::LayoutOf;
2322
use rustc::ty::subst::{Subst,Substs};
2423

2524
use std::collections::VecDeque;
@@ -655,7 +654,7 @@ impl<'a, 'tcx> Inliner<'a, 'tcx> {
655654
fn type_size_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
656655
param_env: ty::ParamEnv<'tcx>,
657656
ty: Ty<'tcx>) -> Option<u64> {
658-
(tcx, param_env).layout_of(ty).ok().map(|layout| layout.size.bytes())
657+
tcx.layout_of(param_env.and(ty)).ok().map(|layout| layout.size.bytes())
659658
}
660659

661660
fn subst_and_normalize<'a, 'tcx: 'a>(

src/librustc_trans/context.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -464,8 +464,7 @@ impl<'a, 'tcx> LayoutOf<Ty<'tcx>> for &'a CodegenCx<'a, 'tcx> {
464464
type TyLayout = TyLayout<'tcx>;
465465

466466
fn layout_of(self, ty: Ty<'tcx>) -> Self::TyLayout {
467-
(self.tcx, ty::ParamEnv::empty(traits::Reveal::All))
468-
.layout_of(ty)
467+
self.tcx.layout_of(ty::ParamEnv::empty(traits::Reveal::All).and(ty))
469468
.unwrap_or_else(|e| match e {
470469
LayoutError::SizeOverflow(_) => self.sess().fatal(&e.to_string()),
471470
_ => bug!("failed to get layout for `{}`: {}", ty, e)

src/librustc_typeck/check/mod.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@ use rustc::ty::adjustment::{Adjust, Adjustment, AutoBorrow};
100100
use rustc::ty::fold::TypeFoldable;
101101
use rustc::ty::maps::Providers;
102102
use rustc::ty::util::{Representability, IntTypeExt};
103-
use rustc::ty::layout::LayoutOf;
104103
use errors::{DiagnosticBuilder, DiagnosticId};
105104

106105
use require_c_abi_if_variadic;
@@ -1553,7 +1552,7 @@ fn check_transparent<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, sp: Span, def_id: De
15531552
let field_infos: Vec<_> = adt.non_enum_variant().fields.iter().map(|field| {
15541553
let ty = field.ty(tcx, Substs::identity_for_item(tcx, field.did));
15551554
let param_env = tcx.param_env(field.did);
1556-
let layout = (tcx, param_env).layout_of(ty);
1555+
let layout = tcx.layout_of(param_env.and(ty));
15571556
// We are currently checking the type this field came from, so it must be local
15581557
let span = tcx.hir.span_if_local(field.did).unwrap();
15591558
let zst = layout.map(|layout| layout.is_zst()).unwrap_or(false);

0 commit comments

Comments
 (0)