Skip to content

Commit 540fcc6

Browse files
committed
Move some supertraits outward.
Specifically, put them where they are genuinely required, i.e. the outermost place they can be.
1 parent 85a4d2a commit 540fcc6

File tree

3 files changed

+19
-11
lines changed

3 files changed

+19
-11
lines changed

compiler/rustc_codegen_ssa/src/mir/operand.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ impl<'a, 'tcx, V: CodegenObject> OperandRef<'tcx, V> {
280280
///
281281
/// If you don't need the type, see [`OperandValue::pointer_parts`]
282282
/// or [`OperandValue::deref`].
283-
pub fn deref<Cx: LayoutTypeMethods<'tcx>>(self, cx: &Cx) -> PlaceRef<'tcx, V> {
283+
pub fn deref<Cx: CodegenMethods<'tcx>>(self, cx: &Cx) -> PlaceRef<'tcx, V> {
284284
if self.layout.ty.is_box() {
285285
// Derefer should have removed all Box derefs
286286
bug!("dereferencing {:?} in codegen", self.layout.ty);

compiler/rustc_codegen_ssa/src/traits/mod.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ mod write;
2727

2828
use std::fmt;
2929

30+
use rustc_middle::ty::layout::FnAbiOf;
31+
use rustc_middle::ty::Ty;
32+
use rustc_target::abi::call::FnAbi;
33+
use rustc_middle::ty::layout::{LayoutOf, TyAndLayout};
34+
3035
pub use self::abi::AbiBuilderMethods;
3136
pub use self::asm::{AsmBuilderMethods, AsmMethods, GlobalAsmOperandRef, InlineAsmOperandRef};
3237
pub use self::backend::{BackendTypes, CodegenBackend, ExtraBackendMethods};
@@ -46,7 +51,9 @@ pub use self::write::{ModuleBufferMethods, ThinBufferMethods, WriteBackendMethod
4651

4752
pub trait CodegenObject = Copy + PartialEq + fmt::Debug;
4853

49-
pub trait CodegenMethods<'tcx> = TypeMethods<'tcx>
54+
pub trait CodegenMethods<'tcx> = LayoutOf<'tcx, LayoutOfResult = TyAndLayout<'tcx>>
55+
+ FnAbiOf<'tcx, FnAbiOfResult = &'tcx FnAbi<'tcx, Ty<'tcx>>>
56+
+ TypeMethods<'tcx>
5057
+ ConstMethods<'tcx>
5158
+ StaticMethods
5259
+ DebugInfoMethods<'tcx>

compiler/rustc_codegen_ssa/src/traits/type_.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use rustc_middle::bug;
2-
use rustc_middle::ty::layout::{FnAbiOf, HasTyCtxt, LayoutOf, TyAndLayout};
2+
use rustc_middle::ty::layout::{HasTyCtxt, TyAndLayout};
33
use rustc_middle::ty::{self, Ty};
44
use rustc_target::abi::call::{ArgAbi, CastTarget, FnAbi, Reg};
55
use rustc_target::abi::{AddressSpace, Float, Integer};
@@ -9,7 +9,7 @@ use super::BackendTypes;
99
use crate::common::TypeKind;
1010
use crate::mir::place::PlaceRef;
1111

12-
pub trait BaseTypeMethods<'tcx>: BackendTypes + HasTyCtxt<'tcx> {
12+
pub trait BaseTypeMethods<'tcx>: BackendTypes {
1313
fn type_i8(&self) -> Self::Type;
1414
fn type_i16(&self) -> Self::Type;
1515
fn type_i32(&self) -> Self::Type;
@@ -40,7 +40,9 @@ pub trait BaseTypeMethods<'tcx>: BackendTypes + HasTyCtxt<'tcx> {
4040
fn val_ty(&self, v: Self::Value) -> Self::Type;
4141
}
4242

43-
pub trait DerivedTypeMethods<'tcx>: BaseTypeMethods<'tcx> + MiscMethods<'tcx> {
43+
pub trait DerivedTypeMethods<'tcx>:
44+
BaseTypeMethods<'tcx> + MiscMethods<'tcx> + HasTyCtxt<'tcx>
45+
{
4446
fn type_int(&self) -> Self::Type {
4547
match &self.sess().target.c_int_width[..] {
4648
"16" => self.type_i16(),
@@ -98,13 +100,12 @@ pub trait DerivedTypeMethods<'tcx>: BaseTypeMethods<'tcx> + MiscMethods<'tcx> {
98100
}
99101
}
100102

101-
impl<'tcx, T> DerivedTypeMethods<'tcx> for T where Self: BaseTypeMethods<'tcx> + MiscMethods<'tcx> {}
102-
103-
pub trait LayoutTypeMethods<'tcx>:
104-
BackendTypes
105-
+ LayoutOf<'tcx, LayoutOfResult = TyAndLayout<'tcx>>
106-
+ FnAbiOf<'tcx, FnAbiOfResult = &'tcx FnAbi<'tcx, Ty<'tcx>>>
103+
impl<'tcx, T> DerivedTypeMethods<'tcx> for T where
104+
Self: BaseTypeMethods<'tcx> + MiscMethods<'tcx> + HasTyCtxt<'tcx>
107105
{
106+
}
107+
108+
pub trait LayoutTypeMethods<'tcx>: BackendTypes {
108109
/// The backend type used for a rust type when it's in memory,
109110
/// such as when it's stack-allocated or when it's being loaded or stored.
110111
fn backend_type(&self, layout: TyAndLayout<'tcx>) -> Self::Type;

0 commit comments

Comments
 (0)