@@ -862,6 +862,18 @@ pub fn find_repr_attrs(sess: &Session, attr: &Attribute) -> Vec<ReprAttr> {
862862 if let Some ( items) = attr. meta_item_list ( ) {
863863 sess. mark_attr_used ( attr) ;
864864 for item in items {
865+ if !item. is_meta_item ( ) {
866+ handle_errors (
867+ & sess. parse_sess ,
868+ item. span ( ) ,
869+ AttrError :: UnsupportedLiteral (
870+ "meta item in `repr` must be an identifier" ,
871+ false ,
872+ ) ,
873+ ) ;
874+ continue ;
875+ }
876+
865877 let mut recognised = false ;
866878 if item. is_word ( ) {
867879 let hint = match item. name_or_empty ( ) {
@@ -878,6 +890,23 @@ pub fn find_repr_attrs(sess: &Session, attr: &Attribute) -> Vec<ReprAttr> {
878890 acc. push ( h) ;
879891 }
880892 } else if let Some ( ( name, value) ) = item. name_value_literal ( ) {
893+ let parse_alignment = |node : & ast:: LitKind | -> Result < u32 , & ' static str > {
894+ if let ast:: LitKind :: Int ( literal, ast:: LitIntType :: Unsuffixed ) = node {
895+ if literal. is_power_of_two ( ) {
896+ // rustc_middle::ty::layout::Align restricts align to <= 2^29
897+ if * literal <= 1 << 29 {
898+ Ok ( * literal as u32 )
899+ } else {
900+ Err ( "larger than 2^29" )
901+ }
902+ } else {
903+ Err ( "not a power of two" )
904+ }
905+ } else {
906+ Err ( "not an unsuffixed integer" )
907+ }
908+ } ;
909+
881910 let mut literal_error = None ;
882911 if name == sym:: align {
883912 recognised = true ;
@@ -937,7 +966,13 @@ pub fn find_repr_attrs(sess: &Session, attr: &Attribute) -> Vec<ReprAttr> {
937966 }
938967 if !recognised {
939968 // Not a word we recognize
940- diagnostic. delay_span_bug ( item. span ( ) , "unrecognized representation hint" ) ;
969+ struct_span_err ! (
970+ diagnostic,
971+ item. span( ) ,
972+ E0552 ,
973+ "unrecognized representation hint"
974+ )
975+ . emit ( ) ;
941976 }
942977 }
943978 }
@@ -1045,16 +1080,3 @@ fn allow_unstable<'a>(
10451080 name
10461081 } )
10471082}
1048-
1049- pub fn parse_alignment ( node : & ast:: LitKind ) -> Result < u32 , & ' static str > {
1050- if let ast:: LitKind :: Int ( literal, ast:: LitIntType :: Unsuffixed ) = node {
1051- if literal. is_power_of_two ( ) {
1052- // rustc_middle::ty::layout::Align restricts align to <= 2^29
1053- if * literal <= 1 << 29 { Ok ( * literal as u32 ) } else { Err ( "larger than 2^29" ) }
1054- } else {
1055- Err ( "not a power of two" )
1056- }
1057- } else {
1058- Err ( "not an unsuffixed integer" )
1059- }
1060- }
0 commit comments