@@ -27,7 +27,7 @@ use crate::attributes::stability::{
27
27
use crate :: attributes:: transparency:: TransparencyParser ;
28
28
use crate :: attributes:: { AttributeParser as _, Combine , Single } ;
29
29
use crate :: parser:: { ArgParser , MetaItemParser } ;
30
- use crate :: session_diagnostics:: { AttributeParseError , AttributeParseErrorReason } ;
30
+ use crate :: session_diagnostics:: { AttributeParseError , AttributeParseErrorReason , UnknownMetaItem } ;
31
31
32
32
macro_rules! group_type {
33
33
( $stage: ty) => {
@@ -241,8 +241,16 @@ impl<'f, 'sess: 'f, S: Stage> AcceptContext<'f, 'sess, S> {
241
241
S :: emit_lint ( self . dcx ( ) , lint, self . target_id , span, diag)
242
242
}
243
243
244
+ pub ( crate ) fn unknown_key (
245
+ & self ,
246
+ span : Span ,
247
+ found : String ,
248
+ options : & ' static [ & ' static str ] ,
249
+ ) -> ErrorGuaranteed {
250
+ self . emit_err ( UnknownMetaItem { span, item : found, expected : options } )
251
+ }
252
+
244
253
pub ( crate ) fn expected_string_literal ( & self , span : Span ) -> ErrorGuaranteed {
245
- // 539?
246
254
self . emit_err ( AttributeParseError {
247
255
span,
248
256
attr_span : self . attr_span ,
@@ -252,12 +260,40 @@ impl<'f, 'sess: 'f, S: Stage> AcceptContext<'f, 'sess, S> {
252
260
} )
253
261
}
254
262
255
- // pub(crate) fn expected_any_arguments(&self, span: Span) -> ErrorGuaranteed {
256
- //
257
- // }
263
+ pub ( crate ) fn expected_list ( & self , span : Span ) -> ErrorGuaranteed {
264
+ self . emit_err ( AttributeParseError {
265
+ span,
266
+ attr_span : self . attr_span ,
267
+ template : self . template . clone ( ) ,
268
+ attribute : self . attr_path . clone ( ) ,
269
+ reason : AttributeParseErrorReason :: ExpectedList ,
270
+ } )
271
+ }
272
+
273
+ /// emit an error that a `name = value` pair was expected at this span. The symbol can be given for
274
+ /// a nicer error message talking about the specific name that was found lacking a value.
275
+ pub ( crate ) fn expected_name_value ( & self , span : Span , name : Option < Symbol > ) -> ErrorGuaranteed {
276
+ self . emit_err ( AttributeParseError {
277
+ span,
278
+ attr_span : self . attr_span ,
279
+ template : self . template . clone ( ) ,
280
+ attribute : self . attr_path . clone ( ) ,
281
+ reason : AttributeParseErrorReason :: ExpectedNameValue ( name) ,
282
+ } )
283
+ }
284
+
285
+ /// emit an error that a `name = value` pair was found where that name was already seen.
286
+ pub ( crate ) fn duplicate_key ( & self , span : Span , key : Symbol ) -> ErrorGuaranteed {
287
+ self . emit_err ( AttributeParseError {
288
+ span,
289
+ attr_span : self . attr_span ,
290
+ template : self . template . clone ( ) ,
291
+ attribute : self . attr_path . clone ( ) ,
292
+ reason : AttributeParseErrorReason :: DuplicateKey ( key) ,
293
+ } )
294
+ }
258
295
259
296
pub ( crate ) fn expected_single_argument ( & self , span : Span ) -> ErrorGuaranteed {
260
- // E534?
261
297
self . emit_err ( AttributeParseError {
262
298
span,
263
299
attr_span : self . attr_span ,
@@ -270,15 +306,34 @@ impl<'f, 'sess: 'f, S: Stage> AcceptContext<'f, 'sess, S> {
270
306
pub ( crate ) fn expected_specific_argument (
271
307
& self ,
272
308
span : Span ,
273
- options : Vec < & ' static str > ,
309
+ possibilities : Vec < & ' static str > ,
310
+ ) -> ErrorGuaranteed {
311
+ self . emit_err ( AttributeParseError {
312
+ span,
313
+ attr_span : self . attr_span ,
314
+ template : self . template . clone ( ) ,
315
+ attribute : self . attr_path . clone ( ) ,
316
+ reason : AttributeParseErrorReason :: ExpectedSpecificArgument {
317
+ possibilities,
318
+ strings : false ,
319
+ } ,
320
+ } )
321
+ }
322
+
323
+ pub ( crate ) fn expected_specific_argument_strings (
324
+ & self ,
325
+ span : Span ,
326
+ possibilities : Vec < & ' static str > ,
274
327
) -> ErrorGuaranteed {
275
- // E535?
276
328
self . emit_err ( AttributeParseError {
277
329
span,
278
330
attr_span : self . attr_span ,
279
331
template : self . template . clone ( ) ,
280
332
attribute : self . attr_path . clone ( ) ,
281
- reason : AttributeParseErrorReason :: ExpectedSpecificArgument ( options) ,
333
+ reason : AttributeParseErrorReason :: ExpectedSpecificArgument {
334
+ possibilities,
335
+ strings : true ,
336
+ } ,
282
337
} )
283
338
}
284
339
}
0 commit comments