aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2020-09-17 14:27:50 +0100
committerGitHub <[email protected]>2020-09-17 14:27:50 +0100
commit7af7e1f25322b723fbaf0b2477b2b0716905f619 (patch)
tree939afa0f475610c3b618b7366ffd05101334c8c8 /crates
parentd84c18d989d07785127d00395b929fc69eca19e6 (diff)
parent6eea06415d96012b01204611a65159b1a251a99d (diff)
Merge #6024
6024: Give `ExternCrate` a `Name`, not a `ModPath` r=jonas-schievink a=jonas-schievink Simplifies things Co-authored-by: Jonas Schievink <[email protected]>
Diffstat (limited to 'crates')
-rw-r--r--crates/hir_def/src/item_tree.rs2
-rw-r--r--crates/hir_def/src/item_tree/lower.rs4
-rw-r--r--crates/hir_def/src/item_tree/tests.rs2
-rw-r--r--crates/hir_def/src/nameres/collector.rs17
-rw-r--r--crates/hir_def/src/path.rs4
5 files changed, 11 insertions, 18 deletions
diff --git a/crates/hir_def/src/item_tree.rs b/crates/hir_def/src/item_tree.rs
index db3b4a985..0fd91b9d0 100644
--- a/crates/hir_def/src/item_tree.rs
+++ b/crates/hir_def/src/item_tree.rs
@@ -491,7 +491,7 @@ pub struct Import {
491 491
492#[derive(Debug, Clone, Eq, PartialEq)] 492#[derive(Debug, Clone, Eq, PartialEq)]
493pub struct ExternCrate { 493pub struct ExternCrate {
494 pub path: ModPath, 494 pub name: Name,
495 pub alias: Option<ImportAlias>, 495 pub alias: Option<ImportAlias>,
496 pub visibility: RawVisibilityId, 496 pub visibility: RawVisibilityId,
497 /// Whether this is a `#[macro_use] extern crate ...`. 497 /// Whether this is a `#[macro_use] extern crate ...`.
diff --git a/crates/hir_def/src/item_tree/lower.rs b/crates/hir_def/src/item_tree/lower.rs
index da62e1297..54814f141 100644
--- a/crates/hir_def/src/item_tree/lower.rs
+++ b/crates/hir_def/src/item_tree/lower.rs
@@ -503,7 +503,7 @@ impl Ctx {
503 &mut self, 503 &mut self,
504 extern_crate: &ast::ExternCrate, 504 extern_crate: &ast::ExternCrate,
505 ) -> Option<FileItemTreeId<ExternCrate>> { 505 ) -> Option<FileItemTreeId<ExternCrate>> {
506 let path = ModPath::from_name_ref(&extern_crate.name_ref()?); 506 let name = extern_crate.name_ref()?.as_name();
507 let alias = extern_crate.rename().map(|a| { 507 let alias = extern_crate.rename().map(|a| {
508 a.name().map(|it| it.as_name()).map_or(ImportAlias::Underscore, ImportAlias::Alias) 508 a.name().map(|it| it.as_name()).map_or(ImportAlias::Underscore, ImportAlias::Alias)
509 }); 509 });
@@ -512,7 +512,7 @@ impl Ctx {
512 // FIXME: cfg_attr 512 // FIXME: cfg_attr
513 let is_macro_use = extern_crate.has_atom_attr("macro_use"); 513 let is_macro_use = extern_crate.has_atom_attr("macro_use");
514 514
515 let res = ExternCrate { path, alias, visibility, is_macro_use, ast_id }; 515 let res = ExternCrate { name, alias, visibility, is_macro_use, ast_id };
516 Some(id(self.data().extern_crates.alloc(res))) 516 Some(id(self.data().extern_crates.alloc(res)))
517 } 517 }
518 518
diff --git a/crates/hir_def/src/item_tree/tests.rs b/crates/hir_def/src/item_tree/tests.rs
index 4d0a3b7e6..1a806cda5 100644
--- a/crates/hir_def/src/item_tree/tests.rs
+++ b/crates/hir_def/src/item_tree/tests.rs
@@ -232,7 +232,7 @@ fn smoke() {
232 #[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("attr_on_use"))] }, input: None }]) }] 232 #[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("attr_on_use"))] }, input: None }]) }]
233 Import { path: ModPath { kind: Plain, segments: [Name(Text("b"))] }, alias: None, visibility: RawVisibilityId("pub(self)"), is_glob: true, is_prelude: false, ast_id: FileAstId::<syntax::ast::generated::nodes::Use>(0), index: 1 } 233 Import { path: ModPath { kind: Plain, segments: [Name(Text("b"))] }, alias: None, visibility: RawVisibilityId("pub(self)"), is_glob: true, is_prelude: false, ast_id: FileAstId::<syntax::ast::generated::nodes::Use>(0), index: 1 }
234 #[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("ext_crate"))] }, input: None }]) }] 234 #[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("ext_crate"))] }, input: None }]) }]
235 ExternCrate { path: ModPath { kind: Plain, segments: [Name(Text("krate"))] }, alias: None, visibility: RawVisibilityId("pub(self)"), is_macro_use: false, ast_id: FileAstId::<syntax::ast::generated::nodes::ExternCrate>(1) } 235 ExternCrate { name: Name(Text("krate")), alias: None, visibility: RawVisibilityId("pub(self)"), is_macro_use: false, ast_id: FileAstId::<syntax::ast::generated::nodes::ExternCrate>(1) }
236 #[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("on_trait"))] }, input: None }]) }] 236 #[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("on_trait"))] }, input: None }]) }]
237 Trait { name: Name(Text("Tr")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(0), auto: false, items: [TypeAlias(Idx::<TypeAlias>(0)), Const(Idx::<Const>(0)), Function(Idx::<Function>(0)), Function(Idx::<Function>(1))], ast_id: FileAstId::<syntax::ast::generated::nodes::Trait>(2) } 237 Trait { name: Name(Text("Tr")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(0), auto: false, items: [TypeAlias(Idx::<TypeAlias>(0)), Const(Idx::<Const>(0)), Function(Idx::<Function>(0)), Function(Idx::<Function>(1))], ast_id: FileAstId::<syntax::ast::generated::nodes::Trait>(2) }
238 > #[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("assoc_ty"))] }, input: None }]) }] 238 > #[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("assoc_ty"))] }, input: None }]) }]
diff --git a/crates/hir_def/src/nameres/collector.rs b/crates/hir_def/src/nameres/collector.rs
index 818008169..c1e1d53f6 100644
--- a/crates/hir_def/src/nameres/collector.rs
+++ b/crates/hir_def/src/nameres/collector.rs
@@ -3,6 +3,8 @@
3//! `DefCollector::collect` contains the fixed-point iteration loop which 3//! `DefCollector::collect` contains the fixed-point iteration loop which
4//! resolves imports and expands macros. 4//! resolves imports and expands macros.
5 5
6use std::iter;
7
6use base_db::{CrateId, FileId, ProcMacroId}; 8use base_db::{CrateId, FileId, ProcMacroId};
7use cfg::CfgOptions; 9use cfg::CfgOptions;
8use hir_expand::InFile; 10use hir_expand::InFile;
@@ -149,7 +151,7 @@ impl Import {
149 let it = &tree[id.value]; 151 let it = &tree[id.value];
150 let visibility = &tree[it.visibility]; 152 let visibility = &tree[it.visibility];
151 Self { 153 Self {
152 path: it.path.clone(), 154 path: ModPath::from_segments(PathKind::Plain, iter::once(it.name.clone())),
153 alias: it.alias.clone(), 155 alias: it.alias.clone(),
154 visibility: visibility.clone(), 156 visibility: visibility.clone(),
155 is_glob: false, 157 is_glob: false,
@@ -356,20 +358,15 @@ impl DefCollector<'_> {
356 fn import_macros_from_extern_crate( 358 fn import_macros_from_extern_crate(
357 &mut self, 359 &mut self,
358 current_module_id: LocalModuleId, 360 current_module_id: LocalModuleId,
359 import: &item_tree::ExternCrate, 361 extern_crate: &item_tree::ExternCrate,
360 ) { 362 ) {
361 log::debug!( 363 log::debug!(
362 "importing macros from extern crate: {:?} ({:?})", 364 "importing macros from extern crate: {:?} ({:?})",
363 import, 365 extern_crate,
364 self.def_map.edition, 366 self.def_map.edition,
365 ); 367 );
366 368
367 let res = self.def_map.resolve_name_in_extern_prelude( 369 let res = self.def_map.resolve_name_in_extern_prelude(&extern_crate.name);
368 &import
369 .path
370 .as_ident()
371 .expect("extern crate should have been desugared to one-element path"),
372 );
373 370
374 if let Some(ModuleDefId::ModuleId(m)) = res.take_types() { 371 if let Some(ModuleDefId::ModuleId(m)) = res.take_types() {
375 mark::hit!(macro_rules_from_other_crates_are_visible_with_macro_use); 372 mark::hit!(macro_rules_from_other_crates_are_visible_with_macro_use);
@@ -802,7 +799,7 @@ impl DefCollector<'_> {
802 let item_tree = self.db.item_tree(krate.file_id); 799 let item_tree = self.db.item_tree(krate.file_id);
803 let extern_crate = &item_tree[krate.value]; 800 let extern_crate = &item_tree[krate.value];
804 801
805 diagnosed_extern_crates.insert(extern_crate.path.segments[0].clone()); 802 diagnosed_extern_crates.insert(extern_crate.name.clone());
806 803
807 self.def_map.diagnostics.push(DefDiagnostic::unresolved_extern_crate( 804 self.def_map.diagnostics.push(DefDiagnostic::unresolved_extern_crate(
808 directive.module_id, 805 directive.module_id,
diff --git a/crates/hir_def/src/path.rs b/crates/hir_def/src/path.rs
index 99395667d..734310458 100644
--- a/crates/hir_def/src/path.rs
+++ b/crates/hir_def/src/path.rs
@@ -56,10 +56,6 @@ impl ModPath {
56 ModPath { kind, segments } 56 ModPath { kind, segments }
57 } 57 }
58 58
59 pub(crate) fn from_name_ref(name_ref: &ast::NameRef) -> ModPath {
60 name_ref.as_name().into()
61 }
62
63 /// Converts an `tt::Ident` into a single-identifier `Path`. 59 /// Converts an `tt::Ident` into a single-identifier `Path`.
64 pub(crate) fn from_tt_ident(ident: &tt::Ident) -> ModPath { 60 pub(crate) fn from_tt_ident(ident: &tt::Ident) -> ModPath {
65 ident.as_name().into() 61 ident.as_name().into()