From 69faf81e0db5abe54b97708c5b8089934fca32f6 Mon Sep 17 00:00:00 2001 From: Josh Mcguigan Date: Sat, 29 Feb 2020 19:48:55 -0800 Subject: fix #2377 super::super::* --- crates/ra_hir_def/src/nameres/tests.rs | 36 +++++++++++++++++++++++++++ crates/ra_hir_def/src/path/lower/lower_use.rs | 11 +++++--- 2 files changed, 43 insertions(+), 4 deletions(-) diff --git a/crates/ra_hir_def/src/nameres/tests.rs b/crates/ra_hir_def/src/nameres/tests.rs index 82f0f835c..dda5ed699 100644 --- a/crates/ra_hir_def/src/nameres/tests.rs +++ b/crates/ra_hir_def/src/nameres/tests.rs @@ -65,6 +65,42 @@ fn crate_def_map_smoke_test() { "###) } +#[test] +fn crate_def_map_super_super() { + let map = def_map( + " + //- /lib.rs + mod a { + const A: usize = 0; + + mod b { + const B: usize = 0; + + mod c { + use super::super::*; + } + } + } + ", + ); + assert_snapshot!(map, @r###" + ⋮crate + ⋮a: t + ⋮ + ⋮crate::a + ⋮A: v + ⋮b: t + ⋮ + ⋮crate::a::b + ⋮B: v + ⋮c: t + ⋮ + ⋮crate::a::b::c + ⋮A: v + ⋮b: t + "###) +} + #[test] fn bogus_paths() { covers!(bogus_paths); diff --git a/crates/ra_hir_def/src/path/lower/lower_use.rs b/crates/ra_hir_def/src/path/lower/lower_use.rs index b6d1125e2..278d5196e 100644 --- a/crates/ra_hir_def/src/path/lower/lower_use.rs +++ b/crates/ra_hir_def/src/path/lower/lower_use.rs @@ -103,10 +103,13 @@ fn convert_path(prefix: Option, path: ast::Path, hygiene: &Hygiene) -> ModPath::from_segments(PathKind::Super(0), iter::empty()) } ast::PathSegmentKind::SuperKw => { - if prefix.is_some() { - return None; - } - ModPath::from_segments(PathKind::Super(1), iter::empty()) + let nested_super_count = match prefix.map(|p| p.kind) { + Some(PathKind::Super(n)) => n, + Some(_) => return None, + None => 0, + }; + + ModPath::from_segments(PathKind::Super(nested_super_count + 1), iter::empty()) } ast::PathSegmentKind::Type { .. } => { // not allowed in imports -- cgit v1.2.3