@@ -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
5858impl 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