Skip to content

Commit 20e32fc

Browse files
bors[bot]ivan770
andauthored
Merge #8206
8206: Ignore main functions not in root module r=Veykril a=ivan770 Closes #8195 Co-authored-by: ivan770 <[email protected]>
2 parents 4cb3ecc + 50e28ae commit 20e32fc

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

crates/ide/src/runnables.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,9 @@ pub(crate) fn runnable_fn(sema: &Semantics<RootDatabase>, def: hir::Function) ->
226226
let func = def.source(sema.db)?;
227227
let name_string = def.name(sema.db).to_string();
228228

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 {
230232
RunnableKind::Bin
231233
} else {
232234
let canonical_path = {
@@ -444,6 +446,10 @@ fn test_foo() {}
444446
445447
#[bench]
446448
fn bench() {}
449+
450+
mod not_a_root {
451+
fn main() {}
452+
}
447453
"#,
448454
&[&BIN, &TEST, &TEST, &BENCH],
449455
expect![[r#"

0 commit comments

Comments
 (0)