aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_def/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir_def/src')
-rw-r--r--crates/ra_hir_def/src/item_scope.rs52
-rw-r--r--crates/ra_hir_def/src/nameres/tests/globs.rs155
2 files changed, 47 insertions, 160 deletions
diff --git a/crates/ra_hir_def/src/item_scope.rs b/crates/ra_hir_def/src/item_scope.rs
index 571ba3b8a..c81b966c3 100644
--- a/crates/ra_hir_def/src/item_scope.rs
+++ b/crates/ra_hir_def/src/item_scope.rs
@@ -5,6 +5,7 @@ use hir_expand::name::Name;
5use once_cell::sync::Lazy; 5use once_cell::sync::Lazy;
6use ra_db::CrateId; 6use ra_db::CrateId;
7use rustc_hash::FxHashMap; 7use rustc_hash::FxHashMap;
8use test_utils::mark;
8 9
9use crate::{ 10use crate::{
10 db::DefDatabase, per_ns::PerNs, visibility::Visibility, AdtId, BuiltinType, HasModule, ImplId, 11 db::DefDatabase, per_ns::PerNs, visibility::Visibility, AdtId, BuiltinType, HasModule, ImplId,
@@ -126,41 +127,26 @@ impl ItemScope {
126 let mut changed = false; 127 let mut changed = false;
127 let existing = self.visible.entry(name).or_default(); 128 let existing = self.visible.entry(name).or_default();
128 129
129 match (existing.types, def.types) { 130 macro_rules! check_changed {
130 (None, Some(_)) => { 131 ($changed:ident, $existing:expr, $def:expr) => {
131 existing.types = def.types; 132 match ($existing, $def) {
132 changed = true; 133 (None, Some(_)) => {
133 } 134 $existing = $def;
134 (Some(e), Some(d)) if e.0 != d.0 => { 135 $changed = true;
135 existing.types = def.types; 136 }
136 changed = true; 137 (Some(e), Some(d)) if e.0 != d.0 => {
137 } 138 mark::hit!(import_shadowed);
138 _ => {} 139 $existing = $def;
139 } 140 $changed = true;
140 141 }
141 match (existing.values, def.values) { 142 _ => {}
142 (None, Some(_)) => { 143 }
143 existing.values = def.values; 144 };
144 changed = true;
145 }
146 (Some(e), Some(d)) if e.0 != d.0 => {
147 existing.values = def.values;
148 changed = true;
149 }
150 _ => {}
151 } 145 }
152 146
153 match (existing.macros, def.macros) { 147 check_changed!(changed, existing.types, def.types);
154 (None, Some(_)) => { 148 check_changed!(changed, existing.values, def.values);
155 existing.macros = def.macros; 149 check_changed!(changed, existing.macros, def.macros);
156 changed = true;
157 }
158 (Some(e), Some(d)) if e.0 != d.0 => {
159 existing.macros = def.macros;
160 changed = true;
161 }
162 _ => {}
163 }
164 150
165 changed 151 changed
166 } 152 }
diff --git a/crates/ra_hir_def/src/nameres/tests/globs.rs b/crates/ra_hir_def/src/nameres/tests/globs.rs
index f0d85d301..f117b0362 100644
--- a/crates/ra_hir_def/src/nameres/tests/globs.rs
+++ b/crates/ra_hir_def/src/nameres/tests/globs.rs
@@ -232,146 +232,47 @@ fn glob_enum_group() {
232 232
233#[test] 233#[test]
234fn glob_shadowed_def() { 234fn glob_shadowed_def() {
235 let db = TestDB::with_files( 235 mark::check!(import_shadowed);
236 let map = def_map(
236 r###" 237 r###"
237 //- /lib.rs 238 //- /lib.rs
238 mod foo; 239 mod foo;
239 mod bar; 240 mod bar;
240 241
241 use foo::*; 242 use foo::*;
242 use bar::Baz; 243 use bar::baz;
244
245 use baz::Bar;
243 246
244 //- /foo.rs 247 //- /foo.rs
245 pub struct Baz; 248 pub mod baz {
249 pub struct Foo;
250 }
246 251
247 //- /bar.rs 252 //- /bar.rs
248 pub struct Baz; 253 pub mod baz {
254 pub struct Bar;
255 }
249 "###, 256 "###,
250 ); 257 );
251 let krate = db.test_crate(); 258 assert_snapshot!(map, @r###"
259 crate
260 Bar: t v
261 bar: t
262 baz: t
263 foo: t
264
265 crate::bar
266 baz: t
267
268 crate::bar::baz
269 Bar: t v
270
271 crate::foo
272 baz: t
252 273
253 let crate_def_map = db.crate_def_map(krate); 274 crate::foo::baz
254 let (_, root_module) = crate_def_map 275 Foo: t v
255 .modules
256 .iter()
257 .find(|(_, module_data)| module_data.parent.is_none())
258 .expect("Root module not found");
259 let visible_entries = root_module.scope.entries().collect::<Vec<_>>();
260 insta::assert_debug_snapshot!(
261 visible_entries,
262 @r###"
263 [
264 (
265 Name(
266 Text(
267 "Baz",
268 ),
269 ),
270 PerNs {
271 types: Some(
272 (
273 AdtId(
274 StructId(
275 StructId(
276 1,
277 ),
278 ),
279 ),
280 Module(
281 ModuleId {
282 krate: CrateId(
283 0,
284 ),
285 local_id: Idx::<ModuleData>(0),
286 },
287 ),
288 ),
289 ),
290 values: Some(
291 (
292 AdtId(
293 StructId(
294 StructId(
295 1,
296 ),
297 ),
298 ),
299 Module(
300 ModuleId {
301 krate: CrateId(
302 0,
303 ),
304 local_id: Idx::<ModuleData>(0),
305 },
306 ),
307 ),
308 ),
309 macros: None,
310 },
311 ),
312 (
313 Name(
314 Text(
315 "bar",
316 ),
317 ),
318 PerNs {
319 types: Some(
320 (
321 ModuleId(
322 ModuleId {
323 krate: CrateId(
324 0,
325 ),
326 local_id: Idx::<ModuleData>(2),
327 },
328 ),
329 Module(
330 ModuleId {
331 krate: CrateId(
332 0,
333 ),
334 local_id: Idx::<ModuleData>(0),
335 },
336 ),
337 ),
338 ),
339 values: None,
340 macros: None,
341 },
342 ),
343 (
344 Name(
345 Text(
346 "foo",
347 ),
348 ),
349 PerNs {
350 types: Some(
351 (
352 ModuleId(
353 ModuleId {
354 krate: CrateId(
355 0,
356 ),
357 local_id: Idx::<ModuleData>(1),
358 },
359 ),
360 Module(
361 ModuleId {
362 krate: CrateId(
363 0,
364 ),
365 local_id: Idx::<ModuleData>(0),
366 },
367 ),
368 ),
369 ),
370 values: None,
371 macros: None,
372 },
373 ),
374 ]
375 "### 276 "###
376 ); 277 );
377} 278}