@@ -12,7 +12,7 @@ use smallvec::smallvec;
12
12
#[ derive( Debug ) ]
13
13
enum InnerAttributeParsePolicy < ' a > {
14
14
Permitted ,
15
- NotPermitted { reason : & ' a str , prev_attr_sp : Option < Span > } ,
15
+ NotPermitted { reason : & ' a str , saw_doc_comment : bool , prev_attr_sp : Option < Span > } ,
16
16
}
17
17
18
18
const DEFAULT_UNEXPECTED_INNER_ATTR_ERR_MSG : & str = "an inner attribute is not \
@@ -43,8 +43,11 @@ impl<'a> Parser<'a> {
43
43
DEFAULT_UNEXPECTED_INNER_ATTR_ERR_MSG
44
44
} ;
45
45
let inner_parse_policy =
46
- InnerAttributeParsePolicy :: NotPermitted { reason : inner_error_reason,
47
- prev_attr_sp : attrs. last ( ) . and_then ( |a| Some ( a. span ) ) } ;
46
+ InnerAttributeParsePolicy :: NotPermitted {
47
+ reason : inner_error_reason,
48
+ saw_doc_comment : just_parsed_doc_comment,
49
+ prev_attr_sp : attrs. last ( ) . and_then ( |a| Some ( a. span ) )
50
+ } ;
48
51
let attr = self . parse_attribute_with_inner_parse_policy ( inner_parse_policy) ?;
49
52
attrs. push ( attr) ;
50
53
just_parsed_doc_comment = false ;
@@ -78,8 +81,11 @@ impl<'a> Parser<'a> {
78
81
let inner_parse_policy = if permit_inner {
79
82
InnerAttributeParsePolicy :: Permitted
80
83
} else {
81
- InnerAttributeParsePolicy :: NotPermitted
82
- { reason : DEFAULT_UNEXPECTED_INNER_ATTR_ERR_MSG , prev_attr_sp : None }
84
+ InnerAttributeParsePolicy :: NotPermitted {
85
+ reason : DEFAULT_UNEXPECTED_INNER_ATTR_ERR_MSG ,
86
+ saw_doc_comment : false ,
87
+ prev_attr_sp : None
88
+ }
83
89
} ;
84
90
self . parse_attribute_with_inner_parse_policy ( inner_parse_policy)
85
91
}
@@ -117,16 +123,22 @@ impl<'a> Parser<'a> {
117
123
118
124
// Emit error if inner attribute is encountered and not permitted
119
125
if style == ast:: AttrStyle :: Inner {
120
- if let InnerAttributeParsePolicy :: NotPermitted { reason, prev_attr_sp }
121
- = inner_parse_policy {
126
+ if let InnerAttributeParsePolicy :: NotPermitted { reason,
127
+ saw_doc_comment, prev_attr_sp } = inner_parse_policy {
128
+ let prev_attr_note = if saw_doc_comment {
129
+ "previous doc comment"
130
+ } else {
131
+ "previous outer attribute"
132
+ } ;
133
+
122
134
let mut diagnostic = self
123
135
. diagnostic ( )
124
136
. struct_span_err ( attr_sp, reason) ;
125
137
126
138
if let Some ( prev_attr_sp) = prev_attr_sp {
127
139
diagnostic
128
140
. span_label ( attr_sp, "not permitted following an outer attibute" )
129
- . span_label ( prev_attr_sp, "previous outer attribute" ) ;
141
+ . span_label ( prev_attr_sp, prev_attr_note ) ;
130
142
}
131
143
132
144
diagnostic
0 commit comments