提交 87d1fb74 编写于 作者: E Eduard-Mihai Burtescu

rustc_target: require `TyAbiInterface` in `LayoutOf`.

上级 8486571a
...@@ -41,7 +41,7 @@ ...@@ -41,7 +41,7 @@
use rustc_session::SessionLintStore; use rustc_session::SessionLintStore;
use rustc_span::lev_distance::find_best_match_for_name; use rustc_span::lev_distance::find_best_match_for_name;
use rustc_span::{symbol::Symbol, MultiSpan, Span, DUMMY_SP}; use rustc_span::{symbol::Symbol, MultiSpan, Span, DUMMY_SP};
use rustc_target::abi::LayoutOf; use rustc_target::abi::{self, LayoutOf};
use tracing::debug; use tracing::debug;
use std::cell::Cell; use std::cell::Cell;
...@@ -1059,6 +1059,27 @@ fn path_generic_args( ...@@ -1059,6 +1059,27 @@ fn path_generic_args(
} }
} }
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> { impl<'tcx> LayoutOf<'tcx> for LateContext<'tcx> {
type Ty = Ty<'tcx>; type Ty = Ty<'tcx>;
type TyAndLayout = Result<TyAndLayout<'tcx>, LayoutError<'tcx>>; type TyAndLayout = Result<TyAndLayout<'tcx>, LayoutError<'tcx>>;
......
...@@ -2034,6 +2034,20 @@ fn tcx(&self) -> TyCtxt<'tcx> { ...@@ -2034,6 +2034,20 @@ fn tcx(&self) -> 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> { impl<'tcx, C> HasParamEnv<'tcx> for LayoutCx<'tcx, C> {
fn param_env(&self) -> ty::ParamEnv<'tcx> { fn param_env(&self) -> ty::ParamEnv<'tcx> {
self.param_env self.param_env
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
Location, Operand, Place, Rvalue, SourceInfo, SourceScope, SourceScopeData, Statement, Location, Operand, Place, Rvalue, SourceInfo, SourceScope, SourceScopeData, Statement,
StatementKind, Terminator, TerminatorKind, UnOp, RETURN_PLACE, 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::subst::{InternalSubsts, Subst};
use rustc_middle::ty::{ use rustc_middle::ty::{
self, ConstInt, ConstKind, Instance, ParamEnv, ScalarInt, Ty, TyCtxt, TypeFoldable, self, ConstInt, ConstKind, Instance, ParamEnv, ScalarInt, Ty, TyCtxt, TypeFoldable,
...@@ -346,13 +346,20 @@ fn data_layout(&self) -> &TargetDataLayout { ...@@ -346,13 +346,20 @@ fn data_layout(&self) -> &TargetDataLayout {
} }
} }
impl<'mir, 'tcx> HasTyCtxt<'tcx> for ConstPropagator<'mir, 'tcx> { impl<'mir, 'tcx> ty::layout::HasTyCtxt<'tcx> for ConstPropagator<'mir, 'tcx> {
#[inline] #[inline]
fn tcx(&self) -> TyCtxt<'tcx> { fn tcx(&self) -> TyCtxt<'tcx> {
self.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> { impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
fn new( fn new(
body: &Body<'tcx>, body: &Body<'tcx>,
......
...@@ -1174,8 +1174,8 @@ fn deref(&self) -> &&'a Layout { ...@@ -1174,8 +1174,8 @@ fn deref(&self) -> &&'a Layout {
} }
/// Trait for context types that can compute layouts of things. /// Trait for context types that can compute layouts of things.
pub trait LayoutOf<'a> { pub trait LayoutOf<'a>: Sized {
type Ty; type Ty: TyAbiInterface<'a, Self>;
type TyAndLayout: MaybeResult<TyAndLayout<'a, Self::Ty>>; type TyAndLayout: MaybeResult<TyAndLayout<'a, Self::Ty>>;
fn layout_of(&self, ty: Self::Ty) -> Self::TyAndLayout; fn layout_of(&self, ty: Self::Ty) -> Self::TyAndLayout;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册