1
Fork 0

rustc_target: move LayoutOf to ty::layout.

This commit is contained in:
Eduard-Mihai Burtescu 2021-08-30 17:38:27 +03:00
parent 50171c310c
commit 4ce933f13f
51 changed files with 148 additions and 170 deletions

View file

@ -13,7 +13,6 @@ use std::str::FromStr;
use rustc_index::vec::{Idx, IndexVec};
use rustc_macros::HashStable_Generic;
use rustc_serialize::json::{Json, ToJson};
use rustc_span::Span;
pub mod call;
@ -1173,46 +1172,6 @@ impl<'a, Ty> Deref for TyAndLayout<'a, Ty> {
}
}
/// Trait for context types that can compute layouts of things.
pub trait LayoutOf<'a>: Sized {
type Ty: TyAbiInterface<'a, Self>;
type TyAndLayout: MaybeResult<TyAndLayout<'a, Self::Ty>>;
fn layout_of(&self, ty: Self::Ty) -> Self::TyAndLayout;
fn spanned_layout_of(&self, ty: Self::Ty, _span: Span) -> Self::TyAndLayout {
self.layout_of(ty)
}
}
pub trait MaybeResult<T> {
type Error;
fn from(x: Result<T, Self::Error>) -> Self;
fn to_result(self) -> Result<T, Self::Error>;
}
impl<T> MaybeResult<T> for T {
type Error = !;
fn from(Ok(x): Result<T, Self::Error>) -> Self {
x
}
fn to_result(self) -> Result<T, Self::Error> {
Ok(self)
}
}
impl<T, E> MaybeResult<T> for Result<T, E> {
type Error = E;
fn from(x: Result<T, Self::Error>) -> Self {
x
}
fn to_result(self) -> Result<T, Self::Error> {
self
}
}
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
pub enum PointerKind {
/// Most general case, we know no restrictions to tell LLVM.