Skip to content

Commit fc9bfd6

Browse files
committed
Treat doc comments separately
1 parent 8b3f28c commit fc9bfd6

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

src/libsyntax/parse/attr.rs

+20-8
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use smallvec::smallvec;
1212
#[derive(Debug)]
1313
enum InnerAttributeParsePolicy<'a> {
1414
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> },
1616
}
1717

1818
const DEFAULT_UNEXPECTED_INNER_ATTR_ERR_MSG: &str = "an inner attribute is not \
@@ -43,8 +43,11 @@ impl<'a> Parser<'a> {
4343
DEFAULT_UNEXPECTED_INNER_ATTR_ERR_MSG
4444
};
4545
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+
};
4851
let attr = self.parse_attribute_with_inner_parse_policy(inner_parse_policy)?;
4952
attrs.push(attr);
5053
just_parsed_doc_comment = false;
@@ -78,8 +81,11 @@ impl<'a> Parser<'a> {
7881
let inner_parse_policy = if permit_inner {
7982
InnerAttributeParsePolicy::Permitted
8083
} 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+
}
8389
};
8490
self.parse_attribute_with_inner_parse_policy(inner_parse_policy)
8591
}
@@ -117,16 +123,22 @@ impl<'a> Parser<'a> {
117123

118124
// Emit error if inner attribute is encountered and not permitted
119125
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+
122134
let mut diagnostic = self
123135
.diagnostic()
124136
.struct_span_err(attr_sp, reason);
125137

126138
if let Some(prev_attr_sp) = prev_attr_sp {
127139
diagnostic
128140
.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);
130142
}
131143

132144
diagnostic

0 commit comments

Comments
 (0)