Put LayoutError behind reference to shrink result

`LayoutError` is 24 bytes, which is bigger than the `Ok` types, so let's
shrink that.
This commit is contained in:
Nilstrieb 2023-04-30 23:05:27 +02:00
parent 6162f6f123
commit 3019c1cb2a
13 changed files with 89 additions and 56 deletions

View file

@ -192,8 +192,8 @@ pub(crate) mod rustc {
TypeError(ErrorGuaranteed),
}
impl<'tcx> From<LayoutError<'tcx>> for Err {
fn from(err: LayoutError<'tcx>) -> Self {
impl<'tcx> From<&LayoutError<'tcx>> for Err {
fn from(err: &LayoutError<'tcx>) -> Self {
match err {
LayoutError::Unknown(..) => Self::UnknownLayout,
err => unimplemented!("{:?}", err),
@ -221,7 +221,7 @@ pub(crate) mod rustc {
}
impl LayoutSummary {
fn from_ty<'tcx>(ty: Ty<'tcx>, ctx: TyCtxt<'tcx>) -> Result<Self, LayoutError<'tcx>> {
fn from_ty<'tcx>(ty: Ty<'tcx>, ctx: TyCtxt<'tcx>) -> Result<Self, &'tcx LayoutError<'tcx>> {
use rustc_middle::ty::ParamEnvAnd;
use rustc_target::abi::{TyAndLayout, Variants};
@ -482,7 +482,7 @@ pub(crate) mod rustc {
fn layout_of<'tcx>(
ctx: TyCtxt<'tcx>,
ty: Ty<'tcx>,
) -> Result<alloc::Layout, LayoutError<'tcx>> {
) -> Result<alloc::Layout, &'tcx LayoutError<'tcx>> {
use rustc_middle::ty::ParamEnvAnd;
use rustc_target::abi::TyAndLayout;