diff options
Diffstat (limited to 'crates/ide/src/runnables.rs')
-rw-r--r-- | crates/ide/src/runnables.rs | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/crates/ide/src/runnables.rs b/crates/ide/src/runnables.rs index 5b488e2c5..3eb9e27ee 100644 --- a/crates/ide/src/runnables.rs +++ b/crates/ide/src/runnables.rs | |||
@@ -98,6 +98,7 @@ impl Runnable { | |||
98 | // | 98 | // |
99 | // | VS Code | **Rust Analyzer: Run** | 99 | // | VS Code | **Rust Analyzer: Run** |
100 | // |=== | 100 | // |=== |
101 | // image::https://user-images.githubusercontent.com/48062697/113065583-055aae80-91b1-11eb-958f-d67efcaf6a2f.gif[] | ||
101 | pub(crate) fn runnables(db: &RootDatabase, file_id: FileId) -> Vec<Runnable> { | 102 | pub(crate) fn runnables(db: &RootDatabase, file_id: FileId) -> Vec<Runnable> { |
102 | let sema = Semantics::new(db); | 103 | let sema = Semantics::new(db); |
103 | 104 | ||
@@ -226,7 +227,9 @@ pub(crate) fn runnable_fn(sema: &Semantics<RootDatabase>, def: hir::Function) -> | |||
226 | let func = def.source(sema.db)?; | 227 | let func = def.source(sema.db)?; |
227 | let name_string = def.name(sema.db).to_string(); | 228 | let name_string = def.name(sema.db).to_string(); |
228 | 229 | ||
229 | let kind = if name_string == "main" { | 230 | let root = def.krate(sema.db)?.root_module(sema.db); |
231 | |||
232 | let kind = if name_string == "main" && def.module(sema.db) == root { | ||
230 | RunnableKind::Bin | 233 | RunnableKind::Bin |
231 | } else { | 234 | } else { |
232 | let canonical_path = { | 235 | let canonical_path = { |
@@ -296,7 +299,7 @@ fn module_def_doctest(sema: &Semantics<RootDatabase>, def: hir::ModuleDef) -> Op | |||
296 | // FIXME: this also looks very wrong | 299 | // FIXME: this also looks very wrong |
297 | if let Some(assoc_def) = assoc_def { | 300 | if let Some(assoc_def) = assoc_def { |
298 | if let hir::AssocItemContainer::Impl(imp) = assoc_def.container(sema.db) { | 301 | if let hir::AssocItemContainer::Impl(imp) = assoc_def.container(sema.db) { |
299 | let ty = imp.target_ty(sema.db); | 302 | let ty = imp.self_ty(sema.db); |
300 | if let Some(adt) = ty.as_adt() { | 303 | if let Some(adt) = ty.as_adt() { |
301 | let name = adt.name(sema.db); | 304 | let name = adt.name(sema.db); |
302 | let idx = path.rfind(':').map_or(0, |idx| idx + 1); | 305 | let idx = path.rfind(':').map_or(0, |idx| idx + 1); |
@@ -444,6 +447,10 @@ fn test_foo() {} | |||
444 | 447 | ||
445 | #[bench] | 448 | #[bench] |
446 | fn bench() {} | 449 | fn bench() {} |
450 | |||
451 | mod not_a_root { | ||
452 | fn main() {} | ||
453 | } | ||
447 | "#, | 454 | "#, |
448 | &[&BIN, &TEST, &TEST, &BENCH], | 455 | &[&BIN, &TEST, &TEST, &BENCH], |
449 | expect![[r#" | 456 | expect![[r#" |