Skip to content

Commit 4bae2a3

Browse files
committed
xtask: check-raw: allow #[allow(non_camel_case_types)]
`cargo xtask check-raw` is very strict to prevent higher-level or sophisticated types in `uefi-raw`. Here, however, I think, it is perfectly fine to allow this. One example is `SerialIoProtocol_1_1`, which follows in the next commit.
1 parent ca751ff commit 4bae2a3

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

xtask/src/check_raw.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ impl From<&Item> for ItemKind {
4343
#[derive(Debug, Eq, PartialEq)]
4444
enum ErrorKind {
4545
ForbiddenAbi,
46+
ForbiddenAllow,
4647
ForbiddenAttr,
4748
ForbiddenItemKind(ItemKind),
4849
ForbiddenRepr(Vec<Repr>),
@@ -60,6 +61,7 @@ impl Display for ErrorKind {
6061
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
6162
match self {
6263
Self::ForbiddenAbi => write!(f, "forbidden ABI"),
64+
Self::ForbiddenAllow => write!(f, "forbidden allow"),
6365
Self::ForbiddenAttr => write!(f, "forbidden attribute"),
6466
Self::ForbiddenItemKind(ItemKind::Enum) => write!(
6567
f,
@@ -140,6 +142,12 @@ fn is_pub(vis: &Visibility) -> bool {
140142
matches!(vis, Visibility::Public(_))
141143
}
142144

145+
/// Allowed `#[allow]` attributes.
146+
#[derive(Debug, Clone, Copy)]
147+
enum Allow {
148+
NonCamelCaseTypes,
149+
}
150+
143151
/// Type repr. A type may have more than one of these (e.g. both `C` and `packed`).
144152
#[derive(Debug, Clone, Copy, Eq, PartialEq, Ord, PartialOrd)]
145153
enum Repr {
@@ -154,6 +162,7 @@ enum Repr {
154162
/// expected in `uefi-raw`.
155163
#[derive(Debug, Clone, Copy)]
156164
enum ParsedAttr {
165+
Allow(Allow),
157166
Derive,
158167
Doc,
159168
Repr(Repr),
@@ -195,6 +204,20 @@ fn parse_attrs(attrs: &[Attribute], src: &Path) -> Result<Vec<ParsedAttr>, Error
195204
if unknown_repr_found {
196205
return Err(Error::new(ErrorKind::UnknownRepr, src, attr));
197206
}
207+
} else if path.is_ident("allow") {
208+
let mut unknown_allow_found = false;
209+
attr.parse_nested_meta(|meta| {
210+
if meta.path.is_ident("non_camel_case_types") {
211+
va.push(ParsedAttr::Allow(Allow::NonCamelCaseTypes));
212+
} else {
213+
unknown_allow_found = true;
214+
}
215+
Ok(())
216+
})
217+
.map_err(|_| Error::new(ErrorKind::MalformedAttrs, src, attr))?;
218+
if unknown_allow_found {
219+
return Err(Error::new(ErrorKind::ForbiddenAllow, src, attr));
220+
}
198221
} else {
199222
return Err(Error::new(ErrorKind::ForbiddenAttr, src, attr));
200223
}

0 commit comments

Comments
 (0)