Skip to content

Commit

Permalink
Merge #8302
Browse files Browse the repository at this point in the history
8302: Allow multiple modules from the same crate in fixtures r=SomeoneToIgnore a=SomeoneToIgnore

A tiny step towards #6633

As discussed in [Zulip](https://rust-lang.zulipchat.com/#narrow/stream/185405-t-compiler.2Fwg-rls-2.2E0/topic/Completion.20benchmarks), we would need to have a generated code for the completions benchmark.
To better represent a real project, we'd better allow to specify multiple modules in a crate within a single fixture.

Co-authored-by: Kirill Bulatov <mail4score@gmail.com>
  • Loading branch information
bors[bot] and SomeoneToIgnore authored Apr 2, 2021
2 parents 8e3e13f + 0364eac commit ad406ed
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 15 deletions.
43 changes: 29 additions & 14 deletions crates/base_db/src/fixture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
//! fn insert_source_code_here() {}
//! "
//! ```
use std::{mem, str::FromStr, sync::Arc};
use std::{mem, str::FromStr, sync::Arc, collections::hash_map::Entry};

use cfg::CfgOptions;
use rustc_hash::FxHashMap;
Expand Down Expand Up @@ -175,19 +175,34 @@ impl ChangeFixture {

if let Some(krate) = meta.krate {
let crate_name = CrateName::normalize_dashes(&krate);
let crate_id = crate_graph.add_crate_root(
file_id,
meta.edition,
Some(crate_name.clone().into()),
meta.cfg,
meta.env,
Default::default(),
);
let prev = crates.insert(crate_name.clone(), crate_id);
assert!(prev.is_none());
for dep in meta.deps {
let dep = CrateName::normalize_dashes(&dep);
crate_deps.push((crate_name.clone(), dep))
match crates.entry(crate_name.clone()) {
Entry::Occupied(_) => {
assert_eq!(
crate_deps,
meta.deps
.iter()
.map(|dep| (crate_name.clone(), CrateName::normalize_dashes(dep)))
.collect::<Vec<_>>(),
"Crate {} has two modules with different dependencies in metadata",
krate,
)
}
Entry::Vacant(v) => {
let new_crate_id = crate_graph.add_crate_root(
file_id,
meta.edition,
Some(crate_name.clone().into()),
meta.cfg,
meta.env,
Default::default(),
);
v.insert(new_crate_id);

for dep in meta.deps {
let dep = CrateName::normalize_dashes(&dep);
crate_deps.push((crate_name.clone(), dep))
}
}
}
} else if meta.path == "/main.rs" || meta.path == "/lib.rs" {
assert!(default_crate_root.is_none());
Expand Down
5 changes: 4 additions & 1 deletion crates/ide_assists/src/handlers/auto_import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -918,6 +918,9 @@ fn main() {
auto_import,
r"
//- /lib.rs crate:dep
pub mod formatters;
//- /formatters.rs crate:dep
pub struct FMT;
pub struct fmt;
Expand All @@ -926,7 +929,7 @@ fn main() {
FMT$0;
}
",
r"use dep::FMT;
r"use dep::formatters::FMT;
fn main() {
FMT;
Expand Down

0 comments on commit ad406ed

Please sign in to comment.