Skip to content

Commit ea67e23

Browse files
Merge #3384
3384: fix #2377 super::super::* r=flodiebold a=JoshMcguigan Thanks @matklad for the detailed explanation on #2377. I believe this fixes it. One thing I'm not sure about is you said the fix would involve changing `crates/ra_hir_def/src/path/lower/lower.rs`, but I only changed `crates/ra_hir_def/src/path/lower/lower_use.rs`. I'm not sure what kind of test code I'd have to write to expose the issue in `lower.rs`, but I'd be happy to add it if you are able to provide additional guidance. closes #2377 Co-authored-by: Josh Mcguigan <[email protected]>
2 parents 6db2da4 + 0057d1e commit ea67e23

File tree

4 files changed

+88
-6
lines changed

4 files changed

+88
-6
lines changed

crates/ra_hir_def/src/nameres/tests.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,42 @@ fn crate_def_map_smoke_test() {
6565
"###)
6666
}
6767

68+
#[test]
69+
fn crate_def_map_super_super() {
70+
let map = def_map(
71+
"
72+
//- /lib.rs
73+
mod a {
74+
const A: usize = 0;
75+
76+
mod b {
77+
const B: usize = 0;
78+
79+
mod c {
80+
use super::super::*;
81+
}
82+
}
83+
}
84+
",
85+
);
86+
assert_snapshot!(map, @r###"
87+
⋮crate
88+
⋮a: t
89+
90+
⋮crate::a
91+
⋮A: v
92+
⋮b: t
93+
94+
⋮crate::a::b
95+
⋮B: v
96+
⋮c: t
97+
98+
⋮crate::a::b::c
99+
⋮A: v
100+
⋮b: t
101+
"###)
102+
}
103+
68104
#[test]
69105
fn bogus_paths() {
70106
covers!(bogus_paths);

crates/ra_hir_def/src/path/lower.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,12 @@ pub(super) fn lower_path(mut path: ast::Path, hygiene: &Hygiene) -> Option<Path>
101101
break;
102102
}
103103
ast::PathSegmentKind::SuperKw => {
104-
kind = PathKind::Super(1);
105-
break;
104+
let nested_super_count = if let PathKind::Super(n) = kind {
105+
n
106+
} else {
107+
0
108+
};
109+
kind = PathKind::Super(nested_super_count + 1);
106110
}
107111
}
108112
path = match qualifier(&path) {

crates/ra_hir_def/src/path/lower/lower_use.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,13 @@ fn convert_path(prefix: Option<ModPath>, path: ast::Path, hygiene: &Hygiene) ->
103103
ModPath::from_segments(PathKind::Super(0), iter::empty())
104104
}
105105
ast::PathSegmentKind::SuperKw => {
106-
if prefix.is_some() {
107-
return None;
108-
}
109-
ModPath::from_segments(PathKind::Super(1), iter::empty())
106+
let nested_super_count = match prefix.map(|p| p.kind) {
107+
Some(PathKind::Super(n)) => n,
108+
Some(_) => return None,
109+
None => 0,
110+
};
111+
112+
ModPath::from_segments(PathKind::Super(nested_super_count + 1), iter::empty())
110113
}
111114
ast::PathSegmentKind::Type { .. } => {
112115
// not allowed in imports

crates/ra_ide/src/completion/complete_dot.rs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -545,4 +545,43 @@ mod tests {
545545
"###
546546
)
547547
}
548+
549+
#[test]
550+
fn test_super_super_completion() {
551+
assert_debug_snapshot!(
552+
do_ref_completion(
553+
r"
554+
mod a {
555+
const A: usize = 0;
556+
557+
mod b {
558+
const B: usize = 0;
559+
560+
mod c {
561+
use super::super::<|>
562+
}
563+
}
564+
}
565+
",
566+
),
567+
@r###"
568+
[
569+
CompletionItem {
570+
label: "A",
571+
source_range: [217; 217),
572+
delete: [217; 217),
573+
insert: "A",
574+
kind: Const,
575+
},
576+
CompletionItem {
577+
label: "b",
578+
source_range: [217; 217),
579+
delete: [217; 217),
580+
insert: "b",
581+
kind: Module,
582+
},
583+
]
584+
"###
585+
);
586+
}
548587
}

0 commit comments

Comments
 (0)