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