Use trait aliases to shorten some code.

This commit is contained in:
Nicholas Nethercote 2024-09-16 14:49:38 +10:00
parent 04a318787b
commit 6daf40e219
4 changed files with 8 additions and 44 deletions

View File

@ -11,6 +11,7 @@
#![feature(negative_impls)] #![feature(negative_impls)]
#![feature(rustdoc_internals)] #![feature(rustdoc_internals)]
#![feature(strict_provenance)] #![feature(strict_provenance)]
#![feature(trait_alias)]
#![feature(try_blocks)] #![feature(try_blocks)]
#![warn(unreachable_pub)] #![warn(unreachable_pub)]
// tidy-alphabetical-end // tidy-alphabetical-end

View File

@ -36,22 +36,11 @@ pub trait BackendTypes {
type DIVariable: Copy; type DIVariable: Copy;
} }
pub trait Backend<'tcx>: pub trait Backend<'tcx> = Sized
Sized
+ BackendTypes + BackendTypes
+ HasTyCtxt<'tcx> + HasTyCtxt<'tcx>
+ LayoutOf<'tcx, LayoutOfResult = TyAndLayout<'tcx>> + LayoutOf<'tcx, LayoutOfResult = TyAndLayout<'tcx>>
+ FnAbiOf<'tcx, FnAbiOfResult = &'tcx FnAbi<'tcx, Ty<'tcx>>> + FnAbiOf<'tcx, FnAbiOfResult = &'tcx FnAbi<'tcx, Ty<'tcx>>>;
{
}
impl<'tcx, T> Backend<'tcx> for T where
Self: BackendTypes
+ HasTyCtxt<'tcx>
+ LayoutOf<'tcx, LayoutOfResult = TyAndLayout<'tcx>>
+ FnAbiOf<'tcx, FnAbiOfResult = &'tcx FnAbi<'tcx, Ty<'tcx>>>
{
}
pub trait CodegenBackend { pub trait CodegenBackend {
/// Locale resources for diagnostic messages - a string the content of the Fluent resource. /// Locale resources for diagnostic messages - a string the content of the Fluent resource.

View File

@ -50,11 +50,9 @@
}; };
pub use self::write::{ModuleBufferMethods, ThinBufferMethods, WriteBackendMethods}; pub use self::write::{ModuleBufferMethods, ThinBufferMethods, WriteBackendMethods};
pub trait CodegenObject: Copy + PartialEq + fmt::Debug {} pub trait CodegenObject = Copy + PartialEq + fmt::Debug;
impl<T: Copy + PartialEq + fmt::Debug> CodegenObject for T {}
pub trait CodegenMethods<'tcx>: pub trait CodegenMethods<'tcx> = Backend<'tcx>
Backend<'tcx>
+ TypeMethods<'tcx> + TypeMethods<'tcx>
+ MiscMethods<'tcx> + MiscMethods<'tcx>
+ ConstMethods<'tcx> + ConstMethods<'tcx>
@ -64,24 +62,7 @@ pub trait CodegenMethods<'tcx>:
+ PreDefineMethods<'tcx> + PreDefineMethods<'tcx>
+ HasParamEnv<'tcx> + HasParamEnv<'tcx>
+ HasTyCtxt<'tcx> + HasTyCtxt<'tcx>
+ HasTargetSpec + HasTargetSpec;
{
}
impl<'tcx, T> CodegenMethods<'tcx> for T where
Self: Backend<'tcx>
+ TypeMethods<'tcx>
+ MiscMethods<'tcx>
+ ConstMethods<'tcx>
+ StaticMethods
+ DebugInfoMethods<'tcx>
+ AsmMethods<'tcx>
+ PreDefineMethods<'tcx>
+ HasParamEnv<'tcx>
+ HasTyCtxt<'tcx>
+ HasTargetSpec
{
}
pub trait HasCodegen<'tcx>: pub trait HasCodegen<'tcx>:
Backend<'tcx> + std::ops::Deref<Target = <Self as HasCodegen<'tcx>>::CodegenCx> Backend<'tcx> + std::ops::Deref<Target = <Self as HasCodegen<'tcx>>::CodegenCx>

View File

@ -172,12 +172,5 @@ fn store_arg(
fn arg_memory_ty(&self, arg_abi: &ArgAbi<'tcx, Ty<'tcx>>) -> Self::Type; fn arg_memory_ty(&self, arg_abi: &ArgAbi<'tcx, Ty<'tcx>>) -> Self::Type;
} }
pub trait TypeMethods<'tcx>: pub trait TypeMethods<'tcx> =
DerivedTypeMethods<'tcx> + LayoutTypeMethods<'tcx> + TypeMembershipMethods<'tcx> DerivedTypeMethods<'tcx> + LayoutTypeMethods<'tcx> + TypeMembershipMethods<'tcx>;
{
}
impl<'tcx, T> TypeMethods<'tcx> for T where
Self: DerivedTypeMethods<'tcx> + LayoutTypeMethods<'tcx> + TypeMembershipMethods<'tcx>
{
}