{"record":{"id":"0e811a461ce20ca3","repo":"rust-lang/rust-analyzer","slug":"missing-default-crate-root-specify-a-main-rs-or-l","errorCode":null,"errorMessage":"missing default crate root, specify a main.rs or lib.rs","messagePattern":"missing default crate root, specify a main\\.rs or lib\\.rs","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/test-fixture/src/lib.rs","lineNumber":425,"sourceCode":"                crate_ws_data.clone(),\n            );\n\n            (\n                move || {\n                    DependencyBuilder::with_prelude(\n                        CrateName::new(\"core\").unwrap(),\n                        core_crate,\n                        true,\n                        true,\n                    )\n                },\n                core_crate,\n            )\n        });\n\n        if crates.is_empty() {\n            let crate_root = default_crate_root\n                .expect(\"missing default crate root, specify a main.rs or lib.rs\");\n            let root = crate_graph.add_crate_root(\n                crate_root,\n                default_edition,\n                Some(CrateName::new(\"ra_test_fixture\").unwrap().into()),\n                None,\n                default_cfg.clone(),\n                Some(default_cfg),\n                default_env,\n                CrateOrigin::Local { repo: None, name: None },\n                Vec::new(),\n                false,\n                proc_macro_cwd.clone(),\n                crate_ws_data.clone(),\n            );\n            if let Some((mini_core, _)) = mini_core {\n                crate_graph.add_dep(root, mini_core()).unwrap();\n            }\n        } else {","sourceCodeStart":407,"sourceCodeEnd":443,"githubUrl":"https://github.com/rust-lang/rust-analyzer/blob/e8f7e90aa3e7b26aa9a000200f606c1078da99ec/crates/test-fixture/src/lib.rs#L407-L443","documentation":"parse_with_proc_macros builds a CrateGraph from the fixture. If no crates were declared in the fixture, it falls back to a single default crate whose root file comes from default_crate_root; when that Option is None the expect panics. It means neither fixture-declared crates (with `-/-` crate root syntax) nor a default main.rs/lib.rs root were available.","triggerScenarios":"Calling parse_with_proc_macros (public API) with an empty crate list and without supplying default_crate_root — e.g. a fixture with proc-macro/dep declarations but no `-/-` root directive, or a fixture that parses to zero crates.","commonSituations":"Programmatically constructing fixtures with proc macros but forgetting the `-/-` crate-root annotation; calling the public fixture API directly rather than through TestDb helpers that set a default root; typos in the crate-root marker so it isn't recognized.","solutions":["Declare a crate root in the fixture using the `-/-` separator with lib.rs/main.rs, e.g. `\"//- /lib.rs crate:main\nfn main() {}\"`.","Pass a default_crate_root (FileId pointing at your fixture's root file) when calling parse_with_proc_macros directly.","Use TestDb::with_single_file-style helpers which supply a default root automatically.","Check ChangeFixture::parse output: if your fixture text was consumed as a proc-macro/dependency directive, fix the directive syntax."],"exampleFix":"// before\nlet db = TestDb::parse_with_proc_macros(fixture_text, /* no default root */ None);\n// after\nlet db = TestDb::parse_with_proc_macros(\n    \"//- /lib.rs crate:main deps:foo\nfn main() {}\",\n    Some(default_lib_file_id),\n);","handlingStrategy":"validation","validationCode":"fn assert_fixture_declares_root(fixture: &str) {\n    let has_root = fixture.contains(\"-/-\") || fixture.contains(\"lib.rs\") || fixture.contains(\"main.rs\");\n    assert!(has_root, \"fixture must declare a crate root or provide a default one\");\n}","typeGuard":null,"tryCatchPattern":"// Avoid by construction; if calling parse_with_proc_macros directly:\nmatch default_crate_root {\n    Some(root) => parse_with_proc_macros(text, Some(root)),\n    None => panic!(\"supply default_crate_root or declare `-/- /lib.rs` in the fixture\"),\n}","preventionTips":["When a fixture declares deps/proc-macros, always add the `-/-` crate-root section.","Prefer TestDb::with_single_file* helpers which set a default root.","Sanity-check ChangeFixture::parse output (crates non-empty) before further processing."],"tags":["rust","testing","fixture","crate-graph","panic"],"backgroundTag":"missing-crate-root","analyzedSha":"e8f7e90aa3e7b26aa9a000200f606c1078da99ec","analyzedAt":"2026-09-03T21:08:06.959Z","contentChangedAt":"2026-09-03T21:08:06.959Z","schemaVersion":2},"datasetVersion":"2026-09-11T07:07:21.782Z"}