@@ -96,9 +96,12 @@ fn parse_repr(cx: &AcceptContext<'_>, param: &MetaItemParser<'_>) -> Option<Repr
96
96
97
97
// FIXME(jdonszelmann): invert the parsing here to match on the word first and then the
98
98
// structure.
99
- let ident = param. path_without_args ( ) . word ( ) ;
100
- let ident_span = ident. map_or ( rustc_span:: DUMMY_SP , |ident| ident. span ) ;
101
- let name = ident. map ( |ident| ident. name ) ;
99
+ let ( name, ident_span) = if let Some ( ident) = param. path_without_args ( ) . word ( ) {
100
+ ( Some ( ident. name ) , ident. span )
101
+ } else {
102
+ ( None , rustc_span:: DUMMY_SP )
103
+ } ;
104
+
102
105
let args = param. args ( ) ;
103
106
104
107
match ( name, args) {
@@ -115,15 +118,15 @@ fn parse_repr(cx: &AcceptContext<'_>, param: &MetaItemParser<'_>) -> Option<Repr
115
118
parse_repr_align ( cx, l, param. span ( ) , AlignKind :: Packed )
116
119
}
117
120
118
- ( Some ( sym:: align | sym:: packed) , ArgParser :: NameValue ( l) ) => {
121
+ ( Some ( name @ sym:: align | name @ sym:: packed) , ArgParser :: NameValue ( l) ) => {
119
122
cx. emit_err ( session_diagnostics:: IncorrectReprFormatGeneric {
120
123
span : param. span ( ) ,
121
124
// FIXME(jdonszelmann) can just be a string in the diag type
122
- repr_arg : & ident . unwrap ( ) . to_string ( ) ,
125
+ repr_arg : name ,
123
126
cause : IncorrectReprFormatGenericCause :: from_lit_kind (
124
127
param. span ( ) ,
125
128
& l. value_as_lit ( ) . kind ,
126
- ident . unwrap ( ) . as_str ( ) ,
129
+ name ,
127
130
) ,
128
131
} ) ;
129
132
None
@@ -133,29 +136,35 @@ fn parse_repr(cx: &AcceptContext<'_>, param: &MetaItemParser<'_>) -> Option<Repr
133
136
( Some ( sym:: C ) , ArgParser :: NoArgs ) => Some ( ReprC ) ,
134
137
( Some ( sym:: simd) , ArgParser :: NoArgs ) => Some ( ReprSimd ) ,
135
138
( Some ( sym:: transparent) , ArgParser :: NoArgs ) => Some ( ReprTransparent ) ,
136
- ( Some ( i @ int_pat ! ( ) ) , ArgParser :: NoArgs ) => {
139
+ ( Some ( name @ int_pat ! ( ) ) , ArgParser :: NoArgs ) => {
137
140
// int_pat!() should make sure it always parses
138
- Some ( ReprInt ( int_type_of_word ( i ) . unwrap ( ) ) )
141
+ Some ( ReprInt ( int_type_of_word ( name ) . unwrap ( ) ) )
139
142
}
140
143
141
144
(
142
- Some ( sym:: Rust | sym:: C | sym:: simd | sym:: transparent | int_pat ! ( ) ) ,
145
+ Some (
146
+ name @ sym:: Rust
147
+ | name @ sym:: C
148
+ | name @ sym:: simd
149
+ | name @ sym:: transparent
150
+ | name @ int_pat ! ( ) ,
151
+ ) ,
143
152
ArgParser :: NameValue ( _) ,
144
153
) => {
145
- cx. emit_err ( session_diagnostics:: InvalidReprHintNoValue {
146
- span : param. span ( ) ,
147
- name : ident. unwrap ( ) . to_string ( ) ,
148
- } ) ;
154
+ cx. emit_err ( session_diagnostics:: InvalidReprHintNoValue { span : param. span ( ) , name } ) ;
149
155
None
150
156
}
151
157
(
152
- Some ( sym:: Rust | sym:: C | sym:: simd | sym:: transparent | int_pat ! ( ) ) ,
158
+ Some (
159
+ name @ sym:: Rust
160
+ | name @ sym:: C
161
+ | name @ sym:: simd
162
+ | name @ sym:: transparent
163
+ | name @ int_pat ! ( ) ,
164
+ ) ,
153
165
ArgParser :: List ( _) ,
154
166
) => {
155
- cx. emit_err ( session_diagnostics:: InvalidReprHintNoParen {
156
- span : param. span ( ) ,
157
- name : ident. unwrap ( ) . to_string ( ) ,
158
- } ) ;
167
+ cx. emit_err ( session_diagnostics:: InvalidReprHintNoParen { span : param. span ( ) , name } ) ;
159
168
None
160
169
}
161
170
0 commit comments