@@ -27,7 +27,7 @@ use crate::attributes::stability::{
2727use crate :: attributes:: transparency:: TransparencyParser ;
2828use crate :: attributes:: { AttributeParser as _, Combine , Single } ;
2929use crate :: parser:: { ArgParser , MetaItemParser } ;
30- use crate :: session_diagnostics:: { AttributeParseError , AttributeParseErrorReason } ;
30+ use crate :: session_diagnostics:: { AttributeParseError , AttributeParseErrorReason , UnknownMetaItem } ;
3131
3232macro_rules! group_type {
3333 ( $stage: ty) => {
@@ -191,8 +191,16 @@ impl<'f, 'sess: 'f, S: Stage> AcceptContext<'f, 'sess, S> {
191191 ( self . emit_lint ) ( AttributeLint { id, span, kind : lint } ) ;
192192 }
193193
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+
194203 pub ( crate ) fn expected_string_literal ( & self , span : Span ) -> ErrorGuaranteed {
195- // 539?
196204 self . emit_err ( AttributeParseError {
197205 span,
198206 attr_span : self . attr_span ,
@@ -202,12 +210,40 @@ impl<'f, 'sess: 'f, S: Stage> AcceptContext<'f, 'sess, S> {
202210 } )
203211 }
204212
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+ }
208245
209246 pub ( crate ) fn expected_single_argument ( & self , span : Span ) -> ErrorGuaranteed {
210- // E534?
211247 self . emit_err ( AttributeParseError {
212248 span,
213249 attr_span : self . attr_span ,
@@ -220,15 +256,34 @@ impl<'f, 'sess: 'f, S: Stage> AcceptContext<'f, 'sess, S> {
220256 pub ( crate ) fn expected_specific_argument (
221257 & self ,
222258 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 > ,
224277 ) -> ErrorGuaranteed {
225- // E535?
226278 self . emit_err ( AttributeParseError {
227279 span,
228280 attr_span : self . attr_span ,
229281 template : self . template . clone ( ) ,
230282 attribute : self . attr_path . clone ( ) ,
231- reason : AttributeParseErrorReason :: ExpectedSpecificArgument ( options) ,
283+ reason : AttributeParseErrorReason :: ExpectedSpecificArgument {
284+ possibilities,
285+ strings : true ,
286+ } ,
232287 } )
233288 }
234289}
0 commit comments