File tree Expand file tree Collapse file tree 3 files changed +53
-14
lines changed Expand file tree Collapse file tree 3 files changed +53
-14
lines changed Original file line number Diff line number Diff line change @@ -344,3 +344,40 @@ fn foo() {
344
344
"# ] ] ,
345
345
)
346
346
}
347
+
348
+ #[ test]
349
+ fn is_visible_from_same_def_map ( ) {
350
+ // Regression test for https://github.com/rust-analyzer/rust-analyzer/issues/9481
351
+ check_at (
352
+ r#"
353
+ fn outer() {
354
+ mod command {
355
+ use crate::name;
356
+ }
357
+
358
+ mod tests {
359
+ use super::*;
360
+ }
361
+ $0
362
+ }
363
+ "# ,
364
+ expect ! [ [ r#"
365
+ block scope
366
+ command: t
367
+ name: _
368
+ tests: t
369
+
370
+ block scope::command
371
+ name: _
372
+
373
+ block scope::tests
374
+ name: _
375
+ outer: v
376
+
377
+ crate
378
+ outer: v
379
+ "# ] ] ,
380
+ ) ;
381
+ // FIXME: `name` should not be visible in the block scope. This happens because ItemTrees store
382
+ // inner items incorrectly.
383
+ }
Original file line number Diff line number Diff line change @@ -115,18 +115,6 @@ impl ModuleId {
115
115
pub fn containing_block ( & self ) -> Option < BlockId > {
116
116
self . block
117
117
}
118
-
119
- /// Returns `true` if this module represents a block expression.
120
- ///
121
- /// Returns `false` if this module is a submodule *inside* a block expression
122
- /// (eg. `m` in `{ mod m {} }`).
123
- pub fn is_block_root ( & self , db : & dyn db:: DefDatabase ) -> bool {
124
- if self . block . is_none ( ) {
125
- return false ;
126
- }
127
-
128
- self . def_map ( db) [ self . local_id ] . parent . is_none ( )
129
- }
130
118
}
131
119
132
120
/// An ID of a module, **local** to a specific crate
Original file line number Diff line number Diff line change @@ -134,8 +134,22 @@ impl Visibility {
134
134
// visibility as the containing module (even though no items are directly nameable from
135
135
// there, getting this right is important for method resolution).
136
136
// In that case, we adjust the visibility of `to_module` to point to the containing module.
137
- if to_module. is_block_root ( db) {
138
- to_module = to_module. containing_module ( db) . unwrap ( ) ;
137
+ // Additional complication: `to_module` might be in `from_module`'s `DefMap`, which we're
138
+ // currently computing, so we must not call the `def_map` query for it.
139
+ let arc;
140
+ let to_module_def_map =
141
+ if to_module. krate == def_map. krate ( ) && to_module. block == def_map. block_id ( ) {
142
+ def_map
143
+ } else {
144
+ arc = to_module. def_map ( db) ;
145
+ & arc
146
+ } ;
147
+ let is_block_root = match to_module. block {
148
+ Some ( _) => to_module_def_map[ to_module. local_id ] . parent . is_none ( ) ,
149
+ None => false ,
150
+ } ;
151
+ if is_block_root {
152
+ to_module = to_module_def_map. containing_module ( to_module. local_id ) . unwrap ( ) ;
139
153
}
140
154
141
155
// from_module needs to be a descendant of to_module
You can’t perform that action at this time.
0 commit comments