aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authoruHOOCCOOHu <[email protected]>2019-09-05 09:20:36 +0100
committeruHOOCCOOHu <[email protected]>2019-09-05 11:50:04 +0100
commitdec43a0c5dd164279f94e9ab6e6d69ec28e294fd (patch)
treeed324f13437c6137e335aecf572e4b189d131e5b /crates
parent6702f5b7b5b7ddc23398c1b5d77891e9b4b1345a (diff)
Consider prelude to be `macro_use`
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_hir/src/marks.rs1
-rw-r--r--crates/ra_hir/src/nameres/collector.rs17
-rw-r--r--crates/ra_hir/src/nameres/tests/macros.rs57
3 files changed, 71 insertions, 4 deletions
diff --git a/crates/ra_hir/src/marks.rs b/crates/ra_hir/src/marks.rs
index 2e1d35c8c..fe119b97c 100644
--- a/crates/ra_hir/src/marks.rs
+++ b/crates/ra_hir/src/marks.rs
@@ -12,4 +12,5 @@ test_utils::marks!(
12 trait_resolution_on_fn_type 12 trait_resolution_on_fn_type
13 infer_while_let 13 infer_while_let
14 macro_rules_from_other_crates_are_visible_with_macro_use 14 macro_rules_from_other_crates_are_visible_with_macro_use
15 prelude_is_macro_use
15); 16);
diff --git a/crates/ra_hir/src/nameres/collector.rs b/crates/ra_hir/src/nameres/collector.rs
index 5d1c42926..3e689e360 100644
--- a/crates/ra_hir/src/nameres/collector.rs
+++ b/crates/ra_hir/src/nameres/collector.rs
@@ -185,11 +185,14 @@ where
185 185
186 if let Some(ModuleDef::Module(m)) = res.take_types() { 186 if let Some(ModuleDef::Module(m)) = res.take_types() {
187 tested_by!(macro_rules_from_other_crates_are_visible_with_macro_use); 187 tested_by!(macro_rules_from_other_crates_are_visible_with_macro_use);
188 self.import_all_macros_exported(m);
189 }
190 }
188 191
189 let item_map = self.db.crate_def_map(m.krate); 192 fn import_all_macros_exported(&mut self, module: Module) {
190 for (name, &macro_id) in &item_map.exported_macros { 193 let item_map = self.db.crate_def_map(module.krate);
191 self.global_macro_scope.insert(name.clone(), macro_id); 194 for (name, &macro_id) in &item_map.exported_macros {
192 } 195 self.global_macro_scope.insert(name.clone(), macro_id);
193 } 196 }
194 } 197 }
195 198
@@ -522,6 +525,12 @@ where
522 DB: DefDatabase, 525 DB: DefDatabase,
523{ 526{
524 fn collect(&mut self, items: &[raw::RawItem]) { 527 fn collect(&mut self, items: &[raw::RawItem]) {
528 // Prelude module is always considered to be `#[macro_use]`.
529 if let Some(prelude_module) = self.def_collector.def_map.prelude {
530 tested_by!(prelude_is_macro_use);
531 self.def_collector.import_all_macros_exported(prelude_module);
532 }
533
525 for item in items { 534 for item in items {
526 match *item { 535 match *item {
527 raw::RawItem::Module(m) => self.collect_module(&self.raw_items[m]), 536 raw::RawItem::Module(m) => self.collect_module(&self.raw_items[m]),
diff --git a/crates/ra_hir/src/nameres/tests/macros.rs b/crates/ra_hir/src/nameres/tests/macros.rs
index ebfefe273..8fcd86bfe 100644
--- a/crates/ra_hir/src/nameres/tests/macros.rs
+++ b/crates/ra_hir/src/nameres/tests/macros.rs
@@ -191,3 +191,60 @@ fn macro_rules_from_other_crates_are_visible_with_macro_use() {
191 ⋮Baz: t v 191 ⋮Baz: t v
192 "###); 192 "###);
193} 193}
194
195#[test]
196fn prelude_is_macro_use() {
197 covers!(prelude_is_macro_use);
198 let map = def_map_with_crate_graph(
199 "
200 //- /main.rs
201 structs!(Foo);
202 structs_priv!(Bar);
203 structs_outside!(Out);
204 crate::structs!(MacroNotResolved2);
205
206 mod bar;
207
208 //- /bar.rs
209 structs!(Baz);
210 crate::structs!(MacroNotResolved3);
211
212 //- /lib.rs
213 #[prelude_import]
214 use self::prelude::*;
215
216 mod prelude {
217 #[macro_export]
218 macro_rules! structs {
219 ($i:ident) => { struct $i; }
220 }
221
222 mod priv_mod {
223 #[macro_export]
224 macro_rules! structs_priv {
225 ($i:ident) => { struct $i; }
226 }
227 }
228 }
229
230 #[macro_export]
231 macro_rules! structs_outside {
232 ($i:ident) => { struct $i; }
233 }
234 ",
235 crate_graph! {
236 "main": ("/main.rs", ["foo"]),
237 "foo": ("/lib.rs", []),
238 },
239 );
240 assert_snapshot!(map, @r###"
241 ⋮crate
242 ⋮Bar: t v
243 ⋮Foo: t v
244 ⋮Out: t v
245 ⋮bar: t
246
247 ⋮crate::bar
248 ⋮Baz: t v
249 "###);
250}