aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2021-03-26 15:00:58 +0000
committerGitHub <[email protected]>2021-03-26 15:00:58 +0000
commit20e32fc946010f8c46728d6cb8bab1b96b3f48b9 (patch)
tree3fa135e7a9bd7ec6a94bad3118e5308fbe639f57
parent4cb3ecce3ff2573c8473733b2538b32cd899b686 (diff)
parent50e28aec25197d0aa2aa175619a004762d45fd65 (diff)
Merge #8206
8206: Ignore main functions not in root module r=Veykril a=ivan770 Closes #8195 Co-authored-by: ivan770 <[email protected]>
-rw-r--r--crates/ide/src/runnables.rs8
1 files changed, 7 insertions, 1 deletions
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<RootDatabase>, def: hir::Function) ->
226 let func = def.source(sema.db)?; 226 let func = def.source(sema.db)?;
227 let name_string = def.name(sema.db).to_string(); 227 let name_string = def.name(sema.db).to_string();
228 228
229 let kind = if name_string == "main" { 229 let root = def.krate(sema.db)?.root_module(sema.db);
230
231 let kind = if name_string == "main" && def.module(sema.db) == root {
230 RunnableKind::Bin 232 RunnableKind::Bin
231 } else { 233 } else {
232 let canonical_path = { 234 let canonical_path = {
@@ -444,6 +446,10 @@ fn test_foo() {}
444 446
445#[bench] 447#[bench]
446fn bench() {} 448fn bench() {}
449
450mod not_a_root {
451 fn main() {}
452}
447"#, 453"#,
448 &[&BIN, &TEST, &TEST, &BENCH], 454 &[&BIN, &TEST, &TEST, &BENCH],
449 expect![[r#" 455 expect![[r#"