Skip to content

Commit 2e47915

Browse files
committed
Auto merge of rust-lang#14208 - Kohei316:master, r=Veykril
fix:add a case in which remainig is None in resolveing types when resolving hir path. fix rust-lang#14030 The variable type is being determined incorrectly This PR fixed a problem in which `go to definition` is jumping to the incorrect position because it was failing to resolve the type in case it defined in the module when resolving hir. In addition, I added a test for this issue and refactored the related code. This is my first PR and I am using a translation tool to write this text. Let me know if you have any problems.
2 parents 4e29820 + aa87764 commit 2e47915

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)