1
Fork 0

ty::layout: propagate errors up to (but not out of) FnAbi::of_*.

This commit is contained in:
Eduard-Mihai Burtescu 2021-08-26 19:01:55 +03:00
parent 4d36faf9ef
commit 7f2f927eb8
2 changed files with 129 additions and 27 deletions

View file

@ -1,6 +1,7 @@
use crate::abi::{self, Abi, Align, FieldsShape, Size};
use crate::abi::{HasDataLayout, TyAbiInterface, TyAndLayout};
use crate::spec::{self, HasTargetSpec};
use std::fmt;
mod aarch64;
mod amdgpu;
@ -599,8 +600,28 @@ pub struct FnAbi<'a, Ty> {
pub can_unwind: bool,
}
/// Error produced by attempting to adjust a `FnAbi`, for a "foreign" ABI.
pub enum AdjustForForeignAbiError {
/// Target architecture doesn't support "foreign" (i.e. non-Rust) ABIs.
Unsupported { arch: String, abi: spec::abi::Abi },
}
impl fmt::Display for AdjustForForeignAbiError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Unsupported { arch, abi } => {
write!(f, "target architecture {:?} does not support `extern {}` ABI", arch, abi)
}
}
}
}
impl<'a, Ty> FnAbi<'a, Ty> {
pub fn adjust_for_foreign_abi<C>(&mut self, cx: &C, abi: spec::abi::Abi) -> Result<(), String>
pub fn adjust_for_foreign_abi<C>(
&mut self,
cx: &C,
abi: spec::abi::Abi,
) -> Result<(), AdjustForForeignAbiError>
where
Ty: TyAbiInterface<'a, C> + Copy,
C: HasDataLayout + HasTargetSpec,
@ -655,7 +676,9 @@ impl<'a, Ty> FnAbi<'a, Ty> {
}
"asmjs" => wasm::compute_c_abi_info(cx, self),
"bpf" => bpf::compute_abi_info(self),
a => return Err(format!("unrecognized arch \"{}\" in target specification", a)),
arch => {
return Err(AdjustForForeignAbiError::Unsupported { arch: arch.to_string(), abi });
}
}
Ok(())