From 50e28aec25197d0aa2aa175619a004762d45fd65 Mon Sep 17 00:00:00 2001 From: ivan770 Date: Fri, 26 Mar 2021 16:04:53 +0200 Subject: Ignore main functions not in root module --- crates/ide/src/runnables.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/crates/ide/src/runnables.rs b/crates/ide/src/runnables.rs index 5b488e2c5..7e4c5a078 100644 --- a/crates/ide/src/runnables.rs +++ b/crates/ide/src/runnables.rs @@ -226,7 +226,9 @@ pub(crate) fn runnable_fn(sema: &Semantics, def: hir::Function) -> let func = def.source(sema.db)?; let name_string = def.name(sema.db).to_string(); - let kind = if name_string == "main" { + let root = def.krate(sema.db)?.root_module(sema.db); + + let kind = if name_string == "main" && def.module(sema.db) == root { RunnableKind::Bin } else { let canonical_path = { @@ -444,6 +446,10 @@ fn test_foo() {} #[bench] fn bench() {} + +mod not_a_root { + fn main() {} +} "#, &[&BIN, &TEST, &TEST, &BENCH], expect![[r#" -- cgit v1.2.3