Skip to content

Commit

Permalink
Recover from a misplaced inner doc comment
Browse files Browse the repository at this point in the history
Fixes #86781
  • Loading branch information
Aaron1011 committed Jul 2, 2021
1 parent f9fa13f commit 5c9bd9c
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
9 changes: 8 additions & 1 deletion compiler/rustc_parse/src/parser/attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,14 @@ impl<'a> Parser<'a> {
}
self.bump();
just_parsed_doc_comment = true;
Some(attr::mk_doc_comment(comment_kind, attr_style, data, self.prev_token.span))
// Always make an outer attribute - this allows us to recover from a misplaced
// inner attribute.
Some(attr::mk_doc_comment(
comment_kind,
ast::AttrStyle::Outer,
data,
self.prev_token.span,
))
} else {
None
};
Expand Down
11 changes: 11 additions & 0 deletions src/test/ui/proc-macro/issue-86781-bad-inner-doc.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// aux-build:test-macros.rs

#[macro_use]
extern crate test_macros;

//! Inner doc comment
//~^ ERROR expected outer doc comment
#[derive(Empty)]
pub struct Foo;

fn main() {}
11 changes: 11 additions & 0 deletions src/test/ui/proc-macro/issue-86781-bad-inner-doc.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
error[E0753]: expected outer doc comment
--> $DIR/issue-86781-bad-inner-doc.rs:6:1
|
LL | //! Inner doc comment
| ^^^^^^^^^^^^^^^^^^^^^
|
= note: inner doc comments like this (starting with `//!` or `/*!`) can only appear before items

error: aborting due to previous error

For more information about this error, try `rustc --explain E0753`.

0 comments on commit 5c9bd9c

Please sign in to comment.