@@ -26,7 +26,7 @@ use crate::attributes::stability::{
2626use crate :: attributes:: transparency:: TransparencyParser ;
2727use crate :: attributes:: { AttributeParser as _, Combine , Single } ;
2828use crate :: parser:: { ArgParser , MetaItemParser } ;
29- use crate :: session_diagnostics:: { AttributeParseError , AttributeParseErrorReason } ;
29+ use crate :: session_diagnostics:: { AttributeParseError , AttributeParseErrorReason , UnknownMetaItem } ;
3030
3131macro_rules! group_type {
3232 ( $stage: ty) => {
@@ -208,8 +208,16 @@ impl<'f, 'sess: 'f, S: Stage> AcceptContext<'f, 'sess, S> {
208208 ( self . emit_lint ) ( AttributeLint { id, span, kind : lint } ) ;
209209 }
210210
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+
211220 pub ( crate ) fn expected_string_literal ( & self , span : Span ) -> ErrorGuaranteed {
212- // 539?
213221 self . emit_err ( AttributeParseError {
214222 span,
215223 attr_span : self . attr_span ,
@@ -219,12 +227,40 @@ impl<'f, 'sess: 'f, S: Stage> AcceptContext<'f, 'sess, S> {
219227 } )
220228 }
221229
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+ }
225262
226263 pub ( crate ) fn expected_single_argument ( & self , span : Span ) -> ErrorGuaranteed {
227- // E534?
228264 self . emit_err ( AttributeParseError {
229265 span,
230266 attr_span : self . attr_span ,
@@ -237,15 +273,34 @@ impl<'f, 'sess: 'f, S: Stage> AcceptContext<'f, 'sess, S> {
237273 pub ( crate ) fn expected_specific_argument (
238274 & self ,
239275 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 > ,
241294 ) -> ErrorGuaranteed {
242- // E535?
243295 self . emit_err ( AttributeParseError {
244296 span,
245297 attr_span : self . attr_span ,
246298 template : self . template . clone ( ) ,
247299 attribute : self . attr_path . clone ( ) ,
248- reason : AttributeParseErrorReason :: ExpectedSpecificArgument ( options) ,
300+ reason : AttributeParseErrorReason :: ExpectedSpecificArgument {
301+ possibilities,
302+ strings : true ,
303+ } ,
249304 } )
250305 }
251306}
0 commit comments