Skip to content

Commit 8651810

Browse files
Merge pull request #1802 from rust-osdev/bishop-check-bool
xtask: Check uefi-raw for uses of the primitive bool type
2 parents 0df1734 + ca63bac commit 8651810

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

xtask/src/check_raw.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ enum ErrorKind {
5151
MissingPub,
5252
MissingRepr,
5353
MissingUnsafe,
54+
PrimitiveBool,
5455
UnderscoreField,
5556
UnknownRepr,
5657
}
@@ -85,6 +86,7 @@ impl Display for ErrorKind {
8586
Self::MissingPub => write!(f, "missing pub"),
8687
Self::MissingRepr => write!(f, "missing repr"),
8788
Self::MissingUnsafe => write!(f, "missing unsafe"),
89+
Self::PrimitiveBool => write!(f, "use `Boolean` instead of `bool`"),
8890
Self::UnderscoreField => write!(f, "field name starts with `_`"),
8991
Self::UnknownRepr => write!(f, "unknown repr"),
9092
}
@@ -234,10 +236,17 @@ fn check_type(ty: &Type, src: &Path) -> Result<(), Error> {
234236
match ty {
235237
Type::Array(TypeArray { elem, .. }) => check_type(elem, src),
236238
Type::BareFn(f) => check_fn_ptr(f, src),
237-
Type::Never(_) | Type::Path(_) => {
239+
Type::Never(_) => {
238240
// Allow.
239241
Ok(())
240242
}
243+
Type::Path(type_path) => {
244+
if type_path.path.is_ident("bool") {
245+
Err(Error::new(ErrorKind::PrimitiveBool, src, ty))
246+
} else {
247+
Ok(())
248+
}
249+
}
241250
Type::Ptr(TypePtr { elem, .. }) => check_type(elem, src),
242251
ty => Err(Error::new(ErrorKind::ForbiddenType, src, ty)),
243252
}
@@ -650,6 +659,17 @@ mod tests {
650659
},
651660
ErrorKind::ForbiddenType,
652661
);
662+
663+
// Forbidden field type: primitive bool.
664+
check_item_err(
665+
parse_quote! {
666+
#[repr(C)]
667+
pub struct S {
668+
pub f: bool,
669+
}
670+
},
671+
ErrorKind::PrimitiveBool,
672+
);
653673
}
654674

655675
#[test]

0 commit comments

Comments
 (0)