diff --git a/compiler/rustc_codegen_cranelift/src/common.rs b/compiler/rustc_codegen_cranelift/src/common.rs index 1d7a1f11b6c8028e9d9c8e96eae50d6b4f7dacc0..6f7ca51d038c0155233e9ad8dcea64cfa70a6b47 100644 --- a/compiler/rustc_codegen_cranelift/src/common.rs +++ b/compiler/rustc_codegen_cranelift/src/common.rs @@ -1,5 +1,5 @@ use rustc_index::vec::IndexVec; -use rustc_middle::ty::layout::LayoutError; +use rustc_middle::ty::layout::{LayoutError, LayoutOfHelpers}; use rustc_middle::ty::SymbolName; use rustc_target::abi::call::FnAbi; use rustc_target::abi::{Integer, Primitive}; @@ -257,7 +257,7 @@ pub(crate) struct FunctionCx<'m, 'clif, 'tcx: 'm> { pub(crate) inline_asm_index: u32, } -impl<'tcx> LayoutOf<'tcx> for FunctionCx<'_, '_, 'tcx> { +impl<'tcx> LayoutOfHelpers<'tcx> for FunctionCx<'_, '_, 'tcx> { type LayoutOfResult = TyAndLayout<'tcx>; #[inline] @@ -365,7 +365,7 @@ pub(crate) fn anonymous_str(&mut self, msg: &str) -> Value { pub(crate) struct RevealAllLayoutCx<'tcx>(pub(crate) TyCtxt<'tcx>); -impl<'tcx> LayoutOf<'tcx> for RevealAllLayoutCx<'tcx> { +impl<'tcx> LayoutOfHelpers<'tcx> for RevealAllLayoutCx<'tcx> { type LayoutOfResult = TyAndLayout<'tcx>; #[inline] diff --git a/compiler/rustc_codegen_llvm/src/builder.rs b/compiler/rustc_codegen_llvm/src/builder.rs index 2c420caad755a315252b1077bec9b17ced42cba2..da24fe08f0dfd6b7349e5290c27b216671de7678 100644 --- a/compiler/rustc_codegen_llvm/src/builder.rs +++ b/compiler/rustc_codegen_llvm/src/builder.rs @@ -15,7 +15,7 @@ use rustc_codegen_ssa::MemFlags; use rustc_data_structures::small_c_str::SmallCStr; use rustc_hir::def_id::DefId; -use rustc_middle::ty::layout::{LayoutError, LayoutOf, TyAndLayout}; +use rustc_middle::ty::layout::{LayoutError, LayoutOfHelpers, TyAndLayout}; use rustc_middle::ty::{self, Ty, TyCtxt}; use rustc_span::Span; use rustc_target::abi::{self, Align, Size}; @@ -88,7 +88,7 @@ fn target_spec(&self) -> &Target { } } -impl LayoutOf<'tcx> for Builder<'_, '_, 'tcx> { +impl LayoutOfHelpers<'tcx> for Builder<'_, '_, 'tcx> { type LayoutOfResult = TyAndLayout<'tcx>; #[inline] diff --git a/compiler/rustc_codegen_llvm/src/context.rs b/compiler/rustc_codegen_llvm/src/context.rs index 6cb85eeb0d92905df721adc5246c2c93b20b1d3a..2d397dc58353402fe76e6b4925e376176376a071 100644 --- a/compiler/rustc_codegen_llvm/src/context.rs +++ b/compiler/rustc_codegen_llvm/src/context.rs @@ -15,7 +15,7 @@ use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::small_c_str::SmallCStr; use rustc_middle::mir::mono::CodegenUnit; -use rustc_middle::ty::layout::{HasParamEnv, LayoutError, LayoutOf, TyAndLayout}; +use rustc_middle::ty::layout::{HasParamEnv, LayoutError, LayoutOfHelpers, TyAndLayout}; use rustc_middle::ty::{self, Instance, Ty, TyCtxt}; use rustc_middle::{bug, span_bug}; use rustc_session::config::{CFGuard, CrateType, DebugInfo}; @@ -835,7 +835,7 @@ fn tcx(&self) -> TyCtxt<'tcx> { } } -impl LayoutOf<'tcx> for CodegenCx<'ll, 'tcx> { +impl LayoutOfHelpers<'tcx> for CodegenCx<'ll, 'tcx> { type LayoutOfResult = TyAndLayout<'tcx>; #[inline] diff --git a/compiler/rustc_lint/src/context.rs b/compiler/rustc_lint/src/context.rs index ee43937e4d64f383fccd2fa3a9aa5b208b156f6c..4c45e33db79c73976ddb1f07dc78eea6bde5d886 100644 --- a/compiler/rustc_lint/src/context.rs +++ b/compiler/rustc_lint/src/context.rs @@ -31,7 +31,7 @@ use rustc_middle::lint::LintDiagnosticBuilder; use rustc_middle::middle::privacy::AccessLevels; use rustc_middle::middle::stability; -use rustc_middle::ty::layout::{LayoutError, LayoutOf, TyAndLayout}; +use rustc_middle::ty::layout::{LayoutError, LayoutOfHelpers, TyAndLayout}; use rustc_middle::ty::print::with_no_trimmed_paths; use rustc_middle::ty::{self, print::Printer, subst::GenericArg, Ty, TyCtxt}; use rustc_serialize::json::Json; @@ -1080,7 +1080,7 @@ fn param_env(&self) -> ty::ParamEnv<'tcx> { } } -impl<'tcx> LayoutOf<'tcx> for LateContext<'tcx> { +impl<'tcx> LayoutOfHelpers<'tcx> for LateContext<'tcx> { type LayoutOfResult = Result, LayoutError<'tcx>>; #[inline] diff --git a/compiler/rustc_middle/src/ty/layout.rs b/compiler/rustc_middle/src/ty/layout.rs index a9cbe2314140058b61146f90653a36772aafc43a..f7ab9dd82ac738971450a43ea912ba456ea56a8e 100644 --- a/compiler/rustc_middle/src/ty/layout.rs +++ b/compiler/rustc_middle/src/ty/layout.rs @@ -2093,8 +2093,9 @@ fn to_result(self) -> Result { pub type TyAndLayout<'tcx> = rustc_target::abi::TyAndLayout<'tcx, Ty<'tcx>>; -/// Trait for contexts that can compute layouts of types. -pub trait LayoutOf<'tcx>: HasDataLayout + HasTyCtxt<'tcx> + HasParamEnv<'tcx> { +/// Trait for contexts that want to be able to compute layouts of types. +/// This automatically gives access to `LayoutOf`, through a blanket `impl`. +pub trait LayoutOfHelpers<'tcx>: HasDataLayout + HasTyCtxt<'tcx> + HasParamEnv<'tcx> { /// The `TyAndLayout`-wrapping type (or `TyAndLayout` itself), which will be /// returned from `layout_of` (see also `handle_layout_err`). type LayoutOfResult: MaybeResult>; @@ -2119,7 +2120,10 @@ fn handle_layout_err( span: Span, ty: Ty<'tcx>, ) -> >>::Error; +} +/// Blanket extension trait for contexts that can compute layouts of types. +pub trait LayoutOf<'tcx>: LayoutOfHelpers<'tcx> { /// Computes the layout of a type. Note that this implicitly /// executes in "reveal all" mode, and will normalize the input type. #[inline] @@ -2143,7 +2147,9 @@ fn spanned_layout_of(&self, ty: Ty<'tcx>, span: Span) -> Self::LayoutOfResult { } } -impl LayoutOf<'tcx> for LayoutCx<'tcx, TyCtxt<'tcx>> { +impl> LayoutOf<'tcx> for C {} + +impl LayoutOfHelpers<'tcx> for LayoutCx<'tcx, TyCtxt<'tcx>> { type LayoutOfResult = Result, LayoutError<'tcx>>; #[inline] @@ -2152,7 +2158,7 @@ fn handle_layout_err(&self, err: LayoutError<'tcx>, _: Span, _: Ty<'tcx>) -> Lay } } -impl LayoutOf<'tcx> for LayoutCx<'tcx, ty::query::TyCtxtAt<'tcx>> { +impl LayoutOfHelpers<'tcx> for LayoutCx<'tcx, ty::query::TyCtxtAt<'tcx>> { type LayoutOfResult = Result, LayoutError<'tcx>>; #[inline] diff --git a/compiler/rustc_mir/src/interpret/eval_context.rs b/compiler/rustc_mir/src/interpret/eval_context.rs index 527caea19fa3ef1a0b239c1c22549f3d5978f62f..2b471415d86cc754793bc37cddbcb12c32099aa4 100644 --- a/compiler/rustc_mir/src/interpret/eval_context.rs +++ b/compiler/rustc_mir/src/interpret/eval_context.rs @@ -8,7 +8,7 @@ use rustc_macros::HashStable; use rustc_middle::ich::StableHashingContext; use rustc_middle::mir; -use rustc_middle::ty::layout::{self, LayoutError, LayoutOf, TyAndLayout}; +use rustc_middle::ty::layout::{self, LayoutError, LayoutOf, LayoutOfHelpers, TyAndLayout}; use rustc_middle::ty::{ self, query::TyCtxtAt, subst::SubstsRef, ParamEnv, Ty, TyCtxt, TypeFoldable, }; @@ -312,7 +312,7 @@ fn param_env(&self) -> ty::ParamEnv<'tcx> { } } -impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> LayoutOf<'tcx> for InterpCx<'mir, 'tcx, M> { +impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> LayoutOfHelpers<'tcx> for InterpCx<'mir, 'tcx, M> { type LayoutOfResult = InterpResult<'tcx, TyAndLayout<'tcx>>; #[inline] diff --git a/compiler/rustc_mir/src/transform/const_prop.rs b/compiler/rustc_mir/src/transform/const_prop.rs index 4be0f28f5d6c4426ef515dd68906b2da7c5d4e16..71c07be4c6d8de860919f58a7e51f38cc4d19e95 100644 --- a/compiler/rustc_mir/src/transform/const_prop.rs +++ b/compiler/rustc_mir/src/transform/const_prop.rs @@ -17,7 +17,7 @@ Location, Operand, Place, Rvalue, SourceInfo, SourceScope, SourceScopeData, Statement, StatementKind, Terminator, TerminatorKind, UnOp, RETURN_PLACE, }; -use rustc_middle::ty::layout::{LayoutError, LayoutOf, TyAndLayout}; +use rustc_middle::ty::layout::{LayoutError, LayoutOf, LayoutOfHelpers, TyAndLayout}; use rustc_middle::ty::subst::{InternalSubsts, Subst}; use rustc_middle::ty::{ self, ConstInt, ConstKind, Instance, ParamEnv, ScalarInt, Ty, TyCtxt, TypeFoldable, @@ -330,7 +330,7 @@ struct ConstPropagator<'mir, 'tcx> { source_info: Option, } -impl<'mir, 'tcx> LayoutOf<'tcx> for ConstPropagator<'mir, 'tcx> { +impl<'mir, 'tcx> LayoutOfHelpers<'tcx> for ConstPropagator<'mir, 'tcx> { type LayoutOfResult = Result, LayoutError<'tcx>>; #[inline] diff --git a/compiler/rustc_passes/src/layout_test.rs b/compiler/rustc_passes/src/layout_test.rs index 0b7fbb6bb8c0be972606a02ebb6ff9a4b2b6ec05..aa78fcfb4b373cc42066634ba885784ac7acb44b 100644 --- a/compiler/rustc_passes/src/layout_test.rs +++ b/compiler/rustc_passes/src/layout_test.rs @@ -3,7 +3,7 @@ use rustc_hir::def_id::LocalDefId; use rustc_hir::itemlikevisit::ItemLikeVisitor; use rustc_hir::ItemKind; -use rustc_middle::ty::layout::{HasParamEnv, HasTyCtxt, LayoutError, LayoutOf, TyAndLayout}; +use rustc_middle::ty::layout::{HasParamEnv, HasTyCtxt, LayoutError, LayoutOfHelpers, TyAndLayout}; use rustc_middle::ty::{ParamEnv, Ty, TyCtxt}; use rustc_span::symbol::sym; use rustc_span::Span; @@ -114,7 +114,7 @@ struct UnwrapLayoutCx<'tcx> { param_env: ParamEnv<'tcx>, } -impl LayoutOf<'tcx> for UnwrapLayoutCx<'tcx> { +impl LayoutOfHelpers<'tcx> for UnwrapLayoutCx<'tcx> { type LayoutOfResult = TyAndLayout<'tcx>; fn handle_layout_err(&self, err: LayoutError<'tcx>, span: Span, ty: Ty<'tcx>) -> ! {