@@ -6,7 +6,7 @@ use hir::{AsAssocItem, Attrs, HirFileId, InFile, Semantics};
66use ide_db:: RootDatabase ;
77use itertools:: Itertools ;
88use syntax:: {
9- ast:: { self , AstNode , AttrsOwner , DocCommentsOwner , ModuleItemOwner , NameOwner } ,
9+ ast:: { self , AstNode , AttrsOwner , ModuleItemOwner , NameOwner } ,
1010 match_ast, SyntaxNode ,
1111} ;
1212
@@ -118,6 +118,7 @@ fn runnable_fn(
118118) -> Option < Runnable > {
119119 let name_string = fn_def. name ( ) ?. text ( ) . to_string ( ) ;
120120
121+ let attrs = Attrs :: from_attrs_owner ( sema. db , InFile :: new ( HirFileId :: from ( file_id) , & fn_def) ) ;
121122 let kind = if name_string == "main" {
122123 RunnableKind :: Bin
123124 } else {
@@ -162,14 +163,13 @@ fn runnable_fn(
162163 RunnableKind :: Test { test_id, attr }
163164 } else if fn_def. has_atom_attr ( "bench" ) {
164165 RunnableKind :: Bench { test_id }
165- } else if has_runnable_doc_test ( & fn_def ) {
166+ } else if has_runnable_doc_test ( & attrs ) {
166167 RunnableKind :: DocTest { test_id }
167168 } else {
168169 return None ;
169170 }
170171 } ;
171172
172- let attrs = Attrs :: from_attrs_owner ( sema. db , InFile :: new ( HirFileId :: from ( file_id) , & fn_def) ) ;
173173 let cfg = attrs. cfg ( ) ;
174174
175175 let nav = if let RunnableKind :: DocTest { .. } = kind {
@@ -189,13 +189,13 @@ fn runnable_struct(
189189 struct_def : ast:: Struct ,
190190 file_id : FileId ,
191191) -> Option < Runnable > {
192- if !has_runnable_doc_test ( & struct_def) {
193- return None ;
194- }
195192 let name_string = struct_def. name ( ) ?. text ( ) . to_string ( ) ;
196193
197194 let attrs =
198195 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+ }
199199 let cfg = attrs. cfg ( ) ;
200200
201201 let test_id = match sema. to_def ( & struct_def) . map ( |def| def. module ( sema. db ) ) {
@@ -240,11 +240,11 @@ const RUSTDOC_FENCE: &str = "```";
240240const RUSTDOC_CODE_BLOCK_ATTRIBUTES_RUNNABLE : & [ & str ] =
241241 & [ "" , "rust" , "should_panic" , "edition2015" , "edition2018" ] ;
242242
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 | {
245245 let mut in_code_block = false ;
246246
247- for line in comments_text . lines ( ) {
247+ for line in String :: from ( doc ) . lines ( ) {
248248 if let Some ( header) = line. strip_prefix ( RUSTDOC_FENCE ) {
249249 in_code_block = !in_code_block;
250250
0 commit comments