@@ -157,7 +157,7 @@ pub(crate) fn runnables(db: &RootDatabase, file_id: FileId) -> Vec<Runnable> {
157
157
hir:: ModuleDef :: Function ( it) => runnable_fn ( & sema, it) ,
158
158
_ => None ,
159
159
} ;
160
- add_opt ( runnable. or_else ( || module_def_doctest ( & sema, def) ) , Some ( def) ) ;
160
+ add_opt ( runnable. or_else ( || module_def_doctest ( sema. db , def) ) , Some ( def) ) ;
161
161
}
162
162
Either :: Right ( impl_) => {
163
163
add_opt ( runnable_impl ( & sema, & impl_) , None ) ;
@@ -168,9 +168,9 @@ pub(crate) fn runnables(db: &RootDatabase, file_id: FileId) -> Vec<Runnable> {
168
168
(
169
169
match assoc {
170
170
hir:: AssocItem :: Function ( it) => runnable_fn ( & sema, it)
171
- . or_else ( || module_def_doctest ( & sema, it. into ( ) ) ) ,
172
- hir:: AssocItem :: Const ( it) => module_def_doctest ( & sema, it. into ( ) ) ,
173
- hir:: AssocItem :: TypeAlias ( it) => module_def_doctest ( & sema, it. into ( ) ) ,
171
+ . or_else ( || module_def_doctest ( sema. db , it. into ( ) ) ) ,
172
+ hir:: AssocItem :: Const ( it) => module_def_doctest ( sema. db , it. into ( ) ) ,
173
+ hir:: AssocItem :: TypeAlias ( it) => module_def_doctest ( sema. db , it. into ( ) ) ,
174
174
} ,
175
175
assoc,
176
176
)
@@ -382,61 +382,59 @@ fn runnable_mod_outline_definition(
382
382
}
383
383
}
384
384
385
- fn module_def_doctest ( sema : & Semantics < RootDatabase > , def : hir:: ModuleDef ) -> Option < Runnable > {
385
+ fn module_def_doctest ( db : & RootDatabase , def : hir:: ModuleDef ) -> Option < Runnable > {
386
386
let attrs = match def {
387
- hir:: ModuleDef :: Module ( it) => it. attrs ( sema . db ) ,
388
- hir:: ModuleDef :: Function ( it) => it. attrs ( sema . db ) ,
389
- hir:: ModuleDef :: Adt ( it) => it. attrs ( sema . db ) ,
390
- hir:: ModuleDef :: Variant ( it) => it. attrs ( sema . db ) ,
391
- hir:: ModuleDef :: Const ( it) => it. attrs ( sema . db ) ,
392
- hir:: ModuleDef :: Static ( it) => it. attrs ( sema . db ) ,
393
- hir:: ModuleDef :: Trait ( it) => it. attrs ( sema . db ) ,
394
- hir:: ModuleDef :: TypeAlias ( it) => it. attrs ( sema . db ) ,
387
+ hir:: ModuleDef :: Module ( it) => it. attrs ( db) ,
388
+ hir:: ModuleDef :: Function ( it) => it. attrs ( db) ,
389
+ hir:: ModuleDef :: Adt ( it) => it. attrs ( db) ,
390
+ hir:: ModuleDef :: Variant ( it) => it. attrs ( db) ,
391
+ hir:: ModuleDef :: Const ( it) => it. attrs ( db) ,
392
+ hir:: ModuleDef :: Static ( it) => it. attrs ( db) ,
393
+ hir:: ModuleDef :: Trait ( it) => it. attrs ( db) ,
394
+ hir:: ModuleDef :: TypeAlias ( it) => it. attrs ( db) ,
395
395
hir:: ModuleDef :: BuiltinType ( _) => return None ,
396
396
} ;
397
397
if !has_runnable_doc_test ( & attrs) {
398
398
return None ;
399
399
}
400
- let def_name = def. name ( sema. db ) . map ( |it| it. to_string ( ) ) ;
401
- let test_id = def
402
- . canonical_path ( sema. db )
403
- // This probably belongs to canonical path?
404
- . map ( |path| {
405
- let assoc_def = match def {
406
- hir:: ModuleDef :: Function ( it) => it. as_assoc_item ( sema. db ) ,
407
- hir:: ModuleDef :: Const ( it) => it. as_assoc_item ( sema. db ) ,
408
- hir:: ModuleDef :: TypeAlias ( it) => it. as_assoc_item ( sema. db ) ,
409
- _ => None ,
410
- } ;
411
- // FIXME: this also looks very wrong
412
- if let Some ( assoc_def) = assoc_def {
413
- if let hir:: AssocItemContainer :: Impl ( imp) = assoc_def. container ( sema. db ) {
414
- let ty = imp. self_ty ( sema. db ) ;
415
- if let Some ( adt) = ty. as_adt ( ) {
416
- let name = adt. name ( sema. db ) ;
417
- let idx = path. rfind ( ':' ) . map_or ( 0 , |idx| idx + 1 ) ;
418
- let ( prefix, suffix) = path. split_at ( idx) ;
419
- let mut ty_args = ty. type_arguments ( ) . peekable ( ) ;
420
- let params = if ty_args. peek ( ) . is_some ( ) {
421
- format ! (
422
- "<{}>" ,
423
- ty_args. format_with( ", " , |ty, cb| cb( & ty. display( sema. db) ) )
424
- )
425
- } else {
426
- String :: new ( )
427
- } ;
428
- return format ! ( "{}{}{}::{}" , prefix, name, params, suffix) ;
400
+ let def_name = def. name ( db) ?;
401
+ let path = ( || {
402
+ let mut path = String :: new ( ) ;
403
+ def. module ( db) ?
404
+ . path_to_root ( db)
405
+ . into_iter ( )
406
+ . rev ( )
407
+ . flat_map ( |it| it. name ( db) )
408
+ . for_each ( |name| format_to ! ( path, "{}::" , name) ) ;
409
+ // This probably belongs to canonical_path?
410
+ if let Some ( assoc_item) = def. as_assoc_item ( db) {
411
+ if let hir:: AssocItemContainer :: Impl ( imp) = assoc_item. container ( db) {
412
+ let ty = imp. self_ty ( db) ;
413
+ if let Some ( adt) = ty. as_adt ( ) {
414
+ let name = adt. name ( db) ;
415
+ let mut ty_args = ty. type_arguments ( ) . peekable ( ) ;
416
+ format_to ! ( path, "{}" , name) ;
417
+ if ty_args. peek ( ) . is_some ( ) {
418
+ format_to ! (
419
+ path,
420
+ "<{}>" ,
421
+ ty_args. format_with( ", " , |ty, cb| cb( & ty. display( db) ) )
422
+ ) ;
429
423
}
424
+ format_to ! ( path, "::{}" , def_name) ;
425
+ return Some ( path) ;
430
426
}
431
427
}
432
- path
433
- } )
434
- . map ( TestId :: Path )
435
- . or_else ( || def_name. clone ( ) . map ( TestId :: Name ) ) ?;
428
+ }
429
+ format_to ! ( path, "{}" , def_name) ;
430
+ Some ( path)
431
+ } ) ( ) ;
432
+
433
+ let test_id = path. map_or_else ( || TestId :: Name ( def_name. to_string ( ) ) , TestId :: Path ) ;
436
434
437
435
let mut nav = match def {
438
- hir:: ModuleDef :: Module ( def) => NavigationTarget :: from_module_to_decl ( sema . db , def) ,
439
- def => def. try_to_nav ( sema . db ) ?,
436
+ hir:: ModuleDef :: Module ( def) => NavigationTarget :: from_module_to_decl ( db, def) ,
437
+ def => def. try_to_nav ( db) ?,
440
438
} ;
441
439
nav. focus_range = None ;
442
440
nav. description = None ;
0 commit comments