Skip to content

Commit f53c93c

Browse files
committed
ty::layout: split LayoutOf into required and (blanket) provided halves.
1 parent 1e02262 commit f53c93c

File tree

8 files changed

+25
-19
lines changed

8 files changed

+25
-19
lines changed

compiler/rustc_codegen_cranelift/src/common.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use rustc_index::vec::IndexVec;
2-
use rustc_middle::ty::layout::LayoutError;
2+
use rustc_middle::ty::layout::{LayoutError, LayoutOfHelpers};
33
use rustc_middle::ty::SymbolName;
44
use rustc_target::abi::call::FnAbi;
55
use rustc_target::abi::{Integer, Primitive};
@@ -257,7 +257,7 @@ pub(crate) struct FunctionCx<'m, 'clif, 'tcx: 'm> {
257257
pub(crate) inline_asm_index: u32,
258258
}
259259

260-
impl<'tcx> LayoutOf<'tcx> for FunctionCx<'_, '_, 'tcx> {
260+
impl<'tcx> LayoutOfHelpers<'tcx> for FunctionCx<'_, '_, 'tcx> {
261261
type LayoutOfResult = TyAndLayout<'tcx>;
262262

263263
#[inline]
@@ -365,7 +365,7 @@ impl<'tcx> FunctionCx<'_, '_, 'tcx> {
365365

366366
pub(crate) struct RevealAllLayoutCx<'tcx>(pub(crate) TyCtxt<'tcx>);
367367

368-
impl<'tcx> LayoutOf<'tcx> for RevealAllLayoutCx<'tcx> {
368+
impl<'tcx> LayoutOfHelpers<'tcx> for RevealAllLayoutCx<'tcx> {
369369
type LayoutOfResult = TyAndLayout<'tcx>;
370370

371371
#[inline]

compiler/rustc_codegen_llvm/src/builder.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use rustc_codegen_ssa::traits::*;
1515
use rustc_codegen_ssa::MemFlags;
1616
use rustc_data_structures::small_c_str::SmallCStr;
1717
use rustc_hir::def_id::DefId;
18-
use rustc_middle::ty::layout::{LayoutError, LayoutOf, TyAndLayout};
18+
use rustc_middle::ty::layout::{LayoutError, LayoutOfHelpers, TyAndLayout};
1919
use rustc_middle::ty::{self, Ty, TyCtxt};
2020
use rustc_span::Span;
2121
use rustc_target::abi::{self, Align, Size};
@@ -88,7 +88,7 @@ impl HasTargetSpec for Builder<'_, '_, 'tcx> {
8888
}
8989
}
9090

91-
impl LayoutOf<'tcx> for Builder<'_, '_, 'tcx> {
91+
impl LayoutOfHelpers<'tcx> for Builder<'_, '_, 'tcx> {
9292
type LayoutOfResult = TyAndLayout<'tcx>;
9393

9494
#[inline]

compiler/rustc_codegen_llvm/src/context.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use rustc_data_structures::base_n;
1515
use rustc_data_structures::fx::FxHashMap;
1616
use rustc_data_structures::small_c_str::SmallCStr;
1717
use rustc_middle::mir::mono::CodegenUnit;
18-
use rustc_middle::ty::layout::{HasParamEnv, LayoutError, LayoutOf, TyAndLayout};
18+
use rustc_middle::ty::layout::{HasParamEnv, LayoutError, LayoutOfHelpers, TyAndLayout};
1919
use rustc_middle::ty::{self, Instance, Ty, TyCtxt};
2020
use rustc_middle::{bug, span_bug};
2121
use rustc_session::config::{CFGuard, CrateType, DebugInfo};
@@ -835,7 +835,7 @@ impl ty::layout::HasTyCtxt<'tcx> for CodegenCx<'ll, 'tcx> {
835835
}
836836
}
837837

838-
impl LayoutOf<'tcx> for CodegenCx<'ll, 'tcx> {
838+
impl LayoutOfHelpers<'tcx> for CodegenCx<'ll, 'tcx> {
839839
type LayoutOfResult = TyAndLayout<'tcx>;
840840

841841
#[inline]

