Skip to content

Commit 5c9bd9c

Browse files
committed
Recover from a misplaced inner doc comment
Fixes #86781
1 parent f9fa13f commit 5c9bd9c

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

compiler/rustc_parse/src/parser/attr.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,14 @@ impl<'a> Parser<'a> {
6464
}
6565
self.bump();
6666
just_parsed_doc_comment = true;
67-
Some(attr::mk_doc_comment(comment_kind, attr_style, data, self.prev_token.span))
67+
// Always make an outer attribute - this allows us to recover from a misplaced
68+
// inner attribute.
69+
Some(attr::mk_doc_comment(
70+
comment_kind,
71+
ast::AttrStyle::Outer,
72+
data,
73+
self.prev_token.span,
74+
))
6875
} else {
6976
None
7077
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// aux-build:test-macros.rs
2+
3+
#[macro_use]
4+
extern crate test_macros;
5+
6+
//! Inner doc comment
7+
//~^ ERROR expected outer doc comment
8+
#[derive(Empty)]
9+
pub struct Foo;
10+
11+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
error[E0753]: expected outer doc comment
2+
--> $DIR/issue-86781-bad-inner-doc.rs:6:1
3+
|
4+
LL | //! Inner doc comment
5+
| ^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: inner doc comments like this (starting with `//!` or `/*!`) can only appear before items
8+
9+
error: aborting due to previous error
10+
11+
For more information about this error, try `rustc --explain E0753`.

0 commit comments

Comments
 (0)