Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit fbf8e12

Browse files
committed
the scope of the return type is not the body of the function
1 parent 519d748 commit fbf8e12

File tree

3 files changed

+30
-7
lines changed

3 files changed

+30
-7
lines changed

crates/hir/src/source_analyzer.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -600,13 +600,11 @@ fn scope_for_offset(
600600
.filter(|it| it.value.kind() == SyntaxKind::MACRO_CALL)?;
601601
Some((source.value.text_range(), scope))
602602
})
603-
// find containing scope
604-
.min_by_key(|(expr_range, _scope)| {
605-
(
606-
!(expr_range.start() <= offset.value && offset.value <= expr_range.end()),
607-
expr_range.len(),
608-
)
603+
.filter(|(expr_range, _scope)| {
604+
expr_range.start() <= offset.value && offset.value <= expr_range.end()
609605
})
606+
// find containing scope
607+
.min_by_key(|(expr_range, _scope)| expr_range.len())
610608
.map(|(expr_range, scope)| {
611609
adjust(db, scopes, source_map, expr_range, offset).unwrap_or(*scope)
612610
})

crates/ide-completion/src/tests/expression.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,6 @@ fn quux(x: i32) {
513513
",
514514
expect![[r#"
515515
fn quux(…) fn(i32)
516-
lc x i32
517516
ma m!(…) macro_rules! m
518517
bt u32
519518
kw crate::

crates/ide-completion/src/tests/type_pos.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,32 @@ fn x<'lt, T, const C: usize>() -> $0
8989
);
9090
}
9191

92+
#[test]
93+
fn fn_return_type2() {
94+
check(
95+
r#"
96+
fn foo() -> B$0 {
97+
struct Bar;
98+
}
99+
"#,
100+
expect![[r#"
101+
en Enum
102+
ma makro!(…) macro_rules! makro
103+
md module
104+
st Record
105+
st Tuple
106+
st Unit
107+
tt Trait
108+
un Union
109+
bt u32
110+
it ()
111+
kw crate::
112+
kw self::
113+
kw super::
114+
"#]],
115+
)
116+
}
117+
92118
#[test]
93119
fn inferred_type_const() {
94120
check(

0 commit comments

Comments
 (0)