Files
sousa-gecko/third_party/rust/bindgen/codegen/error.rs
T
Emilio Cobos Álvarez b50f83948d Bug 1985509 - Update bindgen to fix overaligned types on x86. r=nika,supply-chain-reviewers,profiler-reviewers,canaltinova
Bindgen historically represented 8-byte aligned types with u64. That's
borked in x86 where u64 is 4-byte aligned.

I fixed this in upstream bindgen
(https://github.com/rust-lang/rust-bindgen/pull/3280), so update it.

There are a few changes needed:

 * https://github.com/mozilla/neqo/pull/2913 to deal with the now
   properly aligned type.

 * Similar change (less fun because transmute, but still sound) in the
   macos crash reporter. I could try to generate a bit easier to use
   bindings for 8-byte 8-byte-aligned blobs, but this would do.

 * Some opaque additions in layout/style/ServoBindings.toml and the
   profiler bindings. This is unrelated to the opaque change, but
   fallout from other bindgen improvements. In particular, layout tests
   now run at compile time, so this uncovered some layout mismatches on
   platforms where we don't run rusttests on CI.

Differential Revision: https://phabricator.services.mozilla.com/D262840
2025-08-28 21:18:57 +00:00

53 lines
1.7 KiB
Rust

use std::error;
use std::fmt;
/// Errors that can occur during code generation.
#[derive(Clone, Debug, PartialEq, Eq)]
pub(crate) enum Error {
/// Tried to generate an opaque blob for a type that did not have a layout.
NoLayoutForOpaqueBlob,
/// Tried to instantiate an opaque template definition, or a template
/// definition that is too difficult for us to understand (like a partial
/// template specialization).
InstantiationOfOpaqueType,
/// Function ABI is not supported.
UnsupportedAbi(&'static str),
/// The pointer type size does not match the target's pointer size.
InvalidPointerSize {
ty_name: String,
ty_size: usize,
ptr_size: usize,
},
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
Error::NoLayoutForOpaqueBlob => {
"Tried to generate an opaque blob, but had no layout.".fmt(f)
}
Error::InstantiationOfOpaqueType => {
"Instantiation of opaque template type or partial template specialization."
.fmt(f)
}
Error::UnsupportedAbi(abi) => {
write!(
f,
"{abi} ABI is not supported by the configured Rust target."
)
}
Error::InvalidPointerSize { ty_name, ty_size, ptr_size } => {
write!(f, "The {ty_name} pointer type has size {ty_size} but the current target's pointer size is {ptr_size}.")
}
}
}
}
impl error::Error for Error {}
/// A `Result` of `T` or an error of `bindgen::codegen::error::Error`.
pub(crate) type Result<T> = ::std::result::Result<T, Error>;