compiler/rustc_lint/src/context.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ use rustc_hir::definitions::{DefPathData, DisambiguatedDefPathData};
3131
use rustc_middle::lint::LintDiagnosticBuilder;
3232
use rustc_middle::middle::privacy::AccessLevels;
3333
use rustc_middle::middle::stability;
34-
use rustc_middle::ty::layout::{LayoutError, LayoutOf, TyAndLayout};
34+
use rustc_middle::ty::layout::{LayoutError, LayoutOfHelpers, TyAndLayout};
3535
use rustc_middle::ty::print::with_no_trimmed_paths;
3636
use rustc_middle::ty::{self, print::Printer, subst::GenericArg, Ty, TyCtxt};
3737
use rustc_serialize::json::Json;
@@ -1080,7 +1080,7 @@ impl<'tcx> ty::layout::HasParamEnv<'tcx> for LateContext<'tcx> {
10801080
}
10811081
}
10821082

1083-
impl<'tcx> LayoutOf<'tcx> for LateContext<'tcx> {
1083+
impl<'tcx> LayoutOfHelpers<'tcx> for LateContext<'tcx> {
10841084
type LayoutOfResult = Result<TyAndLayout<'tcx>, LayoutError<'tcx>>;
10851085

10861086
#[inline]

compiler/rustc_middle/src/ty/layout.rs

+10-4
Original file line numberDiff line numberDiff line change
@@ -2093,8 +2093,9 @@ impl<T, E> MaybeResult<T> for Result<T, E> {
20932093

20942094
pub type TyAndLayout<'tcx> = rustc_target::abi::TyAndLayout<'tcx, Ty<'tcx>>;
20952095

2096-
/// Trait for contexts that can compute layouts of types.
2097-
pub trait LayoutOf<'tcx>: HasDataLayout + HasTyCtxt<'tcx> + HasParamEnv<'tcx> {
2096+
/// Trait for contexts that want to be able to compute layouts of types.
2097+
/// This automatically gives access to `LayoutOf`, through a blanket `impl`.
2098+
pub trait LayoutOfHelpers<'tcx>: HasDataLayout + HasTyCtxt<'tcx> + HasParamEnv<'tcx> {
20982099
/// The `TyAndLayout`-wrapping type (or `TyAndLayout` itself), which will be
20992100
/// returned from `layout_of` (see also `handle_layout_err`).
21002101
type LayoutOfResult: MaybeResult<TyAndLayout<'tcx>>;
@@ -2119,7 +2120,10 @@ pub trait LayoutOf<'tcx>: HasDataLayout + HasTyCtxt<'tcx> + HasParamEnv<'tcx> {
21192120
span: Span,
21202121
ty: Ty<'tcx>,
21212122
) -> <Self::LayoutOfResult as MaybeResult<TyAndLayout<'tcx>>>::Error;
2123+
}
21222124

2125+
/// Blanket extension trait for contexts that can compute layouts of types.
2126+
pub trait LayoutOf<'tcx>: LayoutOfHelpers<'tcx> {
21232127
/// Computes the layout of a type. Note that this implicitly
21242128
/// executes in "reveal all" mode, and will normalize the input type.
21252129
#[inline]
@@ -2143,7 +2147,9 @@ pub trait LayoutOf<'tcx>: HasDataLayout + HasTyCtxt<'tcx> + HasParamEnv<'tcx> {
21432147
}
21442148
}
21452149

2146-
impl LayoutOf<'tcx> for LayoutCx<'tcx, TyCtxt<'tcx>> {
2150+
impl<C: LayoutOfHelpers<'tcx>> LayoutOf<'tcx> for C {}
2151+
2152+
impl LayoutOfHelpers<'tcx> for LayoutCx<'tcx, TyCtxt<'tcx>> {
21472153
type LayoutOfResult = Result<TyAndLayout<'tcx>, LayoutError<'tcx>>;
21482154

21492155
#[inline]
@@ -2152,7 +2158,7 @@ impl LayoutOf<'tcx> for LayoutCx<'tcx, TyCtxt<'tcx>> {
21522158
}
21532159
}
21542160

