mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-27 21:43:37 +00:00
Auto merge of #14208 - Kohei316:master, r=Veykril
fix:add a case in which remainig is None in resolveing types when resolving hir path. fix #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.
This commit is contained in:
commit
2e479158bb
2 changed files with 22 additions and 5 deletions
|
@ -943,17 +943,17 @@ fn resolve_hir_path_(
|
|||
res.map(|ty_ns| (ty_ns, path.segments().first()))
|
||||
}
|
||||
None => {
|
||||
let (ty, remaining) =
|
||||
let (ty, remaining_idx) =
|
||||
resolver.resolve_path_in_type_ns(db.upcast(), path.mod_path())?;
|
||||
match remaining {
|
||||
Some(remaining) if remaining > 1 => {
|
||||
if remaining + 1 == path.segments().len() {
|
||||
match remaining_idx {
|
||||
Some(remaining_idx) => {
|
||||
if remaining_idx + 1 == path.segments().len() {
|
||||
Some((ty, path.segments().last()))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
_ => Some((ty, path.segments().get(1))),
|
||||
None => Some((ty, None)),
|
||||
}
|
||||
}
|
||||
}?;
|
||||
|
|
|
@ -1065,6 +1065,23 @@ fn f() -> impl Sub<Item$0 = u8> {}
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn goto_def_for_module_declaration_in_path_if_types_and_values_same_name() {
|
||||
check(
|
||||
r#"
|
||||
mod bar {
|
||||
pub struct Foo {}
|
||||
//^^^
|
||||
pub fn Foo() {}
|
||||
}
|
||||
|
||||
fn baz() {
|
||||
let _foo_enum: bar::Foo$0 = bar::Foo {};
|
||||
}
|
||||
"#,
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unknown_assoc_ty() {
|
||||
check_unresolved(
|
||||
|
|
Loading…
Reference in a new issue