1
+ use std:: borrow:: Cow ;
1
2
use std:: cell:: RefCell ;
2
3
use std:: collections:: BTreeMap ;
3
4
use std:: ops:: { Deref , DerefMut } ;
@@ -766,6 +767,7 @@ impl<'sess> AttributeParser<'sess, Early> {
766
767
sess,
767
768
attrs,
768
769
Some ( sym) ,
770
+ Target :: Crate , // Does not matter, we're not going to emit errors anyways
769
771
target_span,
770
772
target_node_id,
771
773
features,
@@ -779,6 +781,7 @@ impl<'sess> AttributeParser<'sess, Early> {
779
781
sess : & ' sess Session ,
780
782
attrs : & [ ast:: Attribute ] ,
781
783
parse_only : Option < Symbol > ,
784
+ target : Target ,
782
785
target_span : Span ,
783
786
target_node_id : NodeId ,
784
787
features : Option < & ' sess Features > ,
@@ -790,7 +793,7 @@ impl<'sess> AttributeParser<'sess, Early> {
790
793
attrs,
791
794
target_span,
792
795
target_node_id,
793
- Target :: Crate , // Does not matter, we're not going to emit errors anyways
796
+ target ,
794
797
OmitDoc :: Skip ,
795
798
std:: convert:: identity,
796
799
|_lint| {
@@ -806,9 +809,9 @@ impl<'sess> AttributeParser<'sess, Early> {
806
809
target_node_id : NodeId ,
807
810
features : Option < & ' sess Features > ,
808
811
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 > ,
810
813
template : & AttributeTemplate ,
811
- ) -> T {
814
+ ) -> Option < T > {
812
815
let mut parser = Self {
813
816
features,
814
817
tools : Vec :: new ( ) ,
@@ -819,7 +822,9 @@ impl<'sess> AttributeParser<'sess, Early> {
819
822
let ast:: AttrKind :: Normal ( normal_attr) = & attr. kind else {
820
823
panic ! ( "parse_single called on a doc attr" )
821
824
} ;
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) ?;
823
828
let path = meta_parser. path ( ) ;
824
829
let args = meta_parser. args ( ) ;
825
830
let mut cx: AcceptContext < ' _ , ' sess , Early > = AcceptContext {
@@ -926,14 +931,23 @@ impl<'sess, S: Stage> AttributeParser<'sess, S> {
926
931
// }))
927
932
// }
928
933
ast:: AttrKind :: Normal ( n) => {
929
- attr_paths. push ( PathParser :: Ast ( & n. item . path ) ) ;
934
+ attr_paths. push ( PathParser ( Cow :: Borrowed ( & n. item . path ) ) ) ;
930
935
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 < _ > > ( ) ;
935
938
936
939
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
+
937
951
for accept in accepts {
938
952
let mut cx: AcceptContext < ' _ , ' sess , S > = AcceptContext {
939
953
shared : SharedContext {
0 commit comments