1- use  rustc_attr_data_structures:: lints:: AttributeLintKind ; 
2- use  rustc_attr_data_structures:: { AttributeKind ,  DocAttribute ,  DocInline } ; 
1+ // FIXME: to be removed 
2+ #![ allow( unused_imports) ]  
3+ 
34use  rustc_errors:: MultiSpan ; 
45use  rustc_feature:: template; 
6+ use  rustc_hir:: attrs:: { AttributeKind ,  DocAttribute ,  DocInline } ; 
7+ use  rustc_hir:: lints:: AttributeLintKind ; 
58use  rustc_span:: { Span ,  Symbol ,  edition,  sym} ; 
69
710use  super :: { AcceptMapping ,  AttributeParser } ; 
11+ use  super :: prelude:: { Allow ,  AllowedTargets ,  MethodKind ,  Target } ; 
812use  crate :: context:: { AcceptContext ,  FinalizeContext ,  Stage } ; 
913use  crate :: fluent_generated as  fluent; 
1014use  crate :: parser:: { ArgParser ,  MetaItemOrLitParser ,  MetaItemParser ,  PathParser } ; 
@@ -28,8 +32,8 @@ impl DocParser {
2832
2933        match  path. word_sym ( )  { 
3034            Some ( sym:: no_crate_inject)  => { 
31-                 if  ! args. no_args ( )  { 
32-                     cx. expected_no_args ( args . span ( ) . unwrap ( ) ) ; 
35+                 if  let   Err ( span )  =  args. no_args ( )  { 
36+                     cx. expected_no_args ( span) ; 
3337                    return ; 
3438                } 
3539
@@ -42,16 +46,19 @@ impl DocParser {
4246            } 
4347            Some ( sym:: attr)  => { 
4448                let  Some ( list)  = args. list ( )  else  { 
45-                     cx. expected_list ( args . span ( ) . unwrap_or ( path . span ( ) ) ) ; 
49+                     cx. expected_list ( cx . attr_span ) ; 
4650                    return ; 
4751                } ; 
4852
49-                 self . attribute . test_attrs . push ( todo ! ( ) ) ; 
53+                 // FIXME: convert list into a Vec of `AttributeKind`. 
54+                 for  _ in  list { 
55+                     // self.attribute.test_attrs.push(AttributeKind::parse()); 
56+                 } 
5057            } 
5158            _ => { 
5259                cx. expected_specific_argument ( 
5360                    mip. span ( ) , 
54-                     [ sym:: no_crate_inject. as_str ( ) ,  sym:: attr. as_str ( ) ] . to_vec ( ) , 
61+                     & [ sym:: no_crate_inject,  sym:: attr] , 
5562                ) ; 
5663            } 
5764        } 
@@ -162,8 +169,8 @@ impl DocParser {
162169        args :  & ArgParser < ' _ > , 
163170        inline :  DocInline , 
164171    )  { 
165-         if  ! args. no_args ( )  { 
166-             cx. expected_no_args ( args . span ( ) . unwrap ( ) ) ; 
172+         if  let   Err ( span )  =  args. no_args ( )  { 
173+             cx. expected_no_args ( span) ; 
167174            return ; 
168175        } 
169176
@@ -192,8 +199,8 @@ impl DocParser {
192199
193200        macro_rules!  no_args { 
194201            ( $ident:  ident)  => { { 
195-                 if  ! args. no_args( )  { 
196-                     cx. expected_no_args( args . span( ) . unwrap ( ) ) ; 
202+                 if  let   Err ( span )  =  args. no_args( )  { 
203+                     cx. expected_no_args( span) ; 
197204                    return ; 
198205                } 
199206
@@ -239,7 +246,6 @@ impl DocParser {
239246            Some ( sym:: no_inline)  => self . parse_inline ( cx,  path,  args,  DocInline :: NoInline ) , 
240247            Some ( sym:: masked)  => no_args ! ( masked) , 
241248            Some ( sym:: cfg)  => no_args ! ( cfg) , 
242-             Some ( sym:: cfg_hide)  => no_args ! ( cfg_hide) , 
243249            Some ( sym:: notable_trait)  => no_args ! ( notable_trait) , 
244250            Some ( sym:: keyword)  => self . parse_keyword ( cx,  path,  args) , 
245251            Some ( sym:: fake_variadic)  => no_args ! ( fake_variadic) , 
@@ -323,19 +329,18 @@ impl DocParser {
323329            _ => { 
324330                cx. expected_specific_argument ( 
325331                    mip. span ( ) , 
326-                     [ 
327-                         sym:: alias. as_str ( ) , 
328-                         sym:: hidden. as_str ( ) , 
329-                         sym:: html_favicon_url. as_str ( ) , 
330-                         sym:: html_logo_url. as_str ( ) , 
331-                         sym:: html_no_source. as_str ( ) , 
332-                         sym:: html_playground_url. as_str ( ) , 
333-                         sym:: html_root_url. as_str ( ) , 
334-                         sym:: inline. as_str ( ) , 
335-                         sym:: no_inline. as_str ( ) , 
336-                         sym:: test. as_str ( ) , 
337-                     ] 
338-                     . to_vec ( ) , 
332+                     & [ 
333+                         sym:: alias, 
334+                         sym:: hidden, 
335+                         sym:: html_favicon_url, 
336+                         sym:: html_logo_url, 
337+                         sym:: html_no_source, 
338+                         sym:: html_playground_url, 
339+                         sym:: html_root_url, 
340+                         sym:: inline, 
341+                         sym:: no_inline, 
342+                         sym:: test, 
343+                     ] , 
339344                ) ; 
340345            } 
341346        } 
@@ -356,15 +361,17 @@ impl DocParser {
356361                        MetaItemOrLitParser :: MetaItemParser ( mip)  => { 
357362                            self . parse_single_doc_attr_item ( cx,  mip) ; 
358363                        } 
359-                         MetaItemOrLitParser :: Lit ( lit)  => todo ! ( "error should've used equals" ) , 
364+                         MetaItemOrLitParser :: Lit ( lit)  => { 
365+                             cx. expected_name_value ( i. span ( ) ,  None ) ; 
366+                         } 
360367                        MetaItemOrLitParser :: Err ( ..)  => { 
361368                            // already had an error here, move on. 
362369                        } 
363370                    } 
364371                } 
365372            } 
366373            ArgParser :: NameValue ( v)  => { 
367-                 panic ! ( "this should be rare if at all possible" ) ; 
374+                 self . attribute . value . push ( ( v ,  args . span ( ) ) ) ; 
368375            } 
369376        } 
370377    } 
@@ -373,11 +380,41 @@ impl DocParser {
373380impl < S :  Stage >  AttributeParser < S >  for  DocParser  { 
374381    const  ATTRIBUTES :  AcceptMapping < Self ,  S >  = & [ ( 
375382        & [ sym:: doc] , 
376-         template ! ( List :  "hidden| inline|..."  ,  NameValueStr :  "string" ) , 
383+         template ! ( List :  & [ "hidden"  ,   " inline" ,   "test" ] ,  NameValueStr :  "string" ) , 
377384        |this,  cx,  args| { 
378385            this. accept_single_doc_attr ( cx,  args) ; 
379386        } , 
380387    ) ] ; 
388+     const  ALLOWED_TARGETS :  AllowedTargets  = AllowedTargets :: AllowList ( & [ 
389+         Allow ( Target :: ExternCrate ) , 
390+         Allow ( Target :: Use ) , 
391+         Allow ( Target :: Static ) , 
392+         Allow ( Target :: Const ) , 
393+         Allow ( Target :: Fn ) , 
394+         Allow ( Target :: Mod ) , 
395+         Allow ( Target :: ForeignMod ) , 
396+         Allow ( Target :: TyAlias ) , 
397+         Allow ( Target :: Enum ) , 
398+         Allow ( Target :: Variant ) , 
399+         Allow ( Target :: Struct ) , 
400+         Allow ( Target :: Field ) , 
401+         Allow ( Target :: Union ) , 
402+         Allow ( Target :: Trait ) , 
403+         Allow ( Target :: TraitAlias ) , 
404+         Allow ( Target :: Impl  {  of_trait :  true  } ) , 
405+         Allow ( Target :: Field  {  of_trait :  true  } ) , 
406+         Allow ( Target :: AssocConst ) , 
407+         Allow ( Target :: Method ( MethodKind :: Inherent ) ) , 
408+         Allow ( Target :: Method ( MethodKind :: Trait  {  body :  true  } ) ) , 
409+         Allow ( Target :: Method ( MethodKind :: TraitImpl ) ) , 
410+         Allow ( Target :: AssocTy ) , 
411+         Allow ( Target :: ForeignFn ) , 
412+         Allow ( Target :: ForeignStatic ) , 
413+         Allow ( Target :: ForeignTy ) , 
414+         Allow ( Target :: MacroDef ) , 
415+         Allow ( Target :: Crate ) , 
416+     ] ) ; 
417+ 
381418
382419    fn  finalize ( self ,  cx :  & FinalizeContext < ' _ ,  ' _ ,  S > )  -> Option < AttributeKind >  { 
383420        todo ! ( ) 
0 commit comments