aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_project_model
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2020-02-05 10:49:25 +0000
committerGitHub <[email protected]>2020-02-05 10:49:25 +0000
commit514ff113cbc9827d88cbe9368e8e4fa5875bc3db (patch)
tree05035ebe7c248dc4756aac09bd5c310ffe173707 /crates/ra_project_model
parentc9e1aab8803264a40023aa09600b0a8fab8e00ff (diff)
parent78092c7c66a665ada55ea09476a387014f6665b0 (diff)
Merge #3017
3017: Normalize dashes in crate names r=matklad a=SomeoneToIgnore A follow-up for https://rust-lang.zulipchat.com/#narrow/stream/185405-t-compiler.2Fwg-rls-2.2E0/topic/Yet.20another.20auto.20import.20bug In theory, I could have used the same new type in the `Dependency` `name` field, but since the `add_dep` method that actually adds a dependency is private, it seems like an unnecessary change now. Co-authored-by: Kirill Bulatov <[email protected]>
Diffstat (limited to 'crates/ra_project_model')
-rw-r--r--crates/ra_project_model/src/lib.rs43
1 files changed, 30 insertions, 13 deletions
diff --git a/crates/ra_project_model/src/lib.rs b/crates/ra_project_model/src/lib.rs
index 6a104e6f2..bc1d15406 100644
--- a/crates/ra_project_model/src/lib.rs
+++ b/crates/ra_project_model/src/lib.rs
@@ -13,7 +13,7 @@ use std::{
13}; 13};
14 14
15use ra_cfg::CfgOptions; 15use ra_cfg::CfgOptions;
16use ra_db::{CrateGraph, CrateId, Edition, Env, FileId}; 16use ra_db::{CrateGraph, CrateId, CrateName, Edition, Env, FileId};
17use rustc_hash::FxHashMap; 17use rustc_hash::FxHashMap;
18use serde_json::from_reader; 18use serde_json::from_reader;
19 19
@@ -177,7 +177,9 @@ impl ProjectWorkspace {
177 if let (Some(&from), Some(&to)) = 177 if let (Some(&from), Some(&to)) =
178 (crates.get(&from_crate_id), crates.get(&to_crate_id)) 178 (crates.get(&from_crate_id), crates.get(&to_crate_id))
179 { 179 {
180 if let Err(_) = crate_graph.add_dep(from, dep.name.clone().into(), to) { 180 if let Err(_) =
181 crate_graph.add_dep(from, CrateName::new(&dep.name).unwrap(), to)
182 {
181 log::error!( 183 log::error!(
182 "cyclic dependency {:?} -> {:?}", 184 "cyclic dependency {:?} -> {:?}",
183 from_crate_id, 185 from_crate_id,
@@ -215,7 +217,9 @@ impl ProjectWorkspace {
215 if let (Some(&from), Some(&to)) = 217 if let (Some(&from), Some(&to)) =
216 (sysroot_crates.get(&from), sysroot_crates.get(&to)) 218 (sysroot_crates.get(&from), sysroot_crates.get(&to))
217 { 219 {
218 if let Err(_) = crate_graph.add_dep(from, name.into(), to) { 220 if let Err(_) =
221 crate_graph.add_dep(from, CrateName::new(name).unwrap(), to)
222 {
219 log::error!("cyclic dependency between sysroot crates") 223 log::error!("cyclic dependency between sysroot crates")
220 } 224 }
221 } 225 }
@@ -257,7 +261,7 @@ impl ProjectWorkspace {
257 if let Some(proc_macro) = libproc_macro { 261 if let Some(proc_macro) = libproc_macro {
258 if let Err(_) = crate_graph.add_dep( 262 if let Err(_) = crate_graph.add_dep(
259 crate_id, 263 crate_id,
260 "proc_macro".into(), 264 CrateName::new("proc_macro").unwrap(),
261 proc_macro, 265 proc_macro,
262 ) { 266 ) {
263 log::error!( 267 log::error!(
@@ -276,9 +280,14 @@ impl ProjectWorkspace {
276 for &from in pkg_crates.get(&pkg).into_iter().flatten() { 280 for &from in pkg_crates.get(&pkg).into_iter().flatten() {
277 if let Some(to) = lib_tgt { 281 if let Some(to) = lib_tgt {
278 if to != from { 282 if to != from {
279 if let Err(_) = 283 if let Err(_) = crate_graph.add_dep(
280 crate_graph.add_dep(from, pkg.name(&cargo).into(), to) 284 from,
281 { 285 // For root projects with dashes in their name,
286 // cargo metadata does not do any normalization,
287 // so we do it ourselves currently
288 CrateName::normalize_dashes(pkg.name(&cargo)),
289 to,
290 ) {
282 log::error!( 291 log::error!(
283 "cyclic dependency between targets of {}", 292 "cyclic dependency between targets of {}",
284 pkg.name(&cargo) 293 pkg.name(&cargo)
@@ -289,17 +298,23 @@ impl ProjectWorkspace {
289 // core is added as a dependency before std in order to 298 // core is added as a dependency before std in order to
290 // mimic rustcs dependency order 299 // mimic rustcs dependency order
291 if let Some(core) = libcore { 300 if let Some(core) = libcore {
292 if let Err(_) = crate_graph.add_dep(from, "core".into(), core) { 301 if let Err(_) =
302 crate_graph.add_dep(from, CrateName::new("core").unwrap(), core)
303 {
293 log::error!("cyclic dependency on core for {}", pkg.name(&cargo)) 304 log::error!("cyclic dependency on core for {}", pkg.name(&cargo))
294 } 305 }
295 } 306 }
296 if let Some(alloc) = liballoc { 307 if let Some(alloc) = liballoc {
297 if let Err(_) = crate_graph.add_dep(from, "alloc".into(), alloc) { 308 if let Err(_) =
309 crate_graph.add_dep(from, CrateName::new("alloc").unwrap(), alloc)
310 {
298 log::error!("cyclic dependency on alloc for {}", pkg.name(&cargo)) 311 log::error!("cyclic dependency on alloc for {}", pkg.name(&cargo))
299 } 312 }
300 } 313 }
301 if let Some(std) = libstd { 314 if let Some(std) = libstd {
302 if let Err(_) = crate_graph.add_dep(from, "std".into(), std) { 315 if let Err(_) =
316 crate_graph.add_dep(from, CrateName::new("std").unwrap(), std)
317 {
303 log::error!("cyclic dependency on std for {}", pkg.name(&cargo)) 318 log::error!("cyclic dependency on std for {}", pkg.name(&cargo))
304 } 319 }
305 } 320 }
@@ -312,9 +327,11 @@ impl ProjectWorkspace {
312 for dep in pkg.dependencies(&cargo) { 327 for dep in pkg.dependencies(&cargo) {
313 if let Some(&to) = pkg_to_lib_crate.get(&dep.pkg) { 328 if let Some(&to) = pkg_to_lib_crate.get(&dep.pkg) {
314 for &from in pkg_crates.get(&pkg).into_iter().flatten() { 329 for &from in pkg_crates.get(&pkg).into_iter().flatten() {
315 if let Err(_) = 330 if let Err(_) = crate_graph.add_dep(
316 crate_graph.add_dep(from, dep.name.clone().into(), to) 331 from,
317 { 332 CrateName::new(&dep.name).unwrap(),
333 to,
334 ) {
318 log::error!( 335 log::error!(
319 "cyclic dependency {} -> {}", 336 "cyclic dependency {} -> {}",
320 pkg.name(&cargo), 337 pkg.name(&cargo),