@@ -862,6 +862,18 @@ pub fn find_repr_attrs(sess: &Session, attr: &Attribute) -> Vec<ReprAttr> {
862
862
if let Some ( items) = attr. meta_item_list ( ) {
863
863
sess. mark_attr_used ( attr) ;
864
864
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
+
865
877
let mut recognised = false ;
866
878
if item. is_word ( ) {
867
879
let hint = match item. name_or_empty ( ) {
@@ -878,6 +890,23 @@ pub fn find_repr_attrs(sess: &Session, attr: &Attribute) -> Vec<ReprAttr> {
878
890
acc. push ( h) ;
879
891
}
880
892
} 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
+
881
910
let mut literal_error = None ;
882
911
if name == sym:: align {
883
912
recognised = true ;
@@ -937,7 +966,13 @@ pub fn find_repr_attrs(sess: &Session, attr: &Attribute) -> Vec<ReprAttr> {
937
966
}
938
967
if !recognised {
939
968
// 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 ( ) ;
941
976
}
942
977
}
943
978
}
@@ -1045,16 +1080,3 @@ fn allow_unstable<'a>(
1045
1080
name
1046
1081
} )
1047
1082
}
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