diff --git a/crates/hir/src/source_analyzer.rs b/crates/hir/src/source_analyzer.rs index b5e6d99093d..0ae30604a8a 100644 --- a/crates/hir/src/source_analyzer.rs +++ b/crates/hir/src/source_analyzer.rs @@ -600,13 +600,11 @@ fn scope_for_offset( .filter(|it| it.value.kind() == SyntaxKind::MACRO_CALL)?; Some((source.value.text_range(), scope)) }) - // find containing scope - .min_by_key(|(expr_range, _scope)| { - ( - !(expr_range.start() <= offset.value && offset.value <= expr_range.end()), - expr_range.len(), - ) + .filter(|(expr_range, _scope)| { + expr_range.start() <= offset.value && offset.value <= expr_range.end() }) + // find containing scope + .min_by_key(|(expr_range, _scope)| expr_range.len()) .map(|(expr_range, scope)| { adjust(db, scopes, source_map, expr_range, offset).unwrap_or(*scope) }) diff --git a/crates/ide-completion/src/tests/expression.rs b/crates/ide-completion/src/tests/expression.rs index c05a7ad9fa5..ded8e48d4ea 100644 --- a/crates/ide-completion/src/tests/expression.rs +++ b/crates/ide-completion/src/tests/expression.rs @@ -513,7 +513,6 @@ fn quux(x: i32) { ", expect![[r#" fn quux(…) fn(i32) - lc x i32 ma m!(…) macro_rules! m bt u32 kw crate:: diff --git a/crates/ide-completion/src/tests/type_pos.rs b/crates/ide-completion/src/tests/type_pos.rs index 1e5e86eef59..191acb90532 100644 --- a/crates/ide-completion/src/tests/type_pos.rs +++ b/crates/ide-completion/src/tests/type_pos.rs @@ -89,6 +89,32 @@ fn x<'lt, T, const C: usize>() -> $0 ); } +#[test] +fn fn_return_type2() { + check( + r#" +fn foo() -> B$0 { + struct Bar; +} +"#, + expect![[r#" + en Enum + ma makro!(…) macro_rules! makro + md module + st Record + st Tuple + st Unit + tt Trait + un Union + bt u32 + it () + kw crate:: + kw self:: + kw super:: + "#]], + ) +} + #[test] fn inferred_type_const() { check(