@@ -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) => {
@@ -208,8 +208,16 @@ impl<'f, 'sess: 'f, S: Stage> AcceptContext<'f, 'sess, S> {
208
208
( self . emit_lint ) ( AttributeLint { id, span, kind : lint } ) ;
209
209
}
210
210
211
+ pub ( crate ) fn unknown_key (
212
+ & self ,
213
+ span : Span ,
214
+ found : String ,
215
+ options : & ' static [ & ' static str ] ,
216
+ ) -> ErrorGuaranteed {
217
+ self . emit_err ( UnknownMetaItem { span, item : found, expected : options } )
218
+ }
219
+
211
220
pub ( crate ) fn expected_string_literal ( & self , span : Span ) -> ErrorGuaranteed {
212
- // 539?
213
221
self . emit_err ( AttributeParseError {
214
222
span,
215
223
attr_span : self . attr_span ,
@@ -219,12 +227,40 @@ impl<'f, 'sess: 'f, S: Stage> AcceptContext<'f, 'sess, S> {
219
227
} )
220
228
}
221
229
222
- // pub(crate) fn expected_any_arguments(&self, span: Span) -> ErrorGuaranteed {
223
- //
224
- // }
230
+ pub ( crate ) fn expected_list ( & self , span : Span ) -> ErrorGuaranteed {
231
+ self . emit_err ( AttributeParseError {
232
+ span,
233
+ attr_span : self . attr_span ,
234
+ template : self . template . clone ( ) ,
235
+ attribute : self . attr_path . clone ( ) ,
236
+ reason : AttributeParseErrorReason :: ExpectedList ,
237
+ } )
238
+ }
239
+
240
+ /// emit an error that a `name = value` pair was expected at this span. The symbol can be given for
241
+ /// a nicer error message talking about the specific name that was found lacking a value.
242
+ pub ( crate ) fn expected_name_value ( & self , span : Span , name : Option < Symbol > ) -> ErrorGuaranteed {
243
+ self . emit_err ( AttributeParseError {
244
+ span,
245
+ attr_span : self . attr_span ,
246
+ template : self . template . clone ( ) ,
247
+ attribute : self . attr_path . clone ( ) ,
248
+ reason : AttributeParseErrorReason :: ExpectedNameValue ( name) ,
249
+ } )
250
+ }
251
+
252
+ /// emit an error that a `name = value` pair was found where that name was already seen.
253
+ pub ( crate ) fn duplicate_key ( & self , span : Span , key : Symbol ) -> ErrorGuaranteed {
254
+ self . emit_err ( AttributeParseError {
255
+ span,
256
+ attr_span : self . attr_span ,
257
+ template : self . template . clone ( ) ,
258
+ attribute : self . attr_path . clone ( ) ,
259
+ reason : AttributeParseErrorReason :: DuplicateKey ( key) ,
260
+ } )
261
+ }
225
262
226
263
pub ( crate ) fn expected_single_argument ( & self , span : Span ) -> ErrorGuaranteed {
227
- // E534?
228
264
self . emit_err ( AttributeParseError {
229
265
span,
230
266
attr_span : self . attr_span ,
@@ -237,15 +273,34 @@ impl<'f, 'sess: 'f, S: Stage> AcceptContext<'f, 'sess, S> {
237
273
pub ( crate ) fn expected_specific_argument (
238
274
& self ,
239
275
span : Span ,
240
- options : Vec < & ' static str > ,
276
+ possibilities : Vec < & ' static str > ,
277
+ ) -> ErrorGuaranteed {
278
+ self . emit_err ( AttributeParseError {
279
+ span,
280
+ attr_span : self . attr_span ,
281
+ template : self . template . clone ( ) ,
282
+ attribute : self . attr_path . clone ( ) ,
283
+ reason : AttributeParseErrorReason :: ExpectedSpecificArgument {
284
+ possibilities,
285
+ strings : false ,
286
+ } ,
287
+ } )
288
+ }
289
+
290
+ pub ( crate ) fn expected_specific_argument_strings (
291
+ & self ,
292
+ span : Span ,
293
+ possibilities : Vec < & ' static str > ,
241
294
) -> ErrorGuaranteed {
242
- // E535?
243
295
self . emit_err ( AttributeParseError {
244
296
span,
245
297
attr_span : self . attr_span ,
246
298
template : self . template . clone ( ) ,
247
299
attribute : self . attr_path . clone ( ) ,
248
- reason : AttributeParseErrorReason :: ExpectedSpecificArgument ( options) ,
300
+ reason : AttributeParseErrorReason :: ExpectedSpecificArgument {
301
+ possibilities,
302
+ strings : true ,
303
+ } ,
249
304
} )
250
305
}
251
306
}
0 commit comments