Skip to content

Commit 14ee9f5

Browse files
bors[bot]Veykril
andauthored
Merge #7036
7036: Don't split path separators apart in doctest runnables r=Veykril a=Veykril Fixes #7035 bors r+ Co-authored-by: Lukas Wirth <[email protected]>
2 parents e8f5626 + 3ab4f3a commit 14ee9f5

File tree

1 file changed

+39
-1
lines changed

1 file changed

+39
-1
lines changed

crates/ide/src/runnables.rs

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ fn module_def_doctest(sema: &Semantics<RootDatabase>, def: hir::ModuleDef) -> Op
193193
if let hir::AssocItemContainer::Impl(imp) = assoc_def.container(sema.db) {
194194
if let Some(adt) = imp.target_ty(sema.db).as_adt() {
195195
let name = adt.name(sema.db).to_string();
196-
let idx = path.rfind(':').unwrap_or(0);
196+
let idx = path.rfind(':').map_or(0, |idx| idx + 1);
197197
let (prefix, suffix) = path.split_at(idx);
198198
return format!("{}{}::{}", prefix, name, suffix);
199199
}
@@ -931,4 +931,42 @@ mod test_mod {
931931
"#]],
932932
);
933933
}
934+
935+
#[test]
936+
fn test_doc_runnables_impl_mod() {
937+
check(
938+
r#"
939+
//- /lib.rs
940+
mod foo;
941+
//- /foo.rs
942+
struct Foo;<|>
943+
impl Foo {
944+
/// ```
945+
/// let x = 5;
946+
/// ```
947+
fn foo() {}
948+
}
949+
"#,
950+
&[&DOCTEST],
951+
expect![[r#"
952+
[
953+
Runnable {
954+
nav: NavigationTarget {
955+
file_id: FileId(
956+
1,
957+
),
958+
full_range: 27..81,
959+
name: "foo",
960+
},
961+
kind: DocTest {
962+
test_id: Path(
963+
"foo::Foo::foo",
964+
),
965+
},
966+
cfg: None,
967+
},
968+
]
969+
"#]],
970+
);
971+
}
934972
}

0 commit comments

Comments
 (0)