2155-
impl LayoutOf<'tcx> for LayoutCx<'tcx, ty::query::TyCtxtAt<'tcx>> {
2161+
impl LayoutOfHelpers<'tcx> for LayoutCx<'tcx, ty::query::TyCtxtAt<'tcx>> {
21562162
type LayoutOfResult = Result<TyAndLayout<'tcx>, LayoutError<'tcx>>;
21572163

21582164
#[inline]

compiler/rustc_mir/src/interpret/eval_context.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use rustc_index::vec::IndexVec;
88
use rustc_macros::HashStable;
99
use rustc_middle::ich::StableHashingContext;
1010
use rustc_middle::mir;
11-
use rustc_middle::ty::layout::{self, LayoutError, LayoutOf, TyAndLayout};
11+
use rustc_middle::ty::layout::{self, LayoutError, LayoutOf, LayoutOfHelpers, TyAndLayout};
1212
use rustc_middle::ty::{
1313
self, query::TyCtxtAt, subst::SubstsRef, ParamEnv, Ty, TyCtxt, TypeFoldable,
1414
};
@@ -312,7 +312,7 @@ where
312312
}
313313
}
314314

315-
impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> LayoutOf<'tcx> for InterpCx<'mir, 'tcx, M> {
315+
impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> LayoutOfHelpers<'tcx> for InterpCx<'mir, 'tcx, M> {
316316
type LayoutOfResult = InterpResult<'tcx, TyAndLayout<'tcx>>;
317317

318318
#[inline]

compiler/rustc_mir/src/transform/const_prop.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use rustc_middle::mir::{
1717
Location, Operand, Place, Rvalue, SourceInfo, SourceScope, SourceScopeData, Statement,
1818
StatementKind, Terminator, TerminatorKind, UnOp, RETURN_PLACE,
1919
};
20-
use rustc_middle::ty::layout::{LayoutError, LayoutOf, TyAndLayout};
20+
use rustc_middle::ty::layout::{LayoutError, LayoutOf, LayoutOfHelpers, TyAndLayout};
2121
use rustc_middle::ty::subst::{InternalSubsts, Subst};
2222
use rustc_middle::ty::{
2323
self, ConstInt, ConstKind, Instance, ParamEnv, ScalarInt, Ty, TyCtxt, TypeFoldable,
@@ -330,7 +330,7 @@ struct ConstPropagator<'mir, 'tcx> {
330330
source_info: Option<SourceInfo>,
331331
}
332332

333-
impl<'mir, 'tcx> LayoutOf<'tcx> for ConstPropagator<'mir, 'tcx> {
333+
impl<'mir, 'tcx> LayoutOfHelpers<'tcx> for ConstPropagator<'mir, 'tcx> {
334334
type LayoutOfResult = Result<TyAndLayout<'tcx>, LayoutError<'tcx>>;
335335

336336
#[inline]

compiler/rustc_passes/src/layout_test.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use rustc_hir as hir;
33
use rustc_hir::def_id::LocalDefId;
44
use rustc_hir::itemlikevisit::ItemLikeVisitor;
55
use rustc_hir::ItemKind;
6-
use rustc_middle::ty::layout::{HasParamEnv, HasTyCtxt, LayoutError, LayoutOf, TyAndLayout};
6+
use rustc_middle::ty::layout::{HasParamEnv, HasTyCtxt, LayoutError, LayoutOfHelpers, TyAndLayout};
77
use rustc_middle::ty::{ParamEnv, Ty, TyCtxt};
88
use rustc_span::symbol::sym;
99
use rustc_span::Span;
@@ -114,7 +114,7 @@ struct UnwrapLayoutCx<'tcx> {
114114
param_env: ParamEnv<'tcx>,
115115
}
116116

117-
impl LayoutOf<'tcx> for UnwrapLayoutCx<'tcx> {
117+
impl LayoutOfHelpers<'tcx> for UnwrapLayoutCx<'tcx> {
118118
type LayoutOfResult = TyAndLayout<'tcx>;
119119

120120
fn handle_layout_err(&self, err: LayoutError<'tcx>, span: Span, ty: Ty<'tcx>) -> ! {

0 commit comments

Comments
 (0)