1+ use std:: borrow:: Cow ;
12use std:: cell:: RefCell ;
23use std:: collections:: BTreeMap ;
34use std:: ops:: { Deref , DerefMut } ;
@@ -766,6 +767,7 @@ impl<'sess> AttributeParser<'sess, Early> {
766767 sess,
767768 attrs,
768769 Some ( sym) ,
770+ Target :: Crate , // Does not matter, we're not going to emit errors anyways
769771 target_span,
770772 target_node_id,
771773 features,
@@ -779,6 +781,7 @@ impl<'sess> AttributeParser<'sess, Early> {
779781 sess : & ' sess Session ,
780782 attrs : & [ ast:: Attribute ] ,
781783 parse_only : Option < Symbol > ,
784+ target : Target ,
782785 target_span : Span ,
783786 target_node_id : NodeId ,
784787 features : Option < & ' sess Features > ,
@@ -790,7 +793,7 @@ impl<'sess> AttributeParser<'sess, Early> {
790793 attrs,
791794 target_span,
792795 target_node_id,
793- Target :: Crate , // Does not matter, we're not going to emit errors anyways
796+ target ,
794797 OmitDoc :: Skip ,
795798 std:: convert:: identity,
796799 |_lint| {
@@ -806,9 +809,9 @@ impl<'sess> AttributeParser<'sess, Early> {
806809 target_node_id : NodeId ,
807810 features : Option < & ' sess Features > ,
808811 emit_errors : ShouldEmit ,
809- parse_fn : fn ( cx : & mut AcceptContext < ' _ , ' _ , Early > , item : & ArgParser < ' _ > ) -> T ,
812+ parse_fn : fn ( cx : & mut AcceptContext < ' _ , ' _ , Early > , item : & ArgParser < ' _ > ) -> Option < T > ,
810813 template : & AttributeTemplate ,
811- ) -> T {
814+ ) -> Option < T > {
812815 let mut parser = Self {
813816 features,
814817 tools : Vec :: new ( ) ,
@@ -819,7 +822,9 @@ impl<'sess> AttributeParser<'sess, Early> {
819822 let ast:: AttrKind :: Normal ( normal_attr) = & attr. kind else {
820823 panic ! ( "parse_single called on a doc attr" )
821824 } ;
822- let meta_parser = MetaItemParser :: from_attr ( normal_attr, parser. dcx ( ) ) ;
825+ let parts =
826+ normal_attr. item . path . segments . iter ( ) . map ( |seg| seg. ident . name ) . collect :: < Vec < _ > > ( ) ;
827+ let meta_parser = MetaItemParser :: from_attr ( normal_attr, & parts, & sess. psess , emit_errors) ?;
823828 let path = meta_parser. path ( ) ;
824829 let args = meta_parser. args ( ) ;
825830 let mut cx: AcceptContext < ' _ , ' sess , Early > = AcceptContext {
@@ -926,14 +931,23 @@ impl<'sess, S: Stage> AttributeParser<'sess, S> {
926931 // }))
927932 // }
928933 ast:: AttrKind :: Normal ( n) => {
929- attr_paths. push ( PathParser :: Ast ( & n. item . path ) ) ;
934+ attr_paths. push ( PathParser ( Cow :: Borrowed ( & n. item . path ) ) ) ;
930935
931- let parser = MetaItemParser :: from_attr ( n, self . dcx ( ) ) ;
932- let path = parser. path ( ) ;
933- let args = parser. args ( ) ;
934- let parts = path. segments ( ) . map ( |i| i. name ) . collect :: < Vec < _ > > ( ) ;
936+ let parts =
937+ n. item . path . segments . iter ( ) . map ( |seg| seg. ident . name ) . collect :: < Vec < _ > > ( ) ;
935938
936939 if let Some ( accepts) = S :: parsers ( ) . accepters . get ( parts. as_slice ( ) ) {
940+ let Some ( parser) = MetaItemParser :: from_attr (
941+ n,
942+ & parts,
943+ & self . sess . psess ,
944+ self . stage . should_emit ( ) ,
945+ ) else {
946+ continue ;
947+ } ;
948+ let path = parser. path ( ) ;
949+ let args = parser. args ( ) ;
950+
937951 for accept in accepts {
938952 let mut cx: AcceptContext < ' _ , ' sess , S > = AcceptContext {
939953 shared : SharedContext {
0 commit comments