@@ -26,7 +26,7 @@ use crate::attributes::stability::{
26
26
use crate :: attributes:: transparency:: TransparencyParser ;
27
27
use crate :: attributes:: { AttributeParser as _, Combine , Single } ;
28
28
use crate :: parser:: { ArgParser , MetaItemParser } ;
29
- use crate :: session_diagnostics:: { AttributeParseError , AttributeParseErrorReason } ;
29
+ use crate :: session_diagnostics:: { AttributeParseError , AttributeParseErrorReason , UnknownMetaItem } ;
30
30
31
31
macro_rules! group_type {
32
32
( $stage: ty) => {
@@ -189,8 +189,16 @@ impl<'f, 'sess: 'f, S: Stage> AcceptContext<'f, 'sess, S> {
189
189
( self . emit_lint ) ( AttributeLint { id, span, kind : lint } ) ;
190
190
}
191
191
192
+ pub ( crate ) fn unknown_key (
193
+ & self ,
194
+ span : Span ,
195
+ found : String ,
196
+ options : & ' static [ & ' static str ] ,
197
+ ) -> ErrorGuaranteed {
198
+ self . emit_err ( UnknownMetaItem { span, item : found, expected : options } )
199
+ }
200
+
192
201
pub ( crate ) fn expected_string_literal ( & self , span : Span ) -> ErrorGuaranteed {
193
- // 539?
194
202
self . emit_err ( AttributeParseError {
195
203
span,
196
204
attr_span : self . attr_span ,
@@ -200,12 +208,40 @@ impl<'f, 'sess: 'f, S: Stage> AcceptContext<'f, 'sess, S> {
200
208
} )
201
209
}
202
210
203
- // pub(crate) fn expected_any_arguments(&self, span: Span) -> ErrorGuaranteed {
204
- //
205
- // }
211
+ pub ( crate ) fn expected_list ( & self , span : Span ) -> ErrorGuaranteed {
212
+ self . emit_err ( AttributeParseError {
213
+ span,
214
+ attr_span : self . attr_span ,
215
+ template : self . template . clone ( ) ,
216
+ attribute : self . attr_path . clone ( ) ,
217
+ reason : AttributeParseErrorReason :: ExpectedList ,
218
+ } )
219
+ }
220
+
221
+ /// emit an error that a `name = value` pair was expected at this span. The symbol can be given for
222
+ /// a nicer error message talking about the specific name that was found lacking a value.
223
+ pub ( crate ) fn expected_name_value ( & self , span : Span , name : Option < Symbol > ) -> ErrorGuaranteed {
224
+ self . emit_err ( AttributeParseError {
225
+ span,
226
+ attr_span : self . attr_span ,
227
+ template : self . template . clone ( ) ,
228
+ attribute : self . attr_path . clone ( ) ,
229
+ reason : AttributeParseErrorReason :: ExpectedNameValue ( name) ,
230
+ } )
231
+ }
232
+
233
+ /// emit an error that a `name = value` pair was found where that name was already seen.
234
+ pub ( crate ) fn duplicate_key ( & self , span : Span , key : Symbol ) -> ErrorGuaranteed {
235
+ self . emit_err ( AttributeParseError {
236
+ span,
237
+ attr_span : self . attr_span ,
238
+ template : self . template . clone ( ) ,
239
+ attribute : self . attr_path . clone ( ) ,
240
+ reason : AttributeParseErrorReason :: DuplicateKey ( key) ,
241
+ } )
242
+ }
206
243
207
244
pub ( crate ) fn expected_single_argument ( & self , span : Span ) -> ErrorGuaranteed {
208
- // E534?
209
245
self . emit_err ( AttributeParseError {
210
246
span,
211
247
attr_span : self . attr_span ,
@@ -218,15 +254,34 @@ impl<'f, 'sess: 'f, S: Stage> AcceptContext<'f, 'sess, S> {
218
254
pub ( crate ) fn expected_specific_argument (
219
255
& self ,
220
256
span : Span ,
221
- options : Vec < & ' static str > ,
257
+ possibilities : Vec < & ' static str > ,
258
+ ) -> ErrorGuaranteed {
259
+ self . emit_err ( AttributeParseError {
260
+ span,
261
+ attr_span : self . attr_span ,
262
+ template : self . template . clone ( ) ,
263
+ attribute : self . attr_path . clone ( ) ,
264
+ reason : AttributeParseErrorReason :: ExpectedSpecificArgument {
265
+ possibilities,
266
+ strings : false ,
267
+ } ,
268
+ } )
269
+ }
270
+
271
+ pub ( crate ) fn expected_specific_argument_strings (
272
+ & self ,
273
+ span : Span ,
274
+ possibilities : Vec < & ' static str > ,
222
275
) -> ErrorGuaranteed {
223
- // E535?
224
276
self . emit_err ( AttributeParseError {
225
277
span,
226
278
attr_span : self . attr_span ,
227
279
template : self . template . clone ( ) ,
228
280
attribute : self . attr_path . clone ( ) ,
229
- reason : AttributeParseErrorReason :: ExpectedSpecificArgument ( options) ,
281
+ reason : AttributeParseErrorReason :: ExpectedSpecificArgument {
282
+ possibilities,
283
+ strings : true ,
284
+ } ,
230
285
} )
231
286
}
232
287
}
0 commit comments