Skip to content

Commit

Permalink
Rollup merge of rust-lang#86814 - Aaron1011:inner-doc-recover, r=este…
Browse files Browse the repository at this point in the history
…bank

Recover from a misplaced inner doc comment

Fixes rust-lang#86781
  • Loading branch information
JohnTitor committed Jul 18, 2021
2 parents 76300d5 + 5c9bd9c commit 469935f
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 469935f

Please sign in to comment.