From 299f1d79e0c5a1cc6d46ff7e3c9a9c8ac4884f2c Mon Sep 17 00:00:00 2001 From: Nicholas Bishop Date: Fri, 24 Oct 2025 15:03:54 -0400 Subject: [PATCH] xtask: Check uefi-raw for uses of the primitive bool type --- xtask/src/check_raw.rs | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/xtask/src/check_raw.rs b/xtask/src/check_raw.rs index b3301a54c..17964f710 100644 --- a/xtask/src/check_raw.rs +++ b/xtask/src/check_raw.rs @@ -51,6 +51,7 @@ enum ErrorKind { MissingPub, MissingRepr, MissingUnsafe, + PrimitiveBool, UnderscoreField, UnknownRepr, } @@ -85,6 +86,7 @@ impl Display for ErrorKind { Self::MissingPub => write!(f, "missing pub"), Self::MissingRepr => write!(f, "missing repr"), Self::MissingUnsafe => write!(f, "missing unsafe"), + Self::PrimitiveBool => write!(f, "use `Boolean` instead of `bool`"), Self::UnderscoreField => write!(f, "field name starts with `_`"), Self::UnknownRepr => write!(f, "unknown repr"), } @@ -234,10 +236,17 @@ fn check_type(ty: &Type, src: &Path) -> Result<(), Error> { match ty { Type::Array(TypeArray { elem, .. }) => check_type(elem, src), Type::BareFn(f) => check_fn_ptr(f, src), - Type::Never(_) | Type::Path(_) => { + Type::Never(_) => { // Allow. Ok(()) } + Type::Path(type_path) => { + if type_path.path.is_ident("bool") { + Err(Error::new(ErrorKind::PrimitiveBool, src, ty)) + } else { + Ok(()) + } + } Type::Ptr(TypePtr { elem, .. }) => check_type(elem, src), ty => Err(Error::new(ErrorKind::ForbiddenType, src, ty)), } @@ -650,6 +659,17 @@ mod tests { }, ErrorKind::ForbiddenType, ); + + // Forbidden field type: primitive bool. + check_item_err( + parse_quote! { + #[repr(C)] + pub struct S { + pub f: bool, + } + }, + ErrorKind::PrimitiveBool, + ); } #[test]