- visit_file_defs(&sema, file_id, &mut |def| match def {
- Either::Left(def) => {
- let runnable = match def {
- hir::ModuleDef::Module(it) => runnable_mod(&sema, it),
- hir::ModuleDef::Function(it) => runnable_fn(&sema, it),
- _ => None,
- };
- add_opt(runnable.or_else(|| module_def_doctest(sema.db, def)), Some(def));
- }
- Either::Right(impl_) => {
- add_opt(runnable_impl(&sema, &impl_), None);
- impl_
- .items(db)
- .into_iter()
- .map(|assoc| {
- (
- match assoc {
- hir::AssocItem::Function(it) => runnable_fn(&sema, it)
- .or_else(|| module_def_doctest(sema.db, it.into())),
- hir::AssocItem::Const(it) => module_def_doctest(sema.db, it.into()),
- hir::AssocItem::TypeAlias(it) => module_def_doctest(sema.db, it.into()),
- },
- assoc,
- )
- })
- .for_each(|(r, assoc)| add_opt(r, Some(assoc.into())));
+ visit_file_defs(&sema, file_id, &mut |def| {
+ let runnable = match def {
+ Definition::Module(it) => runnable_mod(&sema, it),
+ Definition::Function(it) => runnable_fn(&sema, it),
+ Definition::SelfType(impl_) => runnable_impl(&sema, &impl_),
+ _ => None,
+ };
+ add_opt(
+ runnable
+ .or_else(|| module_def_doctest(sema.db, def))
+ // #[macro_export] mbe macros are declared in the root, while their definition may reside in a different module
+ .filter(|it| it.nav.file_id == file_id),
+ Some(def),
+ );
+ if let Definition::SelfType(impl_) = def {
+ impl_.items(db).into_iter().for_each(|assoc| {
+ let runnable = match assoc {
+ hir::AssocItem::Function(it) => {
+ runnable_fn(&sema, it).or_else(|| module_def_doctest(sema.db, it.into()))
+ }
+ hir::AssocItem::Const(it) => module_def_doctest(sema.db, it.into()),
+ hir::AssocItem::TypeAlias(it) => module_def_doctest(sema.db, it.into()),
+ };
+ add_opt(runnable, Some(assoc.into()))
+ });