Skip to content

Commit 87d1fb7

Browse files
committed
rustc_target: require TyAbiInterface in LayoutOf.
1 parent 8486571 commit 87d1fb7

File tree

4 files changed

+47
-5
lines changed

4 files changed

+47
-5
lines changed

compiler/rustc_lint/src/context.rs

+22-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ use rustc_session::Session;
4141
use rustc_session::SessionLintStore;
4242
use rustc_span::lev_distance::find_best_match_for_name;
4343
use rustc_span::{symbol::Symbol, MultiSpan, Span, DUMMY_SP};
44-
use rustc_target::abi::LayoutOf;
44+
use rustc_target::abi::{self, LayoutOf};
4545
use tracing::debug;
4646

4747
use std::cell::Cell;
@@ -1059,6 +1059,27 @@ impl<'tcx> LateContext<'tcx> {
10591059
}
10601060
}
10611061

1062+
impl<'tcx> abi::HasDataLayout for LateContext<'tcx> {
1063+
#[inline]
1064+
fn data_layout(&self) -> &abi::TargetDataLayout {
1065+
&self.tcx.data_layout
1066+
}
1067+
}
1068+
1069+
impl<'tcx> ty::layout::HasTyCtxt<'tcx> for LateContext<'tcx> {
1070+
#[inline]
1071+
fn tcx(&self) -> TyCtxt<'tcx> {
1072+
self.tcx
1073+
}
1074+
}
1075+
1076+
impl<'tcx> ty::layout::HasParamEnv<'tcx> for LateContext<'tcx> {
1077+
#[inline]
1078+
fn param_env(&self) -> ty::ParamEnv<'tcx> {
1079+
self.param_env
1080+
}
1081+
}
1082+
10621083
impl<'tcx> LayoutOf<'tcx> for LateContext<'tcx> {
10631084
type Ty = Ty<'tcx>;
10641085
type TyAndLayout = Result<TyAndLayout<'tcx>, LayoutError<'tcx>>;

compiler/rustc_middle/src/ty/layout.rs

+14
Original file line numberDiff line numberDiff line change
@@ -2034,6 +2034,20 @@ impl<'tcx> HasTyCtxt<'tcx> for TyCtxt<'tcx> {
20342034
}
20352035
}
20362036

2037+
impl<'tcx> HasDataLayout for ty::query::TyCtxtAt<'tcx> {
2038+
#[inline]
2039+
fn data_layout(&self) -> &TargetDataLayout {
2040+
&self.data_layout
2041+
}
2042+
}
2043+
2044+
impl<'tcx> HasTyCtxt<'tcx> for ty::query::TyCtxtAt<'tcx> {
2045+
#[inline]
2046+
fn tcx(&self) -> TyCtxt<'tcx> {
2047+
**self
2048+
}
2049+
}
2050+
20372051
impl<'tcx, C> HasParamEnv<'tcx> for LayoutCx<'tcx, C> {
20382052
fn param_env(&self) -> ty::ParamEnv<'tcx> {
20392053
self.param_env

compiler/rustc_mir/src/transform/const_prop.rs

+9-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::{HasTyCtxt, LayoutError, TyAndLayout};
20+
use rustc_middle::ty::layout::{LayoutError, TyAndLayout};
2121
use rustc_middle::ty::subst::{InternalSubsts, Subst};
2222
use rustc_middle::ty::{
2323
self, ConstInt, ConstKind, Instance, ParamEnv, ScalarInt, Ty, TyCtxt, TypeFoldable,
@@ -346,13 +346,20 @@ impl<'mir, 'tcx> HasDataLayout for ConstPropagator<'mir, 'tcx> {
346346
}
347347
}
348348

349-
impl<'mir, 'tcx> HasTyCtxt<'tcx> for ConstPropagator<'mir, 'tcx> {
349+
impl<'mir, 'tcx> ty::layout::HasTyCtxt<'tcx> for ConstPropagator<'mir, 'tcx> {
350350
#[inline]
351351
fn tcx(&self) -> TyCtxt<'tcx> {
352352
self.tcx
353353
}
354354
}
355355

356+
impl<'mir, 'tcx> ty::layout::HasParamEnv<'tcx> for ConstPropagator<'mir, 'tcx> {
357+
#[inline]
358+
fn param_env(&self) -> ty::ParamEnv<'tcx> {
359+
self.param_env
360+
}
361+
}
362+
356363
impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
357364
fn new(
358365
body: &Body<'tcx>,

compiler/rustc_target/src/abi/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1174,8 +1174,8 @@ impl<'a, Ty> Deref for TyAndLayout<'a, Ty> {
11741174
}
11751175

11761176
/// Trait for context types that can compute layouts of things.
1177-
pub trait LayoutOf<'a> {
1178-
type Ty;
1177+
pub trait LayoutOf<'a>: Sized {
1178+
type Ty: TyAbiInterface<'a, Self>;
11791179
type TyAndLayout: MaybeResult<TyAndLayout<'a, Self::Ty>>;
11801180

11811181
fn layout_of(&self, ty: Self::Ty) -> Self::TyAndLayout;

0 commit comments

Comments
 (0)