Skip to content

Commit aa87764

Browse files
committed
Fix resolving types when resolving HIR and add a related test
1 parent 1d32a7b commit aa87764

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

crates/hir/src/source_analyzer.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -943,17 +943,17 @@ fn resolve_hir_path_(
943943
res.map(|ty_ns| (ty_ns, path.segments().first()))
944944
}
945945
None => {
946-
let (ty, remaining) =
946+
let (ty, remaining_idx) =
947947
resolver.resolve_path_in_type_ns(db.upcast(), path.mod_path())?;
948-
match remaining {
949-
Some(remaining) if remaining > 1 => {
950-
if remaining + 1 == path.segments().len() {
948+
match remaining_idx {
949+
Some(remaining_idx) => {
950+
if remaining_idx + 1 == path.segments().len() {
951951
Some((ty, path.segments().last()))
952952
} else {
953953
None
954954
}
955955
}
956-
_ => Some((ty, path.segments().get(1))),
956+
None => Some((ty, None)),
957957
}
958958
}
959959
}?;

crates/ide/src/goto_definition.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1065,6 +1065,23 @@ fn f() -> impl Sub<Item$0 = u8> {}
10651065
);
10661066
}
10671067

1068+
#[test]
1069+
fn goto_def_for_module_declaration_in_path_if_types_and_values_same_name() {
1070+
check(
1071+
r#"
1072+
mod bar {
1073+
pub struct Foo {}
1074+
//^^^
1075+
pub fn Foo() {}
1076+
}
1077+
1078+
fn baz() {
1079+
let _foo_enum: bar::Foo$0 = bar::Foo {};
1080+
}
1081+
"#,
1082+
)
1083+
}
1084+
10681085
#[test]
10691086
fn unknown_assoc_ty() {
10701087
check_unresolved(

0 commit comments

Comments
 (0)