@@ -6,7 +6,7 @@ use hir::{AsAssocItem, Attrs, HirFileId, InFile, Semantics};
6
6
use ide_db:: RootDatabase ;
7
7
use itertools:: Itertools ;
8
8
use syntax:: {
9
- ast:: { self , AstNode , AttrsOwner , DocCommentsOwner , ModuleItemOwner , NameOwner } ,
9
+ ast:: { self , AstNode , AttrsOwner , ModuleItemOwner , NameOwner } ,
10
10
match_ast, SyntaxNode ,
11
11
} ;
12
12
@@ -118,6 +118,7 @@ fn runnable_fn(
118
118
) -> Option < Runnable > {
119
119
let name_string = fn_def. name ( ) ?. text ( ) . to_string ( ) ;
120
120
121
+ let attrs = Attrs :: from_attrs_owner ( sema. db , InFile :: new ( HirFileId :: from ( file_id) , & fn_def) ) ;
121
122
let kind = if name_string == "main" {
122
123
RunnableKind :: Bin
123
124
} else {
@@ -162,14 +163,13 @@ fn runnable_fn(
162
163
RunnableKind :: Test { test_id, attr }
163
164
} else if fn_def. has_atom_attr ( "bench" ) {
164
165
RunnableKind :: Bench { test_id }
165
- } else if has_runnable_doc_test ( & fn_def ) {
166
+ } else if has_runnable_doc_test ( & attrs ) {
166
167
RunnableKind :: DocTest { test_id }
167
168
} else {
168
169
return None ;
169
170
}
170
171
} ;
171
172
172
- let attrs = Attrs :: from_attrs_owner ( sema. db , InFile :: new ( HirFileId :: from ( file_id) , & fn_def) ) ;
173
173
let cfg = attrs. cfg ( ) ;
174
174
175
175
let nav = if let RunnableKind :: DocTest { .. } = kind {
@@ -189,13 +189,13 @@ fn runnable_struct(
189
189
struct_def : ast:: Struct ,
190
190
file_id : FileId ,
191
191
) -> Option < Runnable > {
192
- if !has_runnable_doc_test ( & struct_def) {
193
- return None ;
194
- }
195
192
let name_string = struct_def. name ( ) ?. text ( ) . to_string ( ) ;
196
193
197
194
let attrs =
198
195
Attrs :: from_attrs_owner ( sema. db , InFile :: new ( HirFileId :: from ( file_id) , & struct_def) ) ;
196
+ if !has_runnable_doc_test ( & attrs) {
197
+ return None ;
198
+ }
199
199
let cfg = attrs. cfg ( ) ;
200
200
201
201
let test_id = match sema. to_def ( & struct_def) . map ( |def| def. module ( sema. db ) ) {
@@ -240,11 +240,11 @@ const RUSTDOC_FENCE: &str = "```";
240
240
const RUSTDOC_CODE_BLOCK_ATTRIBUTES_RUNNABLE : & [ & str ] =
241
241
& [ "" , "rust" , "should_panic" , "edition2015" , "edition2018" ] ;
242
242
243
- fn has_runnable_doc_test ( def : & dyn DocCommentsOwner ) -> bool {
244
- def . doc_comment_text ( ) . map_or ( false , |comments_text | {
243
+ fn has_runnable_doc_test ( attrs : & hir :: Attrs ) -> bool {
244
+ attrs . docs ( ) . map_or ( false , |doc | {
245
245
let mut in_code_block = false ;
246
246
247
- for line in comments_text . lines ( ) {
247
+ for line in String :: from ( doc ) . lines ( ) {
248
248
if let Some ( header) = line. strip_prefix ( RUSTDOC_FENCE ) {
249
249
in_code_block = !in_code_block;
250
250
0 commit comments