File tree 5 files changed +45
-5
lines changed
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"),
432
432
E0750 : include_str!( "./error_codes/E0750.md" ) ,
433
433
E0751 : include_str!( "./error_codes/E0751.md" ) ,
434
434
E0752 : include_str!( "./error_codes/E0752.md" ) ,
435
+ E0753 : include_str!( "./error_codes/E0753.md" ) ,
435
436
;
436
437
// E0006, // merged with E0005
437
438
// 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;
4
4
use rustc_ast:: token:: { self , Nonterminal } ;
5
5
use rustc_ast:: util:: comments;
6
6
use rustc_ast_pretty:: pprust;
7
- use rustc_errors:: PResult ;
7
+ use rustc_errors:: { error_code , PResult } ;
8
8
use rustc_span:: { Span , Symbol } ;
9
9
10
10
use log:: debug;
@@ -50,10 +50,16 @@ impl<'a> Parser<'a> {
50
50
} else if let token:: DocComment ( s) = self . token . kind {
51
51
let attr = self . mk_doc_comment ( s) ;
52
52
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
+ )
54
60
. note (
55
61
"inner doc comments like this (starting with \
56
- `//!` or `/*!`) can only appear before items",
62
+ `//!` or `/*!`) can only appear before items",
57
63
)
58
64
. emit ( ) ;
59
65
}
Original file line number Diff line number Diff line change 1
- error: expected outer doc comment
1
+ error[E0753] : expected outer doc comment
2
2
--> $DIR/doc-comment-in-if-statement.rs:2:13
3
3
|
4
4
LL | if true /*!*/ {}
@@ -17,3 +17,4 @@ LL | if true /*!*/ {}
17
17
18
18
error: aborting due to 2 previous errors
19
19
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
2
2
--> $DIR/issue-30318.rs:3:1
3
3
|
4
4
LL | //! Misplaced comment...
@@ -8,3 +8,4 @@ LL | //! Misplaced comment...
8
8
9
9
error: aborting due to previous error
10
10
11
+ For more information about this error, try `rustc --explain E0753`.
You can’t perform that action at this time.
0 commit comments