diff --git a/crates/ra_db/src/fixture.rs b/crates/ra_db/src/fixture.rs index ee883b6154..ade187629b 100644 --- a/crates/ra_db/src/fixture.rs +++ b/crates/ra_db/src/fixture.rs @@ -8,8 +8,8 @@ use rustc_hash::FxHashMap; use test_utils::{extract_offset, parse_fixture, CURSOR_MARKER}; use crate::{ - CrateGraph, Edition, FileId, FilePosition, RelativePathBuf, SourceDatabaseExt, SourceRoot, - SourceRootId, + CrateGraph, CrateId, Edition, FileId, FilePosition, RelativePathBuf, SourceDatabaseExt, + SourceRoot, SourceRootId, }; pub const WORKSPACE: SourceRootId = SourceRootId(0); @@ -33,6 +33,14 @@ pub trait WithFixture: Default + SourceDatabaseExt + 'static { let pos = with_files(&mut db, fixture); (db, pos.unwrap()) } + + fn test_crate(&self) -> CrateId { + let crate_graph = self.crate_graph(); + let mut it = crate_graph.iter(); + let res = it.next().unwrap(); + assert!(it.next().is_none()); + res + } } impl WithFixture for DB {} diff --git a/crates/ra_hir_def/src/nameres/collector.rs b/crates/ra_hir_def/src/nameres/collector.rs index 37d0f30936..83eef821f7 100644 --- a/crates/ra_hir_def/src/nameres/collector.rs +++ b/crates/ra_hir_def/src/nameres/collector.rs @@ -798,7 +798,7 @@ mod tests { fn do_limited_resolve(code: &str, limit: u32, poison_limit: u32) -> CrateDefMap { let (db, _file_id) = TestDB::with_single_file(&code); - let krate = db.crate_graph().iter().next().unwrap(); + let krate = db.test_crate(); let def_map = { let edition = db.crate_graph().edition(krate); diff --git a/crates/ra_hir_def/src/nameres/tests/incremental.rs b/crates/ra_hir_def/src/nameres/tests/incremental.rs index 80dcec62f0..903a227719 100644 --- a/crates/ra_hir_def/src/nameres/tests/incremental.rs +++ b/crates/ra_hir_def/src/nameres/tests/incremental.rs @@ -1,12 +1,12 @@ use std::sync::Arc; -use ra_db::{SourceDatabase, SourceDatabaseExt}; +use ra_db::SourceDatabaseExt; use super::*; fn check_def_map_is_not_recomputed(initial: &str, file_change: &str) { let (mut db, pos) = TestDB::with_position(initial); - let krate = db.crate_graph().iter().next().unwrap(); + let krate = db.test_crate(); { let events = db.log_executed(|| { db.crate_def_map(krate); @@ -111,7 +111,7 @@ fn typing_inside_a_macro_should_not_invalidate_def_map() { m!(X); ", ); - let krate = db.crate_graph().iter().next().unwrap(); + let krate = db.test_crate(); { let events = db.log_executed(|| { let crate_def_map = db.crate_def_map(krate); diff --git a/crates/ra_hir_def/src/nameres/tests/mod_resolution.rs b/crates/ra_hir_def/src/nameres/tests/mod_resolution.rs index dee364a142..eb7b85c07c 100644 --- a/crates/ra_hir_def/src/nameres/tests/mod_resolution.rs +++ b/crates/ra_hir_def/src/nameres/tests/mod_resolution.rs @@ -656,7 +656,7 @@ fn unresolved_module_diagnostics() { //- /foo.rs ", ); - let krate = db.crate_graph().iter().next().unwrap(); + let krate = db.test_crate(); let crate_def_map = db.crate_def_map(krate);