diff options
| author | morine0122 <k0000.m000.job@gmail.com> | 2023-02-26 19:04:16 +0900 |
|---|---|---|
| committer | morine0122 <k0000.m000.job@gmail.com> | 2023-02-26 21:50:39 +0900 |
| commit | aa877645a6d5b16884fe1bd553d6f5ca921ea102 (patch) | |
| tree | 35a487222690d512442f6371b6a3267aa2380387 | |
| parent | 1d32a7b7c66450c792dafe162b229d40ab6a1cc8 (diff) | |
| download | rust-aa877645a6d5b16884fe1bd553d6f5ca921ea102.tar.gz rust-aa877645a6d5b16884fe1bd553d6f5ca921ea102.zip | |
Fix resolving types when resolving HIR and add a related test
| -rw-r--r-- | crates/hir/src/source_analyzer.rs | 10 | ||||
| -rw-r--r-- | crates/ide/src/goto_definition.rs | 17 |
2 files changed, 22 insertions, 5 deletions
diff --git a/crates/hir/src/source_analyzer.rs b/crates/hir/src/source_analyzer.rs index 3b39e9fa919..ef5434771d9 100644 --- a/crates/hir/src/source_analyzer.rs +++ b/crates/hir/src/source_analyzer.rs @@ -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)), } } }?; diff --git a/crates/ide/src/goto_definition.rs b/crates/ide/src/goto_definition.rs index 93019527f44..65d1181d092 100644 --- a/crates/ide/src/goto_definition.rs +++ b/crates/ide/src/goto_definition.rs @@ -1066,6 +1066,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( r#" |
