diff options
author | ivan770 <[email protected]> | 2021-03-26 14:04:53 +0000 |
---|---|---|
committer | ivan770 <[email protected]> | 2021-03-26 14:04:53 +0000 |
commit | 50e28aec25197d0aa2aa175619a004762d45fd65 (patch) | |
tree | 3fa135e7a9bd7ec6a94bad3118e5308fbe639f57 /crates/ide | |
parent | 4cb3ecce3ff2573c8473733b2538b32cd899b686 (diff) |
Ignore main functions not in root module
Diffstat (limited to 'crates/ide')
-rw-r--r-- | crates/ide/src/runnables.rs | 8 |
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] |
446 | fn bench() {} | 448 | fn bench() {} |
449 | |||
450 | mod 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#" |