diff options
| author | Eduard-Mihai Burtescu <eddyb@lyken.rs> | 2021-08-25 16:40:39 +0300 |
|---|---|---|
| committer | Eduard-Mihai Burtescu <eddyb@lyken.rs> | 2021-08-27 13:09:32 +0300 |
| commit | 87d1fb747f8ed3dde3cd36c17d1ef735872a7bf9 (patch) | |
| tree | 0557567511048be5e9f425d3d0e7ad7fcb4c9e17 | |
| parent | 8486571a10ce57b02ae19bfb1b31736fb2a1b4fe (diff) | |
| download | rust-87d1fb747f8ed3dde3cd36c17d1ef735872a7bf9.tar.gz rust-87d1fb747f8ed3dde3cd36c17d1ef735872a7bf9.zip | |
rustc_target: require `TyAbiInterface` in `LayoutOf`.
| -rw-r--r-- | compiler/rustc_lint/src/context.rs | 23 | ||||
| -rw-r--r-- | compiler/rustc_middle/src/ty/layout.rs | 14 | ||||
| -rw-r--r-- | compiler/rustc_mir/src/transform/const_prop.rs | 11 | ||||
| -rw-r--r-- | compiler/rustc_target/src/abi/mod.rs | 4 |
4 files changed, 47 insertions, 5 deletions
diff --git a/compiler/rustc_lint/src/context.rs b/compiler/rustc_lint/src/context.rs index 6c622a43015..7dbc3d60439 100644 --- a/compiler/rustc_lint/src/context.rs +++ b/compiler/rustc_lint/src/context.rs @@ -41,7 +41,7 @@ use rustc_session::Session; use rustc_session::SessionLintStore; use rustc_span::lev_distance::find_best_match_for_name; use rustc_span::{symbol::Symbol, MultiSpan, Span, DUMMY_SP}; -use rustc_target::abi::LayoutOf; +use rustc_target::abi::{self, LayoutOf}; use tracing::debug; use std::cell::Cell; @@ -1059,6 +1059,27 @@ impl<'tcx> LateContext<'tcx> { } } +impl<'tcx> abi::HasDataLayout for LateContext<'tcx> { + #[inline] + fn data_layout(&self) -> &abi::TargetDataLayout { + &self.tcx.data_layout + } +} + +impl<'tcx> ty::layout::HasTyCtxt<'tcx> for LateContext<'tcx> { + #[inline] + fn tcx(&self) -> TyCtxt<'tcx> { + self.tcx + } +} + +impl<'tcx> ty::layout::HasParamEnv<'tcx> for LateContext<'tcx> { + #[inline] + fn param_env(&self) -> ty::ParamEnv<'tcx> { + self.param_env + } +} + impl<'tcx> LayoutOf<'tcx> for LateContext<'tcx> { type Ty = Ty<'tcx>; type TyAndLayout = Result<TyAndLayout<'tcx>, LayoutError<'tcx>>; diff --git a/compiler/rustc_middle/src/ty/layout.rs b/compiler/rustc_middle/src/ty/layout.rs index d8d1f4929ad..df5e6b2da99 100644 --- a/compiler/rustc_middle/src/ty/layout.rs +++ b/compiler/rustc_middle/src/ty/layout.rs @@ -2034,6 +2034,20 @@ impl<'tcx> HasTyCtxt<'tcx> for TyCtxt<'tcx> { } } +impl<'tcx> HasDataLayout for ty::query::TyCtxtAt<'tcx> { + #[inline] + fn data_layout(&self) -> &TargetDataLayout { + &self.data_layout + } +} + +impl<'tcx> HasTyCtxt<'tcx> for ty::query::TyCtxtAt<'tcx> { + #[inline] + fn tcx(&self) -> TyCtxt<'tcx> { + **self + } +} + impl<'tcx, C> HasParamEnv<'tcx> for LayoutCx<'tcx, C> { fn param_env(&self) -> ty::ParamEnv<'tcx> { self.param_env diff --git a/compiler/rustc_mir/src/transform/const_prop.rs b/compiler/rustc_mir/src/transform/const_prop.rs index c17c88973a9..5c51aa4ed67 100644 --- a/compiler/rustc_mir/src/transform/const_prop.rs +++ b/compiler/rustc_mir/src/transform/const_prop.rs @@ -17,7 +17,7 @@ use rustc_middle::mir::{ Location, Operand, Place, Rvalue, SourceInfo, SourceScope, SourceScopeData, Statement, StatementKind, Terminator, TerminatorKind, UnOp, RETURN_PLACE, }; -use rustc_middle::ty::layout::{HasTyCtxt, LayoutError, TyAndLayout}; +use rustc_middle::ty::layout::{LayoutError, TyAndLayout}; use rustc_middle::ty::subst::{InternalSubsts, Subst}; use rustc_middle::ty::{ self, ConstInt, ConstKind, Instance, ParamEnv, ScalarInt, Ty, TyCtxt, TypeFoldable, @@ -346,13 +346,20 @@ impl<'mir, 'tcx> HasDataLayout for ConstPropagator<'mir, 'tcx> { } } -impl<'mir, 'tcx> HasTyCtxt<'tcx> for ConstPropagator<'mir, 'tcx> { +impl<'mir, 'tcx> ty::layout::HasTyCtxt<'tcx> for ConstPropagator<'mir, 'tcx> { #[inline] fn tcx(&self) -> TyCtxt<'tcx> { self.tcx } } +impl<'mir, 'tcx> ty::layout::HasParamEnv<'tcx> for ConstPropagator<'mir, 'tcx> { + #[inline] + fn param_env(&self) -> ty::ParamEnv<'tcx> { + self.param_env + } +} + impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> { fn new( body: &Body<'tcx>, diff --git a/compiler/rustc_target/src/abi/mod.rs b/compiler/rustc_target/src/abi/mod.rs index 250afbecd58..367071926fe 100644 --- a/compiler/rustc_target/src/abi/mod.rs +++ b/compiler/rustc_target/src/abi/mod.rs @@ -1174,8 +1174,8 @@ impl<'a, Ty> Deref for TyAndLayout<'a, Ty> { } /// Trait for context types that can compute layouts of things. -pub trait LayoutOf<'a> { - type Ty; +pub trait LayoutOf<'a>: Sized { + type Ty: TyAbiInterface<'a, Self>; type TyAndLayout: MaybeResult<TyAndLayout<'a, Self::Ty>>; fn layout_of(&self, ty: Self::Ty) -> Self::TyAndLayout; |
