{"record":{"id":"4cd66b564caeb218","repo":"rust-lang/rust-analyzer","slug":"could-not-find-file-position-in-fixture-did-you-f","errorCode":null,"errorMessage":"Could not find file position in fixture. Did you forget to add an `$0`?","messagePattern":"Could not find file position in fixture\\. Did you forget to add an `\\$0`\\?","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/test-fixture/src/lib.rs","lineNumber":223,"sourceCode":"    #[track_caller]\n    fn with_range(#[rust_analyzer::rust_fixture] ra_fixture: &str) -> (Self, FileRange) {\n        let (db, file_id, range_or_offset) = Self::with_range_or_offset(ra_fixture);\n        let range = range_or_offset.expect_range();\n        (db, FileRange { file_id, range })\n    }\n\n    /// See the trait documentation for more information on fixtures.\n    #[track_caller]\n    fn with_range_or_offset(\n        #[rust_analyzer::rust_fixture] ra_fixture: &str,\n    ) -> (Self, EditionedFileId, RangeOrOffset) {\n        let mut db = Self::default();\n        let fixture = ChangeFixture::parse(ra_fixture);\n        fixture.change.apply(&mut db);\n\n        let (file_id, range_or_offset) = fixture\n            .file_position\n            .expect(\"Could not find file position in fixture. Did you forget to add an `$0`?\");\n        let file_id = EditionedFileId::from_span_file_id(&db, file_id);\n        (db, file_id, range_or_offset)\n    }\n\n    fn test_crate(&self) -> Crate {\n        all_crates(self).iter().copied().find(|&krate| !krate.data(self).origin.is_lang()).unwrap()\n    }\n}\n\nimpl<DB: SourceDatabase + Default + 'static> WithFixture for DB {}\n\npub struct ChangeFixture {\n    pub file_position: Option<(span::EditionedFileId, RangeOrOffset)>,\n    pub file_lines: Vec<usize>,\n    pub files: Vec<span::EditionedFileId>,\n    pub change: ChangeWithProcMacros,\n    pub sysroot_files: Vec<FileId>,\n}","sourceCodeStart":205,"sourceCodeEnd":241,"githubUrl":"https://github.com/rust-lang/rust-analyzer/blob/e8f7e90aa3e7b26aa9a000200f606c1078da99ec/crates/test-fixture/src/lib.rs#L205-L241","documentation":"This panic comes from the test-fixture helper that parses a fixture string and extracts the cursor position. rust-analyzer test fixtures mark positions with `$0`; if the fixture text contains no `$0` marker, file_position is None and the expect panics. It means the test author forgot to mark where the cursor/selection should be.","triggerScenarios":"Calling TestDb::with_range_or_offset (or helpers like with_single_file_with_position that go through it) with a ra_fixture string lacking `$0`, or where `$0` was consumed by another marker such as `//^` annotations without an actual `$0`.","commonSituations":"Writing a new expect/infer test and forgetting the cursor marker; copying a fixture that used `//^^^` comment annotations only; `$0` accidentally removed during fixture cleanup (testing conventions require minimal fixtures).","solutions":["Add `$0` inside the fixture text at the position of interest, e.g. `fn f() { foo$0(); }`.","If using comment-based markers (`//^`), keep `$0` only if the API needs a cursor too; otherwise use the marker-based helper instead.","Ensure `$0` appears exactly once if the helper expects a single file position.","Check the fixture annotation syntax in docs/book/src/contributing/testing.md if unsure which marker your helper requires."],"exampleFix":"// before\nlet (db, file_id, range) = TestDb::with_range_or_offset(r#\"fn main() { foo(); }\"#);\n// after\nlet (db, file_id, range) = TestDb::with_range_or_offset(r#\"fn main() { foo$0(); }\"#);","handlingStrategy":"validation","validationCode":"fn assert_fixture_has_cursor(fixture: &str) {\n    assert!(fixture.contains(\"$0\"), \"fixture must contain $0 cursor marker\");\n}","typeGuard":null,"tryCatchPattern":"// Called from #[should_panic] tests only; otherwise validate before calling:\nassert!(ra_fixture.contains(\"$0\"));\nlet (db, file_id, pos) = TestDb::with_range_or_offset(ra_fixture);","preventionTips":["Always include exactly one $0 in position-sensitive fixtures.","Use comment markers (//^) only when using marker-based helpers that don't need $0.","Re-read docs/book/src/contributing/testing.md when adopting a new test helper."],"tags":["rust","testing","fixture","panic"],"backgroundTag":"missing-fixture-cursor-marker","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"}