File tree Expand file tree Collapse file tree 2 files changed +23
-5
lines changed
ide/src/syntax_highlighting Expand file tree Collapse file tree 2 files changed +23
-5
lines changed Original file line number Diff line number Diff line change @@ -90,6 +90,13 @@ const RUSTDOC_FENCE_TOKENS: &[&'static str] = &[
90
90
"edition2021" ,
91
91
] ;
92
92
93
+ fn is_rustdoc_fence_token ( token : & str ) -> bool {
94
+ if RUSTDOC_FENCE_TOKENS . contains ( & token) {
95
+ return true ;
96
+ }
97
+ token. starts_with ( 'E' ) && token. len ( ) == 5 && token[ 1 ..] . parse :: < u32 > ( ) . is_ok ( )
98
+ }
99
+
93
100
/// Injection of syntax highlighting of doctests.
94
101
pub ( super ) fn doc_comment (
95
102
hl : & mut Highlights ,
@@ -174,8 +181,7 @@ pub(super) fn doc_comment(
174
181
is_codeblock = !is_codeblock;
175
182
// Check whether code is rust by inspecting fence guards
176
183
let guards = & line[ idx + RUSTDOC_FENCE . len ( ) ..] ;
177
- let is_rust =
178
- guards. split ( ',' ) . all ( |sub| RUSTDOC_FENCE_TOKENS . contains ( & sub. trim ( ) ) ) ;
184
+ let is_rust = guards. split ( ',' ) . all ( |sub| is_rustdoc_fence_token ( sub. trim ( ) ) ) ;
179
185
is_doctest = is_codeblock && is_rust;
180
186
continue ;
181
187
}
Original file line number Diff line number Diff line change @@ -27,9 +27,8 @@ pub(crate) fn format_docs(src: &str) -> String {
27
27
in_code_block ^= true ;
28
28
29
29
if in_code_block {
30
- is_rust = header
31
- . split ( ',' )
32
- . all ( |sub| RUSTDOC_CODE_BLOCK_ATTRIBUTES_RUST_SPECIFIC . contains ( & sub. trim ( ) ) ) ;
30
+ is_rust =
31
+ header. split ( ',' ) . all ( |sub| is_rust_specific_code_block_attribute ( sub. trim ( ) ) ) ;
33
32
34
33
if is_rust {
35
34
line = "```rust" ;
@@ -42,6 +41,13 @@ pub(crate) fn format_docs(src: &str) -> String {
42
41
processed_lines. join ( "\n " )
43
42
}
44
43
44
+ fn is_rust_specific_code_block_attribute ( attr : & str ) -> bool {
45
+ if RUSTDOC_CODE_BLOCK_ATTRIBUTES_RUST_SPECIFIC . contains ( & attr) {
46
+ return true ;
47
+ }
48
+ attr. starts_with ( 'E' ) && attr. len ( ) == 5 && attr[ 1 ..] . parse :: < u32 > ( ) . is_ok ( )
49
+ }
50
+
45
51
fn code_line_ignored_by_rustdoc ( line : & str ) -> bool {
46
52
let trimmed = line. trim ( ) ;
47
53
trimmed == "#" || trimmed. starts_with ( "# " ) || trimmed. starts_with ( "#\t " )
@@ -81,6 +87,12 @@ mod tests {
81
87
assert_eq ! ( format_docs( comment) , "```rust\n let z = 55;\n ```" ) ;
82
88
}
83
89
90
+ #[ test]
91
+ fn test_format_docs_handles_error_codes ( ) {
92
+ let comment = "```compile_fail,E0641\n let b = 0 as *const _;\n ```" ;
93
+ assert_eq ! ( format_docs( comment) , "```rust\n let b = 0 as *const _;\n ```" ) ;
94
+ }
95
+
84
96
#[ test]
85
97
fn test_format_docs_skips_comments_in_rust_block ( ) {
86
98
let comment =
You can’t perform that action at this time.
0 commit comments