rustc_target: require TyAbiInterface in LayoutOf.

This commit is contained in:
Eduard-Mihai Burtescu 2021-08-25 16:40:39 +03:00
parent 8486571a10
commit 87d1fb747f
4 changed files with 47 additions and 5 deletions

View File

@ -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>>;

View File

@ -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

View File

@ -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>,

View File

@ -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;