Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 62d5a47

Browse filesBrowse files
committed
xtask: improved error output for "wrong" repr
1 parent d23e994 commit 62d5a47
Copy full SHA for 62d5a47

File tree

Expand file treeCollapse file tree

1 file changed

+23
-22
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+23
-22
lines changed

‎xtask/src/check_raw.rs

Copy file name to clipboardExpand all lines: xtask/src/check_raw.rs
+23-22Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ enum ErrorKind {
4545
ForbiddenAbi,
4646
ForbiddenAttr,
4747
ForbiddenItemKind(ItemKind),
48-
ForbiddenRepr,
48+
ForbiddenRepr(Vec<Repr>),
4949
ForbiddenType,
5050
MalformedAttrs,
5151
MissingPub,
@@ -57,25 +57,26 @@ enum ErrorKind {
5757

5858
impl Display for ErrorKind {
5959
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
60-
write!(
61-
f,
62-
"{}",
63-
match self {
64-
Self::ForbiddenAbi => "forbidden ABI",
65-
Self::ForbiddenAttr => "forbidden attribute",
66-
Self::ForbiddenItemKind(ItemKind::Enum) =>
67-
"forbidden use of enum; use the `newtype_enum!` macro instead",
68-
Self::ForbiddenItemKind(_) => "forbidden type of item",
69-
Self::ForbiddenRepr => "forbidden repr",
70-
Self::ForbiddenType => "forbidden type",
71-
Self::MalformedAttrs => "malformed attribute contents",
72-
Self::MissingPub => "missing pub",
73-
Self::MissingRepr => "missing repr",
74-
Self::MissingUnsafe => "missing unsafe",
75-
Self::UnderscoreField => "field name starts with `_`",
76-
Self::UnknownRepr => "unknown repr",
77-
}
78-
)
60+
match self {
61+
Self::ForbiddenAbi => write!(f, "forbidden ABI"),
62+
Self::ForbiddenAttr => write!(f, "forbidden attribute"),
63+
Self::ForbiddenItemKind(ItemKind::Enum) => write!(
64+
f,
65+
"forbidden use of enum; use the `newtype_enum!` macro instead"
66+
),
67+
Self::ForbiddenItemKind(_) => write!(f, "forbidden type of item"),
68+
Self::ForbiddenRepr(reprs) => write!(
69+
f,
70+
"at least one of the following repr is forbidden: {reprs:?}"
71+
),
72+
Self::ForbiddenType => write!(f, "forbidden type"),
73+
Self::MalformedAttrs => write!(f, "malformed attribute contents"),
74+
Self::MissingPub => write!(f, "missing pub"),
75+
Self::MissingRepr => write!(f, "missing repr"),
76+
Self::MissingUnsafe => write!(f, "missing unsafe"),
77+
Self::UnderscoreField => write!(f, "field name starts with `_`"),
78+
Self::UnknownRepr => write!(f, "unknown repr"),
79+
}
7980
}
8081
}
8182

@@ -290,7 +291,7 @@ fn check_type_attrs(attrs: &[Attribute], spanned: &dyn Spanned, src: &Path) -> R
290291
} else if ALLOWED_REPRS.contains(&reprs.as_slice()) {
291292
Ok(())
292293
} else {
293-
Err(Error::new(ErrorKind::ForbiddenRepr, src, spanned))
294+
Err(Error::new(ErrorKind::ForbiddenRepr(reprs), src, spanned))
294295
}
295296
}
296297

@@ -347,7 +348,7 @@ fn check_macro(item: &ItemMacro, src: &Path) -> Result<(), Error> {
347348
let reprs = get_reprs(&attrs);
348349
let allowed_reprs: &[&[Repr]] = &[&[Repr::Transparent]];
349350
if !allowed_reprs.contains(&reprs.as_slice()) {
350-
return Err(Error::new(ErrorKind::ForbiddenRepr, src, mac));
351+
return Err(Error::new(ErrorKind::ForbiddenRepr(reprs), src, mac));
351352
}
352353
}
353354

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.