File tree Expand file tree Collapse file tree 5 files changed +45
-5
lines changed Expand file tree Collapse file tree 5 files changed +45
-5
lines changed Original file line number Diff line number Diff line change @@ -432,6 +432,7 @@ E0749: include_str!("./error_codes/E0749.md"),
432432E0750 : include_str!( "./error_codes/E0750.md" ) ,
433433E0751 : include_str!( "./error_codes/E0751.md" ) ,
434434E0752 : include_str!( "./error_codes/E0752.md" ) ,
435+ E0753 : include_str!( "./error_codes/E0753.md" ) ,
435436;
436437// E0006, // merged with E0005
437438// E0008, // cannot bind by-move into a pattern guard
Original file line number Diff line number Diff line change 1+ An inner doc comment was used in an invalid context.
2+
3+ Erroneous code example:
4+
5+ ``` compile_fail,E0753
6+ fn foo() {}
7+ //! foo
8+ // ^ error!
9+ fn main() {}
10+ ```
11+
12+ Inner document can only be used before items. For example:
13+
14+ ```
15+ //! A working comment applied to the module!
16+ fn foo() {
17+ //! Another working comment!
18+ }
19+ fn main() {}
20+ ```
21+
22+ In case you want to document the item following the doc comment, you might want
23+ to use outer doc comment:
24+
25+ ```
26+ /// I am an outer doc comment
27+ #[doc = "I am also an outer doc comment!"]
28+ fn foo() {
29+ // ...
30+ }
31+ ```
Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ use rustc_ast::attr;
44use rustc_ast:: token:: { self , Nonterminal } ;
55use rustc_ast:: util:: comments;
66use rustc_ast_pretty:: pprust;
7- use rustc_errors:: PResult ;
7+ use rustc_errors:: { error_code , PResult } ;
88use rustc_span:: { Span , Symbol } ;
99
1010use log:: debug;
@@ -50,10 +50,16 @@ impl<'a> Parser<'a> {
5050 } else if let token:: DocComment ( s) = self . token . kind {
5151 let attr = self . mk_doc_comment ( s) ;
5252 if attr. style != ast:: AttrStyle :: Outer {
53- self . struct_span_err ( self . token . span , "expected outer doc comment" )
53+ self . sess
54+ . span_diagnostic
55+ . struct_span_err_with_code (
56+ self . token . span ,
57+ "expected outer doc comment" ,
58+ error_code ! ( E0753 ) ,
59+ )
5460 . note (
5561 "inner doc comments like this (starting with \
56- `//!` or `/*!`) can only appear before items",
62+ `//!` or `/*!`) can only appear before items",
5763 )
5864 . emit ( ) ;
5965 }
Original file line number Diff line number Diff line change 1- error: expected outer doc comment
1+ error[E0753] : expected outer doc comment
22 --> $DIR/doc-comment-in-if-statement.rs:2:13
33 |
44LL | if true /*!*/ {}
@@ -17,3 +17,4 @@ LL | if true /*!*/ {}
1717
1818error: aborting due to 2 previous errors
1919
20+ For more information about this error, try `rustc --explain E0753`.
Original file line number Diff line number Diff line change 1- error: expected outer doc comment
1+ error[E0753] : expected outer doc comment
22 --> $DIR/issue-30318.rs:3:1
33 |
44LL | //! Misplaced comment...
@@ -8,3 +8,4 @@ LL | //! Misplaced comment...
88
99error: aborting due to previous error
1010
11+ For more information about this error, try `rustc --explain E0753`.
You can’t perform that action at this time.
0 commit comments